No such file or directory: AH02454: FCGI: attempt to connect to Unix domain socket /var/run/php/php5.6-fpm.sock (*) failed
You have configured your Apache virtual host correctly for PHP 5.6 FastCGI communication. Your SetHandler directive points to the standard Unix domain socket at /var/run/php/php5.6-fpm.sock, and your phpinfo() output confirms the interpreter version matches your expectations. However, after introducing Mod_Ruid2 to restrict execution rights via RUidGid admin0 admin0, Apache can no longer reach the backend. The error log explicitly states: (2)No such file or directory: AH02454: FCGI: attempt to connect to Unix domain socket /var/run/php/php5.6-fpm.sock (*) failed.
This failure is not a syntax error in your Apache configuration; it is an access control issue triggered by the switch in user context. When Apache processes a request, it runs as the apache (or www-data) user by default. To execute PHP scripts via FPM, this Apache process must be able to read and write to the Unix socket file.
The error message provides a crucial clue: the asterisk in ( *) indicates that the connection attempt failed because the socket file itself does not exist or cannot be accessed. This often happens when the ownership of the socket changes after you applied RUidGid. Mod_Ruid2 switches the effective user and group for the request to admin0. If your PHP-FPM pool configuration (/etc/php/5.6/fpm/pool.d/www.conf) was set to run as a specific user (e.g., www-data), and you are now trying to execute code as admin0, the socket permissions might not allow the transition, or the socket path has shifted due to how FPM initializes under the new UID/GID context.
However, looking closely at your virtual host configuration, there is a more immediate structural problem causing this specific "No such file" error. You are using RDocumentChRoot. This directive attempts to change the root directory for the document root inside the Apache process. The syntax you provided:
RDocumentChRoot /var /www/html
is incorrect. The RDocumentChRoot directive in Mod_Ruid2 expects a single argument representing the new root path, not two separate arguments separated by a space. This malformed directive likely causes Apache to fail in setting up its internal file system context correctly before it even attempts the FCGI handshake. More critically, if you are using RDocumentChRoot, you must ensure that the Mod_Ruid2 module is loaded and configured to handle the UID/GID switch before the request hits the FCGI handler.
The standard approach to fixing this involves ensuring the socket file exists and has the correct permissions before Apache attempts to bind to it. The socket is created by PHP-FPM, not Apache. If your PHP-FPM process manager (php-fpm) is configured to run as a different user than what Apache expects, or if RUidGid forces a context where the FPM socket is unreadable, the connection will fail.
To resolve this, you need to verify two things:
- Socket Permissions: Ensure that
/var/run/php/php5.6-fpm.sockexists and is owned by a user thatapache(orwww-data) can access. Typically, this file is owned bywww-data:www-datawith mode0770. If Mod_Ruid2 changes the UID toadmin0, ensure that the socket permissions allow cross-user interaction if your architecture requires it. - Mod_Ruid2 Configuration: The directive
RDocumentChRootis deprecated and often unnecessary when usingSetHandler proxy:unix:.... Instead of chrooting the entire document root, you should focus on setting the correct UIDs/GIDs for the request handler itself.
Consider modifying your configuration to explicitly set the user before handling the PHP request if you strictly require Mod_Ruid2:
RUidGid admin0 admin0
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/"
</FilesMatch>
If the socket path is missing entirely, check if your PHP-FPM service is running and listening on that specific socket. You can verify this with ls -la /var/run/php/. If the file is missing, restart PHP-FPM: systemctl restart php5.6-fpm.
Finally, be aware that mixing complex chrooting with FCGI sockets via proxy: handlers is fragile. A more robust solution often involves configuring PHP-FPM to listen on a TCP port instead of a Unix socket if you need granular control over UID/GID switching, or ensuring the admin0 user exists and has write permissions to the socket file specifically. The error (2)No such file or directory usually implies the socket file is physically absent in the expected location because the process creating it (PHP-FPM) did not start successfully under the new constraints, or the path defined in Apache does not match the actual socket created by FPM.