最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php-fpm在ubuntu如何连接
时间:2026-08-13 09:17:49 编辑:袖梨 来源:一聚教程网
在 Ubuntu 上,PHP-FPM(FastCGI Process Manager)通常不“直接连接”,而是由 Web 服务器(Nginx / Apache)通过 FastCGI 协议调用。下面按常见场景给你说明。

一、PHP-FPM 是什么?
PHP-FPM 是一个 FastCGI 服务,监听在某个端口或 Unix Socket 上,等待 Web 服务器请求。
二、安装 PHP-FPM(Ubuntu)
sudo apt updatesudo apt install php-fpm
查看版本:
php -v三、确认 PHP-FPM 监听方式(重点)
查看 PHP-FPM 配置文件
ls /etc/php/*/fpm/pool.d/通常是:
/etc/php/8.2/fpm/pool.d/www.conf查看监听方式
grep listen /etc/php/8.2/fpm/pool.d/www.conf常见两种:
Unix Socket(推荐)
listen = /run/php/php8.2-fpm.sockTCP 端口
listen = 127.0.0.1:9000修改后重启:
sudo systemctl restart php8.2-fpm四、Nginx 连接 PHP-FPM(最常见)
安装 Nginx
sudo apt install nginxNginx 配置示例
server {listen 80;
server_name localhost;
root /var/www/html;
index index.php;
location ~ .php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Socket 方式
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
# TCP 方式(二选一)
# fastcgi_pass 127.0.0.1:9000;
}
}
重启 Nginx
sudo systemctl restart nginx五、Apache 连接 PHP-FPM
启用 proxy_fcgi
sudo apt install apache2sudo a2enmod proxy_fcgi
sudo a2enconf php8.2-fpm
重启 Apache
sudo systemctl restart apache2Apache 会自动连接 PHP-FPM(默认 socket)
六、测试 PHP-FPM 是否成功
创建测试文件:
echo "<?php phpinfo();" | sudo tee /var/www/html/info.php浏览器访问:
http://服务器IP/info.php看到 PHP 信息页面
七、常见问题排查
502 Bad Gateway
- PHP-FPM 没启动
- socket 路径错误
- socket 权限不足
检查:
systemctl status php8.2-fpmls -l /run/php/
访问 PHP 直接下载
- Nginx / Apache 没有正确配置 fastcgi_pass
八、一句话总结
PHP-FPM 不直接“连接”,而是 Web 服务器通过 socket 或端口调用它。
如果你告诉我:
- 用的是 Nginx 还是 Apache
- Ubuntu 版本
- PHP 版本
我可以给你一份完全适配你环境的配置。
相关文章
- 米哈游通行证登录入口地址(网页版入口) 08-13
- (数据库)数据库分类 08-13
- 迅捷 FWR100 无线路由器设置无线MAC地址过滤设置 08-13
- MySQL数据库——数据库操作 08-13
- 火车票余票查询入口-火车票时刻表查询入口 08-13
- 数据库|数据库入门(二) 08-13