1、環境準備
[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_64php
關閉防火牆
systemctl stop firewalld.servicehtml
關閉防火牆開機啓動
systemctl disable firewalld.service mysql
關閉SELINUX (重啓生效)
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/configlinux
2、增長nginx源
#vi /etc/yum.repos.d/nginx.reponginx
源的內容web
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1sql
查看源是否配置成功
yum list nginx
yum list |grep nginxcentos
更新源
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm服務器
3、下載lnmp軟件包
安裝lnmp服務
yum install -y nginx mariadb-server php72w-common php72w-fpm php72w-mysql php72w-pdo php72w-gdsession
4、編寫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 '<?php phpinfo();?>' >>/usr/share/nginx/html/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/