最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
ubuntu中php-fpm怎样与Nginx配合
时间:2026-06-26 08:41:52 编辑:袖梨 来源:一聚教程网
在Ubuntu系统中,PHP-FPM(FastCGI Process Manager)与Nginx配合工作可以提供高效的PHP处理能力。以下是配置PHP-FPM与Nginx配合的步骤:

1. 安装PHP-FPM和Nginx
首先,确保你已经安装了PHP-FPM和Nginx。你可以使用以下命令来安装它们:
sudo apt updatesudo apt install nginx php-fpm2. 配置PHP-FPM
PHP-FPM的配置文件通常位于 /etc/php/版本号/fpm/pool.d/www.conf。你需要确保PHP-FPM监听在正确的socket或端口上。
使用Unix Socket
如果你选择使用Unix Socket,编辑 /etc/php/版本号/fpm/pool.d/www.conf 文件,找到以下行并取消注释:
listen = /run/php/php7.4-fpm.sock确保Nginx配置文件中使用相同的socket路径。
使用TCP端口
如果你选择使用TCP端口,编辑 /etc/php/版本号/fpm/pool.d/www.conf 文件,找到以下行并取消注释:
listen = 127.0.0.1:9000确保Nginx配置文件中使用相同的端口。
3. 配置Nginx
编辑Nginx的默认站点配置文件 /etc/nginx/sites-available/default 或创建一个新的配置文件。
使用Unix Socket
如果你使用Unix Socket,Nginx配置文件中的 location ~ .php$ 部分应该如下所示:
server {listen 80;server_name your_domain.com;root /var/www/html;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.4-fpm.sock;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}}使用TCP端口
如果你使用TCP端口,Nginx配置文件中的 location ~ .php$ 部分应该如下所示:
server {listen 80;server_name your_domain.com;root /var/www/html;index index.php index.html index.htm;location / {try_files $uri $uri/ =404;}location ~ .php$ {include snippets/fastcgi-php.conf;fastcgi_pass 127.0.0.1:9000;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}}4. 重启服务
完成配置后,重启Nginx和PHP-FPM服务以应用更改:
sudo systemctl restart nginxsudo systemctl restart php7.4-fpm5. 测试配置
创建一个简单的PHP文件(例如 info.php)放在你的网站根目录下,内容如下:
<?phpphpinfo();?>访问 http://your_domain.com/info.php,如果看到PHP信息页面,说明配置成功。
通过以上步骤,你就可以在Ubuntu系统中成功配置PHP-FPM与Nginx配合工作。
相关文章
- 明末渊虚之羽防具有哪些排名 07-02
- 如何获取和平精英皮肤照片 07-02
- 空洞骑士丝之歌如何获取制造金属 07-02
- 鱼骨头螃蟹阵容如何搭配 07-02
- 战魂旅人玩法是什么 07-02
- 无限暖暖祝你幸福发饰如何获取 07-02