centos7安装nginx配置php-fpm

centos7安装nginx配置php-fpm

安装nginx,使用SCL源

# 安装
yum install rh-nginx112-nginx
# 查看服务名称systemctl list-unit-files
rh-nginx112-nginx.service
# 启动,即可访问ip浏览
systemctl start rh-nginx112-nginx.service

配置php-fpm环境

# 查找fpm
ls /opt/rh/rh-php71/root/sbin/php-fpm
# 没有就安装
yum install rh-php71-php-fpm
# 运行php-fpm
/opt/rh/rh-php71/root/sbin/php-fpm
# 修改php.ini之后,平滑重启fpm
# INT, TERM 立刻终止
# QUIT 平滑终止
# USR1 重新打开日志文件
# USR2 平滑重载所有worker进程并重新载入配置和二进制模块
# 参看进程号
ps aux | grep php-fpm
# 主进程master
kill -USR2 1354
# 查看php-fpm环境配置文件
# 位置在/etc/opt/rh/rh-php71/php-fpm.conf
ps -aux |grep php-fpm
# 查看端口9000,fpm默认端口是9000
# command not found: netstat
yum install net-tools
netstat -tnl | grep 9000
# 显示:
# tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN 
# 所有端口
netstat -ntlp
# 查看nginx环境配置文件
# 位置在/etc/opt/rh/rh-nginx112/nginx/nginx.conf
# 修改:
location {}
# 替换为:
location / {
     index index.php index.html index.htm; #添加了一个 index.php
}
# 添加:
location ~ \.php$ {
        root /opt/rh/rh-nginx112/root/usr/share/nginx/html; #指定php的根目录
        fastcgi_pass 127.0.0.1:9000;#php-fpm的默认端口是9000
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
}
# 检测配置文件是不是ok
/opt/rh/rh-nginx112/root/usr/sbin/nginx -t
# 提示:
# nginx: the configuration file /etc/opt/rh/rh-nginx112/nginx/nginx.conf syntax is ok
# nginx: configuration file /etc/opt/rh/rh-nginx112/nginx/nginx.conf test is successful
# 重启
/opt/rh/rh-nginx112/root/usr/sbin/nginx -s reload
# 新建php文件
cd /opt/rh/rh-nginx112/root/usr/share/nginx/html
mv index.html index.html.bak
touch index.php
nano index.php
# 添加

你可能感兴趣的:(php,centos,rh)