centos7快速安装Php8.2
1、进入centos命令行状态
yum -y install epel-release
yum -y install nginx
# Remi 源
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils
yum-config-manager --enable remi-php82
yum -y install php82-php-fpm php82-php-mysqlnd php82-php-gd php82-php-xml php82-php-mbstring
# 软链接让 systemctl 识别
ln -s /usr/bin/php82-php /usr/bin/php
ln -s /opt/remi/php82/root/usr/sbin/php-fpm /usr/sbin/php-fpm
2、设为开机启动
systemctl enable --now php-fpm
【可选】修改php-frm的web.conf配置
文件目录:/etc/php-fpm.d/www.conf
listen = /run/php-fpm/www.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
user = nginx
group = nginx
重启:systemctl restart php-fpm
3、修改nginx配置文件
server {
listen 80;
server_name _; # 或你的域名/IP
root /usr/share/nginx/html;# 你的 web 根目录
index index.php index.html index.htm;
# 解决 URL 美化(可选)
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# 处理 PHP
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
#如果是socket模式用下面这行
#fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# 安全:禁止访问隐藏文件
location ~ /\. {
deny all;
}
}
4、从新加载nginx配置
nginx -t && systemctl reload nginx
5、如果防火墙没开80端口
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
6、问题排查
6.1 访问提示:files not found,检查文件权限
ls -lZ /usr/share/nginx/html/index.php
# 1. 把文件属主/属组改成 nobody(与 php-fpm 进程一致)
sudo chown nobody:nobody /usr/local/nginx/html/index.php
# 2. 把目录和文件恢复成 Web 专用的 SELinux 上下文
sudo restorecon -Rv /usr/local/nginx/html