CentOS 7.4 yum方式搭建LNMP環境,部署WordPress博客,並安裝XCache模塊
IP | 安裝的程序包 | 版本 |
192.168.1.221 | nginx(epel源) | 1.12.2 |
php | 5.4.16 | |
php-fpm(FastCGI進程管理器) | ||
php-mysql(PHP連接MySQL時需要用到的驅動) | ||
192.168.1.222 | mariadb-server | 5.5.56 |
備註:CentOS 7.4已經不再內置mysql-server程序包
二、搭建LNMP:
1、安裝前準備:
(1)校對服務器時間
(2) 配置epel源
2、安裝nginx:# yum -y install nginx # systemctl start nginx.service # ss -tunlp | grep :80
配置文件及目錄:
? 主配置文件:/etc/nginx/nginx.conf
? 輔助配置文件:/etc/nginx/*
? 網頁存放根目錄:/usr/share/nginx/html
3、安裝php:# yum -y install php,配置文件:/etc/php.ini
4、安裝配置php-fpm:
# yum -y install php-fpm
# vim /etc/php-fpm.d/www.conf,修改以下參數的值:
listen = 192.168.1.221:9000 //php-fpm監聽的地址端口
listen.allowed_clients = 192.168.1.221 //
user = nginx
group = nginx
# systemctl start php-fpm.service
# ss -tunlp | grep :9000
配置文件:
? 主配置文件:/etc/php-fpm.conf
? 輔助配置文件:/etc/php-fpm.d/www.conf
5、安裝配置mariadb:
# yum -y install mariadb-server mariadb mariadb-devel
# systemctl start mariadb.service
# ss -tunlp | grep :3306
mariadb配置文件:/etc/my.cnf
//修改mariadb數據庫root用戶密碼為123456(默認為空)、刪除匿名用戶、刪除測試數據庫、重載授權表
# mysql_secure_installation
# mysql -uroot -p
MariaDB [(none)]> grant all on *.* to 'root'@'192.168.%.%' identified by '123456'; //授權root用戶遠程登錄
MariaDB [(none)]> flush privileges;
6、安裝php-mysql:# yum -y install php-mysql
7、 配置nginx支持php:
# cd /etc/nginx
# cp nginx.conf nginx.conf.bak
# vim nginx.conf
# systemctl reload nginx.service
# systemctl restart php-fpm.service
三、測試LNMP:
# cd /usr/share/nginx/html
# vim index.php
瀏覽器中輸入http://192.168.1.221/index.php:
停止192.168.1.222上的mariadb:# systemctl stop mariadb.service
mariadb與php通信正常
訪問http://192.168.1.221
四、安裝配置WordPress:
WordPress是一種使用PHP語言和MariaDB數據庫開發的開源、免費的Blog引擎,用戶可以在支持PHP和MariaDB數據庫的服務器上建立自己的Blog。WordPress是一個功能非常強大的博客系統,插件眾多,易於擴展,安裝和使用都非常方便。目前WordPress已經成為主流的Blog搭建平臺。下載地址https://cn.wordpress.org/,此處以wordpress-4.8.1-zh_CN.zip為例。
# yum -y install unzip
# unzip -q wordpress-4.8.1-zh_CN.zip
# cp -a wordpress/ /usr/share/nginx/html
# cd /usr/share/nginx/html/wordpress
# cp wp-config-sample.php wp-config.php
# vim wp-config.php,修改數據庫相關信息:
# mysql -uroot -p
MariaDB [(none)]> create database wpdb;
MariaDB [(none)]> grant all on wpdb.* to 'wpuser'@'%' identified by "123456";
MariaDB [(none)]> flush privileges;
# mysql -uwpuser -p
MariaDB [(none)]> show databases;
修改nginx配置文件,在index參數後新增index.php:
# vim /etc/nginx/nginx.conf
location / {
index index.php index.html index.htm;
}
# systemctl reload nginx.service
瀏覽器中輸入http://192.168.1.221/wordpress:
點擊“安裝WordPress”:
點擊“登錄”:
輸入用戶名和密碼,點擊“登錄”:
刪除安裝文件:# rm -rf /usr/share/nginx/html/wordpress/wp-admin/install.php
博客前臺登錄地址http://192.168.1.221/wordpress/
博客後臺管理地址http://192.168.1.221/wordpress/wp-admin/
五、安裝XCache模塊:
配置epel源,安裝XCache:# yum -y install php-xcache --> 3.1.1
# rpm -ql php-xcache --> /etc/php.d/xcache.ini、/usr/lib64/php/modules/xcache.so
# systemctl reload nginx.service
# systemctl restart php-fpm.service
已加載XCache相關模塊:
CentOS 7.4 yum方式搭建LNMP環境,部署WordPress博客,並安裝XCache模塊