在 CentOS 7 上使用 Remi 仓库安装 PHP 7.4,您可以按照以下步骤操作
安装 EPEL 仓库:
yum install -y epel-release
安装 Remi 仓库:
sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
3. 启用 Remi 仓库:
sudo yum-config-manager --enable remi-php74
安装 PHP:
sudo yum install -y php
5. 验证安装:
php -v
PHP-FPM 是一个 PHP FastCGI 进程管理器,它可以与 Nginx 协同工作来处理 PHP 请求。
安装 PHP-FPM:
yum install -y php-fpm
启动并开机启用 PHP-FPM:
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
配置 Nginx:
server { listen 80; server_name your_domain_or_ip; #配置访问/php/时转发给php-fpm处理location ^~ /php/ {alias /var/www/html/; # 根据您的实际路径进行修改# 当访问 /php/ 时,默认加载 index.phplocation = /php/ {rewrite ^ /php/index.php last;}location ~ \.php$ {fastcgi_pass 127.0.0.1:9000; # PHP-FPM 默认监听的地址和端口fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $request_filename;include fastcgi_params;}}}
检测并重新加载 Nginx配置:
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
修改php目录的用户和组:
当使用root上传的php程序时,文件和组所有者为root,我们要把其修改为php-fpm的用户和组
首先查看php-fpm的用户和组
1. 查找php-fpm的配置文件位置
一般php-fpm的配置都在/etc/目录下,我们在该目录下搜索即可
[root@VM-0-6-centos ~]# find /etc -name php-fpm.conf
/etc/php-fpm.conf
/etc/opt/remi/php74/php-fpm.conf
从上面的输出可以看出有两个配置文件,我们现在要确认当前的php-fpm正在使用哪个配置文件
[root@VM-0-6-centos ~]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2023-09-06 18:17:15 CST; 1h 4min ago
Main PID: 18518 (php-fpm)
Status: "Processes active: 0, idle: 7, Requests: 37, slow: 0, Traffic: 0req/sec"
CGroup: /system.slice/php-fpm.service
├─18518 php-fpm: master process (/etc/php-fpm.conf)
├─18519 php-fpm: pool www
├─18520 php-fpm: pool www
├─18521 php-fpm: pool www
├─18522 php-fpm: pool www
├─18523 php-fpm: pool www
├─23246 php-fpm: pool www
└─24461 php-fpm: pool www
Sep 06 18:17:15 VM-0-6-centos systemd[1]: Starting The PHP FastCGI Process Manager...
Sep 06 18:17:15 VM-0-6-centos systemd[1]: Started The PHP FastCGI Process Manager.
通过查看php-fpm状态可以看到正在使用的配置文件为/etc/php-fpm.conf
查看/etc/php-fpm.conf文件找到user和group配置
[root@VM-0-6-centos ~]# cat /etc/php-fpm.d/www.conf | grep -E 'user\s?=|group\s?='
user = apache
group = apache
发现用户和组为apache:apache
修改php目录所有文件为php-fpm的用户和组
chown -R apache:apache /var/www/html
来源地址:https://blog.csdn.net/justdoshare/article/details/132721424