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 = 127.0.0.1:9000
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>
</Proxy>
<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/"
</If>
</FilesMatch>
I've set up a test site as follows:
<VirtualHost 192.168.1.35:80>
ServerAdmin webmaster@example.com
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
</Directory>
</VirtualHost>
(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 192.168.1.41:54578] AH01079: failed to make connection to backend: httpd-UDS
Hopefully someone can tell me where I'm going wrong!
Edit:
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 127.0.0.1:8000 (*) failed
[Sun Jul 22 23:25:08.066548 2018] [proxy_fcgi:error] [pid 16319] [client 192.168.1.41:56396] 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?
Thanks,
James
Best Answer
Since you are using a TCP socket proxy on
<Proxy "fcgi://localhost:9000/" enablereuse=on max=10> </Proxy>
The issue is caused by
SetHandler "proxy:fcgi://localhost/:9000"
For some reason Apache interprets the slash as a directory separator and defaults to port
8000
for the proxy.To resolve the issue simply remove the
/
before:9000
SetHandler "proxy:fcgi://localhost:9000"
Ensure your php-fpm configuration matches:
I highly recommend you declare an IP address instead. localhost is kind of a catch-all.
Below is a suggested Apache virtual host and php-fpm configuration when not using a Unix Domain Socket (UDS).
9001
is used to not conflict with the default[www]
php-fpm pool and allow you to create a separate pool configuration.Ensure your MPM configuration does not conflict with your current configurations.
You can optionally replace the TCP socket configuration in favor of using a UDS.