为什么 php-fpm 监听端口 9000?
➜ ~ sudo lsof -i :9000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 23153 root 8u IPv4 0xbdb928c0ec095c13 0t0 TCP localhost:cslistener (LISTEN)
php-fpm 23154 _www 9u IPv4 0xbdb928c0ec095c13 0t0 TCP localhost:cslistener (LISTEN)
php-fpm 23155 _www 9u IPv4 0xbdb928c0ec095c13 0t0 TCP localhost:cslistener (LISTEN)
当然,我的 Mac 上安装了 PHP。但为什么它总是在 9000 上收听?这是否存在安全风险?
➜ ~ sudo lsof -i :9000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 23153 root 8u IPv4 0xbdb928c0ec095c13 0t0 TCP localhost:cslistener (LISTEN)
php-fpm 23154 _www 9u IPv4 0xbdb928c0ec095c13 0t0 TCP localhost:cslistener (LISTEN)
php-fpm 23155 _www 9u IPv4 0xbdb928c0ec095c13 0t0 TCP localhost:cslistener (LISTEN)
sure, I have PHP installed on my mac. But why is it listening on 9000 always? is it a security risk?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当 PHP 最初发布时,PHP 主要作为 Apache Web 服务器的插件运行,名为 mod-php
这是运行 PHP 的“快速且简单”的方式。您只需配置 Apache 即可加载 PHP 模块,它是所谓的 LAMP 堆栈。但这也意味着 PHP 受到 Apache 的限制,这可能会影响性能。随着性能变得越来越重要,并且随着 nginx 等其他 Web 服务器的兴起,有必要让 PHP 在自己的进程下运行,这意味着您可以独立于 Web 服务器来调整 PHP。
PHP-FPM 是一项接受处理 PHP 文件请求的服务。它并不关心您正在运行什么 Web 服务器,并且默认情况下,它接受端口 9000 上的 Web 服务器连接。 来自 nginx 默认配置
另一种默认方式是通过 Linux 套接字文件。 Ubuntu 下 Apache2 是这样做的
有安全风险吗?
不可以。在侦听套接字时,您的服务器不应配置为侦听端口 9000 上的公共流量。这就是您的网络服务器正在做的事情。只有服务器本地的东西才应该访问端口 9000。
When PHP was originally put out there, PHP mostly ran as a plugin of the Apache web server called mod-php
This was the "quick and easy" way to run PHP. You only had to have Apache configured to load the PHP module, and it was a cornerstone of the so-called LAMP stack. But it also meant that PHP was constrained by Apache, which could hamper performance. As performance became more of an issue, and with the rise of other web servers like nginx, there was a need for PHP to run under its own processes, which meant you could tune PHP separately from the web server.
PHP-FPM is a service that accepts requests to process PHP files. It doesn't care what web server you're running and, by default, it accepts those web server connections on port 9000. From the nginx default configuration
The other default way is over a Linux socket file. Here's how Apache2 does it under Ubuntu
Is it a security risk?
No. While it's listening on a socket, your server should not be configured to listen on port 9000 for public traffic. That's what your web server is doing. Only things local to your server should be accessing port 9000.