Apache: "File Not Found" after setting up php-fpm chroot

This is resolved. There were two issues with my above code.

Issue #1 - Only Apache 2.4.10 and above can support sockets

The default version of Apache that comes in the base CentOS repositories (Apache 2.4.6) only support TCP ports. The above code is therefore incorrect, and the listen directive in the php-fpm config file needed to be changed to something like this:

listen = 127.0.0.1:9001

I also made the appropriate change in my http.d conf file, but in addition, I also switched to using the ProxyPassMatch directive instead of using the FilesMatch directive. So my code then became:

ProxyPassMatch "^/(.*\.php)$" "fcgi://127.0.0.1:9001/site1.com"

Note that this code is still wrong... see below

Moving on...

Issue #2 - Relevant Paths

The path in the ProxyPassMatch directive (or, in the case of my older code using the FilesMatch directive) inside my http.d conf file becomes relative to the chroot. It is not relative to the www document root (if different).

So my code in my http.d conf file became:

ProxyPassMatch "^/(.*\.php)$" "fcgi://127.0.0.1:9001/www/$1"

And voila! I have a php-fpm chroot.


php-fpm has a bug with chroot and path.

for example with index.php in www

chroot = /home/www/site1.com
chdir = /www

with this config php-fpm write this path :

/home/www/site1.com/home/www/site1.com/www

one solution is to create a symbolic link in shell :

cd /home/www/site1.com
mkdir -p home/www
cd home/www
ln -s /home/www/site1.com site1.com

but it is not clean.

https://bugs.php.net/bug.php?id=55322

https://bugs.php.net/bug.php?id=62279


Some people might receive this error because of 2 things.

  • Wrong relative paths in php.ini
    In case you specify open_basedir, doc_root, user_dir, session.save_path, upload_tmp_dir (and others) in your PHP-FPM.conf, then these paths must be relative to chroot.
    For example:

chroot = /var/www
php_admin_value[doc_root] = /htdocs
;All paths must be relative to chroot since after chrooting PHP does not know about the absolute path

  • cgi.fix_pathinfo = 1 in php.ini
    TL;DR just change it to 0.
    For some reasons this value affects your PHP-FPM even though this parameter is ment to be for CGI only.
    You should read more about this parameter since it may break other things too, more here