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 x@mail.com
    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 x@mail.com
    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.

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.

  • Thanks for your explanation @PeterZhabin, didn't know that. I did change the name of the Unix socket when testing, but I didn't delete the |fcgi://localhost/ part, since I didn't understand it. Couple questions: I've got more users/websites, so more fpm .conf's. Then, do I just delete them and use the corresponding socket (x.com.sock, y.com.sock, etc) for each site? Will it just perform well with mod_proxy? I thought FastCGI was far better and efficient than mod_proxy_fcgi, but clearly I was wrong. – Karls Oct 7 '18 at 13:46
  • Your .conf files are for FPM and they are required so that when you start an FPM service it would create corresponding sockets. If you delete them, no FPM pools will be created when you start php-fpm, no sockets will be created and you will receive errors when Apache would attempt to proxy requests. – Peter Zhabin Oct 7 '18 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.