|   注册

防火墙

# 添加规则
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=mysql

# 重启
firewall-cmd --reload

软件仓库

yum install epel-release -y

#PHP7
rpm -Uvh http://mirror.webtatic.com/yum/el7/webtatic-release.rpm

一、安装Nginx

# Nginx 官方源
vi /etc/yum.repos.d/nginx.repo

添加如下内容

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1

安装

yum install nginx -y

# 开机启动
systemctl enable nginx
systemctl start nginx

测试

http://服务器IP

配置

vi /etc/nginx/nginx.conf

文件内容

    keepalive_timeout 30;

    #开启Gzip压缩
    gzip on;
    gzip_buffers 4 8k;
    gzip_min_length 1k;
    gzip_types application/javascript text/css application/octet-stream application/pdf image/gif image/jpeg image/png image/x-icon;
    gzip_vary on;

    #include /etc/nginx/conf.d/*.conf;
    include /home/vhosts/*.conf;

二、配置虚拟主机

# 创建目录
mkdir -p /home/vhosts
# 拷贝配置文件
cp /etc/nginx/conf.d/*.conf /home/vhosts/default.conf
# 编辑配置文件
vi /home/vhosts/default.conf

文件内容

server {
    # 监听80端口(默认服务器只允许一台虚拟主机)
    listen       80 default_server;
    # 监听域名
    server_name  localhost;
    # 指向目录
    root /home/www/;
    # 默认打开文件
    index index.php index.html;

    # 设置编码
    charset utf-8;

    # 网站根目录
    location / {

    }

    # 禁用.ht文件
    location ~ /\.ht {
        deny  all;
    }
}

重启Nginx

systemctl restart nginx

测试

echo '<h1>Server</h1>' > /home/www/test.html

http://服务器IP/test.html

三、安装PHP

# PHP5
yum install php-fpm php-mysql php-cli php-gd php-pdo -y

#PHP7
yum install php72w-fpm php72w-mysql php72w-cli php72w-gd php72w-pdo -y

#开机启动
systemctl enable php-fpm
systemctl start php-fpm

配置

vi /etc/php.ini

date.timezone = "Asia/Shanghai" #时区
session.save_path = "/tmp" #Session目录

Session 问题

# 创建目录
mkdir /var/lib/php/session/
chmod -R 777 /var/lib/php/session/
# 重启PHP
systemctl restart php-fpm

Nginx调用PHP

    # 调用PHP环境
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

四、安装MariaDB

# 安装
yum install mariadb mariadb-server -y

# 开机启动
systemctl enable mariadb.service
systemctl start mariadb.service

# 查看运行
netstat -tap | grep mysql

配置(root密码)

mysql_secure_installation

五、安装phpMyAdmin

# PHP5
yum install php-mbstring -y

# PHP7
yum install php72w-mbstring php72w-xml php72w-bcmath php72w-process php72w-tidy -y

# phpMyAdmin
yum install phpMyAdmin -y

配置Nginx

    # phpMyAdmin 
    location /phpMyAdmin {
        # 安装目录
        root /usr/share;
        index index.php;
        # 解析PHP
        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
    # 跳转phpMyAdmin
    location /phpmyadmin {
        rewrite ^/* /phpMyAdmin last;
    }

六、ThinkPHP5重写

1) PHP配置

vi /etc/php.ini

cgi.fix_pathinfo = 1

2) Nginx配置

    location / {
        index  index.html index.htm index.php;
        #autoindex  on;

        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            break;
        }
     }

     location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        include        fastcgi_params;
    }

3) 重启服务

systemctl restart nginx php-fpm

WebMIS

基于MVC框架开发的多用户、多权限开源解决方案,整合了Jquery、TinyMCE、ChartJS等插件!

视频教程
Linux教程
PHP教程
JavaScript教程
MVC框架
自建HMVC框架
Phalcon框架
Lumen框架
Linux文档
Shell文档
CentOS文档
Archlinux文档
WebMIS © 2017-2020 备案号: 滇ICP备14000710号
https://webmis.vip/home/