安装 Nginx :
1 |
yum install nginx |
配置 PHP 安装源 :
1 |
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm |
1 |
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm |
安装 PHP7.2 ( * 号表示安装所有有关 PHP7.2 的,扩展之类的, --exclude 排除有冲突的 mysql 与 mysqlnd 这两个PHP扩展有冲突)
1 |
yum install php72w* --exclude php72w-mysqlnd |
配置 MariaDB ( Mysql 分支版本 ) yum 安装源
1 2 3 4 5 6 7 8 9 10 11 |
vi /etc/yum.repos.d/MariaDB.repo # MariaDB 10.0 CentOS repository list - created 2014-10-13 13:04 UTC # http://mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://mirrors.aliyun.com/mariadb/yum/10.3/centos7-amd64/ gpgkey = http://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck=1 :wq # 保存退出 |
安装 MariaDB
1 |
yum install MariaDB-server MariaDB-client |
设置 Nginx MariaDB PHP-FPM 开机启动
1 2 3 |
systemctl enable nginx systemctl enable mariadb systemctl enable php-fpm |
开启 Nginx MariaDB PHP-FPM
1 2 3 |
systemctl start nginx systemctl start mariadb systemctl start php-fpm |
配置 MariaDB (设置数据库密码等)
1 |
mysql_secure_installation |
配置Nginx 与 PHP-FPM 之间通信(这里采用 tcp socket 方式; unix socket 方式性能会更好,该 nginx 和 php-fpm 必须在同一服务器下)
1 |
netstat -tunlp # 查看 php-fpm 端口号 |
1 |
vi /etc/nginx/php-fpm.conf |
1 2 3 4 5 |
location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; # PHP-FPM IP:端口号 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } |
网站域名配置
1 |
vi /etc/nginx/conf.d/example.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
server { listen 80; #listen 443 ssl http2; # server_name 域名; index index.html index.htm index.php default.html default.htm default.php; # root 网站根目录; #error_page 404 /404.html; # Deny access to PHP files in specific directory #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; } location / { # PHP 框架 ThinkPHP5.0 重写规则 if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } } include php-fpm.conf; # 引入FPM配置 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /.well-known { allow all; } location ~ /\. { deny all; } access_log off; # ssl_certificate 公钥文件路径; # ssl_certificate_key 私钥文件路径; } |