Apache 2.4 with PHP-FPM 5.6 on Centos 6

James Shields asked:

I’m trying to get PHP working over FPM on Centos.

On the FPM side, /etc/php-fpm.d/www.conf is pretty much the default values. I’m left it using a TCP port as follows (I may want to change to a file port later for performance, but lets walk before we run):

listen =

The php-fpm service starts without any problems.

So I think my problems are on the Apache side. I added a config file conf.d/php-fpm.conf containing the following:

# Defining a worker will improve performance
# And in this case, re-use the worker (dependent on support from the fcgi application)
# If you have enough idle workers, this would only improve the performance marginally
<Proxy "fcgi://localhost:9000/" enablereuse=on max=10>
<FilesMatch "\.php$">
    <If "-f %{REQUEST_FILENAME}">
        # Pick one of the following approaches
        # Use the standard TCP socket
        SetHandler "proxy:fcgi://localhost/:9000"
        # If your version of httpd is 2.4.9 or newer (or has the back-ported feature), you can use the unix domain socket
        #SetHandler "proxy:unix:/path/to/app.sock|fcgi://localhost/"

I’ve set up a test site as follows:

    ServerAdmin [email protected]
    ServerName centos.local
    ServerAlias www.centos.local

    #ProxyPassMatch "^/(.*\.php)$" "unix:/var/run/myappname.sock|fcgi://localhost/webroot"

    DirectoryIndex index.html

    ErrorLog /var/log/httpd24/centos.error.log
    CustomLog /var/log/httpd24/centos.access.log combined

    <Directory /var/www/vhosts/centos.local/httpdocs>
        DocumentRoot /var/www/vhosts/centos.local/httpdocs
        # Allow .htaccess
        AllowOverride All
        Require all granted

(I’m not sure if the ProxyPassMatch is needed, I seem to get the same result whether I have it or not).

The httpd service starts, and html pages serve fine, but if I try to load a PHP file, I get Service Unavailable in the browser, and the following written to the error log:

[Sun Jul 22 21:13:21.813760 2018] [proxy:error] [pid 14621] (2)No such file or directory: AH02454: FCGI: attempt to connect to Unix domain socket /var/run/myappname.sock (localhost) failed
[Sun Jul 22 21:13:21.814003 2018] [proxy_fcgi:error] [pid 14621] [client] AH01079: failed to make connection to backend: httpd-UDS

Hopefully someone can tell me where I’m going wrong!


As suggested, I’ve taken out the ProxyPassMatch. I now get the following error:

[Sun Jul 22 23:25:08.066467 2018] [proxy:error] [pid 16319] (13)Permission denied: AH00957: FCGI: attempt to connect to (*) failed
[Sun Jul 22 23:25:08.066548 2018] [proxy_fcgi:error] [pid 16319] [client] AH01079: failed to make connection to backend: localhost

It seems to be failing to find the FPM on port 8000, but I can’t see anything in any of my config files. What am I missing?



My answer:

The tutorial you’ve followed shows three distinct methods for proxying PHP to php-fpm. They are all mutually exclusive, and you’re meant to choose exactly one of them.

I recommend you stick with the Proxy via handler approach as in your first code block, and remove the TCP socket (IP and port) approach from your second code block. That is, delete the following:

    ProxyPassMatch "^/(.*\.php)$" "unix:/var/run/myappname.sock|fcgi://localhost/webroot"

It doesn’t reference the TCP socket that php-fpm is listening on anyway.

BTW you should also fix the DirectoryIndex but that’s another issue.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.