要配置Ubuntu上的PHP-FPM与Nginx联动,你需要按照以下步骤操作:
1. 安装PHP-FPM
首先,确保你已经安装了PHP-FPM。如果没有安装,可以使用以下命令进行安装:
sudo apt update
sudo apt install php-fpm
2. 配置PHP-FPM
PHP-FPM的默认配置文件通常位于 /etc/php/7.x/fpm/pool.d/www.conf(其中 7.x 是你的PHP版本)。你可以根据需要进行一些基本配置,例如监听地址和端口。
sudo nano /etc/php/7.x/fpm/pool.d/www.conf
找到以下行并进行修改:
;listen = /run/php/php7.x-fpm.sock ; 默认使用Unix socket
listen = 127.0.0.1:9000 ; 使用TCP/IP socket
3. 配置Nginx
接下来,配置Nginx以使用PHP-FPM处理PHP请求。编辑Nginx的站点配置文件,通常位于 /etc/nginx/sites-available/your-site。
sudo nano /etc/nginx/sites-available/your-site
确保你的配置文件中有以下内容:
server {
listen 80;
server_name your-domain.com www.your-domain.com;
root /var/www/your-site;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.x-fpm.sock; ; 使用Unix socket
# 或者使用TCP/IP socket
# fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
4. 启用站点配置
创建一个符号链接以启用站点配置:
sudo ln -s /etc/nginx/sites-available/your-site /etc/nginx/sites-enabled/
5. 检查Nginx配置并重启
检查Nginx配置文件是否有语法错误:
sudo nginx -t
如果没有错误,重启Nginx以应用更改:
sudo systemctl restart nginx
6. 启动PHP-FPM
确保PHP-FPM服务正在运行:
sudo systemctl start php7.x-fpm
sudo systemctl enable php7.x-fpm
7. 测试配置
创建一个简单的PHP文件来测试配置是否成功。例如,在 /var/www/your-site 目录下创建一个 info.php 文件:
echo "" | sudo tee /var/www/your-site/info.php
然后在浏览器中访问 http://your-domain.com/info.php,你应该能看到PHP信息页面。
通过以上步骤,你应该已经成功配置了Ubuntu上的PHP-FPM与Nginx的联动。
以上就是关于“Ubuntu php-fpm与Nginx如何配置联动”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm