Centos 7 中 LEMP环境配置

从EPEL安装Nginx

Extra Packages for Enterprise Linux (EPEL)

yum install epel-release
yum update
yum install nginx

启用Nginx

systemctl enable nginx.service
systemctl start nginx.service
检查运行状态
systemctl status nginx.service

配置虚拟目录

vim /etc/nginx/conf.d/wordpress.conf
server {
listen 80;
server_name www.bihell.com bihell.com;

access_log /srv/www/bihell.com/logs/access.log;
error_log /srv/www/bihell.com/logs/error.log;

location / {
root /srv/www/bihell.com/public_html;
index index.php index.html index.htm;

if (-f $request_filename) {
expires 30d;
break;
}

if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1 last;
}
}

location ~ .php$ {
fastcgi_pass   localhost:9000;
fastcgi_index  index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/bihell.com/public_html$fastcgi_script_name;

fastcgi_param PATH_INFO               $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
创建相关目录
mkdir -p /srv/www/bihell.com/{public_html,logs}
测试配置
nginx -t
获取WEB线程的用户名,并设置目录权限
<?php echo(exec("whoami")); ?>
chown -R www-data:www-data wordpress/
usermod -a -G www-data www-data
配置好以后记得重启服务
systemctl restart nginx.service

安装MariaDB

yum -y install mariadb mariadb-server
启用服务
systemctl enable mariadb.service
systemctl start mariadb.service
初始化
mysql_secure_installation
登陆数据库
mysql -u root -p
创建数据库和用户
create database webdata; 
grant all on webdata.* to 'foreman' identified by '5t1ck';

安装PHP

yum install php-fpm php-mysql php-cli
配置PHP
vi /etc/php.ini
设置如下
cgi.fix_pathinfo=0
编辑 /etc/php-fpm.d/www.conf 文件,确保以下行注释去掉.
pm.min_spare_servers = 5
pm.max_spare_servers = 35
启用PHP
systemctl enable php-fpm.service
systemctl restart php-fpm.service
测试php
<?php phpinfo(); ?>
输入你的网址
http://bihell.com

参考文档

Nginx + PHP-FPM + MariaDB on CentOS 7 / RHEL 7
Install WordPress with Nginx 1.6 on CentOS 7 / RHEL 7
LEMP server on CentOS 7 with FastCGI
迁移WordPress
使用Dropbox Uploader脚本定时备份Linux数据
在LEMP环境中安装WordPress