一、环境准备
[root@Server ~]# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)
[root@Server ~]# uname -r
3.10.0-957.10.1.el7.x86_64

关闭防火墙
systemctl stop firewalld.service

关闭防火墙开机启动
systemctl disable firewalld.service

关闭SELINUX (重启生效)
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config

二、增加nginx源
#vi /etc/yum.repos.d/nginx.repo

源的内容

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

查看源是否配置成功
yum list nginx
yum list |grep nginx

更新源
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

三、下载lnmp软件包
安装lnmp服务
yum install -y nginx mariadb-server php72w-common php72w-fpm php72w-mysql php72w-pdo php72w-gd

四、编写nginx配置文件
vi /etc/nginx/conf.d/default.conf

location / {
    root   /usr/share/nginx/html;
            if (!-e $request_filename) {

rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
index index.php index.html index.htm;

上面增加index.php 增加if段 为了url write

location ~ \.php$ {
root           html;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script
_name;
            include        fastcgi_params;
    }

去除所有#注释 修改为绝对路径 /usr/share/nginx/html

启动lnmp服务
systemctl start nginx.service mariadb.service php-fpm.service
加入开机启动
systemctl enable nginx.service mariadb.service php-fpm.service
检查是否启动
[root@Server ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9000 0.0.0.0: LISTEN 15807/php-fpm: mast
tcp 0 0 0.0.0.0:3306 0.0.0.0:
LISTEN 16056/mysqld
tcp 0 0 0.0.0.0:80 0.0.0.0: LISTEN 15811/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:
LISTEN 6583/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0: LISTEN 7105/master
tcp6 0 0 :::22 :::
LISTEN 6583/sshd
tcp6 0 0 ::1:25 ::: LISTEN 7105/master
udp 0 0 127.0.0.1:323 0.0.0.0:
6066/chronyd
udp6 0 0 ::1:323 :::* 6066/chronyd

创建info.php
echo '' >>/usr/share/nginx/html/info.php

测试
http://127.0.0.1/info.php

重启nginx服务
systemctl restart nginx.service

yum remove php*

[root@Server ~]# mysqladmin -u root -p password 123456
Enter password:
如果原密码为空 直接回车 123456为新密码

wget https://files.phpmyadmin.net/phpMyAdmin/4.8.5/phpMyAdmin-4.8.5-all-languages.zip
cd /var/lib/php/
mkdir session
chmod -R 777 php



关于URL重写
对于Apache服务器,请确保

httpd.conf配置文件中加载了mod_rewrite.so模块
AllowOverride None 将None改为 All`
项目目录下的.htaccess已经配置好重写规则,如有需求酌情修改.

对于Nginx服务器,以下是一个可供参考的配置:

location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
如果你的应用安装在二级目录,Nginx的伪静态方法设置如下,其中youdomain是所在的目录名称。

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



chmod -R 777 /usr/share/nginx/html/wordpress/