一, 演示环境:
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 // 允许连接的 FastCGI 客户端地址
- 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 相关模块:
来源: http://blog.51cto.com/qiuyue/2104852