大网数据广告活动
服务器运维问答

Configuration change for Apache + PhP-FPM 7.2 necessary?

· 52CE 我爱测

Until now, I was using Ubuntu 16.04.5 Server with Apache, Nginx as a reverse proxy, PHP 7.0 + FastCGI + FPM, everything updated to last version. Everything went fine. This is one Apache virtualhost, for, say, x.com: <VirtualHost …

问题原文

原帖链接 · Karls · CC BY-SA 4.0

Until now, I was using Ubuntu 16.04.5 Server with Apache, Nginx as a reverse proxy, PHP 7.0 + FastCGI + FPM, everything updated to last version. Everything went fine.

This is one Apache virtualhost, for, say, x.com:

<VirtualHost *:8080>
    ServerName x.com
    ServerAlias www.x.com
    ServerAdmin [email omitted]
    DocumentRoot /home/user/x.com/site
    ErrorLog /home/user/x.com/logs/error.log
    CustomLog /home/user/x.com/logs/access.log combined
    <Directory /home/user/x.com/site>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
    </Directory>
    <IfModule mod_fastcgi.c>
        AddHandler php7.2-fcgi-x.com .php
        Action php7.2-fcgi-x.com /php7.2-fcgi-x.com
        Alias /php7.2-fcgi-x.com /usr/lib/cgi-bin/php7.2-fcgi-x.com
        FastCgiExternalServer /usr/lib/cgi-bin/php7.2-fcgi-x.com -socket /var/run/php/php7.2-fpm.x.com.sock -pass-header Authorization
        <Directory /usr/lib/cgi-bin>
            Require all granted
        </Directory>
    </IfModule>
</VirtualHost>

This is one FPM-pool .conf file for x.com:

[x.com]

user = user
group = www-data

listen = /run/php/php7.2-fpm.x.com.sock

listen.owner = www-data
listen.group = www-data

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

Now I'm using the same but with Ubuntu 18.04.1 and PHP, FPM, etc are 7.2. It is a clean install, not an update from the other versions.

It seems to work fine, but I'm not entirely sure, because I've seen several people posting PHP-FPM 7.2 configurations like this:

<VirtualHost *:8080>
    ServerName x.com
    ServerAlias www.x.com
    ServerAdmin [email omitted]
    DocumentRoot /home/user/x.com/site
    ErrorLog /home/user/x.com/logs/error.log
    CustomLog /home/user/x.com/logs/access.log combined
    <Directory /home/user/x.com/site>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
    <FilesMatch \.php$>
        # 2.4.10+ can proxy to unix socket
        SetHandler "proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost/"
        # Else we can just use a tcp socket:
        #SetHandler "proxy:fcgi://127.0.0.1:9000"
    </FilesMatch>
</VirtualHost>

Now, this doesn't work for me, even if I delete the FPM individual .conf files. And I simply don't understand what the line SetHandler "proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost/" does, or how one simple line can substitute all the bigger block of code that everybody's been using for FastCGI these last years.

Can somebody shed some light on this?

Thanks in advance.

已采纳解答

原帖链接 · Peter Zhabin · CC BY-SA 4.0

Well, the difference is simple. Your working approach with handlers is being backed by mod_fastcgi whereas the second one requires mod_proxy_fcgi and mod_proxy within your configuration and proxies requests to FPM socket. The latter being preferred because it does not require separate configuration and memory overhead mod_fastcgi brings along. In your case, where everything you use of mod_fastcgi functionality is just FastCGIExternalServer it makes a little sense to bring in all the machinery mod_fastcgi has within.

Your problem is likely because your current configuration uses a fancy name for a socket, that is /var/run/php/php7.2-fpm.x.com.sock whereas your attempted config uses standard /var/run/php/php7.2-fpm.sock that does not exist on your system. You should use socket name exactly as it shown in your FPM configuration (and your working config) when attempting to use mod_proxy_fcgi and also remove |fcgi://localhost/ as your FPM is only listening on a UNIX socket.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-10-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。