4、Rocky Linux 9.4 Nginx 解析 PHP
需要保持 nginx 用户与 php-fpm 用户一致,不然可能会出现如下错误:
PHP Primary script unknown
1、修改 php-fpm 运行用户,编译 www.conf
文件
$ sudo vim /etc/php-fpm.d/www.conf
把 user 与 group 内容修改为 nginx,如下:
user = nginx
group = nginx
2、配置 Nginx 解析 PHP
修改 vim /etc/nginx/nginx.conf
user nginx nginx;
worker_processes 4;
worker_rlimit_nofile 65535;
events {
worker_connections 10240;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /www;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root /www;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
3、配置 PHP
位置:/etc/php-fpm.d/www.conf
,修改如下:
user = nginx
group = nginx
4、创建目录
$ sudo mkdir /www
$ sudo chown -R nginx:nginx /www
5、创建测试文件
使用 ziruchu
用户进行登录并创建文件
$ echo "<?php phpinfo(); " > /www/index.php
请登录后再评论