CentOS 7 搭建LEMP环境

注:E指engineX,即nginx

安装nginx

yum install nginx
systemctl enable nginx
systemctl start nginx
curl http://127.0.0.1

安装php

yum install php php-mysql php-fpm

 

编辑/etc/php.ini,修改:

cgi.fix_pathinfo=0

编辑/etc/php-fpm.d/www.conf,修改:

listen = /run/php-fpm/php-fpm.sock
...
listen.owner = nginx
listen.group = nginx
...
user = nginx
group = nginx
systemctl enable php-fpm
systemctl start php-fpm

vim /etc/nginx/default.d/default.conf,粘贴以下内容

index index.php index.html index.htm;
server_name your domain name or IP; 
# pass the PHP scripts to FastCGI server listening on the php-fpm socket 
location ~ \.php$ { 
try_files $uri =404; 
fastcgi_pass unix:/run/php-fpm/php-fpm.sock; 
fastcgi_index index.php; 
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
include fastcgi_params; 
}
重启nginx: systemctl restart nginx

安装MySQL/MariaDB

yum install mariadb mariadb-server
systemctl enable mariadb
systemctl start mariadb

配置安全:

mysql_secure_installation

重启mariadb:systemctl restart mariadb

测试nginx配置文件命令

nginx -t

nginx session问题
mkdir /var/lib/php/session
chown -R nginx:nginx /var/lib/php/session
Call to undefined function mb_strlen(); 问题
yum install php-mbstring
然后systemctl restart php-fpm
php 显示不了验证码
yum install php-gd
php创建xml失败
yum install php-xml
最后 systemctl restart php-fpm
如果使用firewalld防火墙,则使用以下命令开启http服务
配置防火墙在public区域永久开放http服务
firewall-cmd –permanent –zone=public –add-service=http