Apache PHP error: [proxy:error] No such file or directory: AH02454: FCGI: attempt to connect to Unix domain socket failed

  apache, fpm, php, sockets

I’m getting this error while trying to access a simple phpinfo script (any php). The Apache is not able to connect to the socket file of php-fpm service (Event type module enabled) saying that the file does not exists, but it does exists and has the right permission (apparently).

I found some similar questions saying about permissions and the right path of the socket file, missing directories and wrong directories (like tmp), but it is not my case.

PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Apache/2.4.41 (Ubuntu)

The error on /var/log/apache/error.log is:

[Thu Apr 08 00:52:48.491885 2021] [proxy:error] [pid 6750:tid 139911897593600] (2)No such file or directory: AH02454: FCGI: attempt to connect to Unix domain socket /var/run/apache2/listen = /var/run/php/php7.4-fpm.sock (localhost) failed
[Thu Apr 08 00:52:48.491944 2021] [proxy_fcgi:error] [pid 6750:tid 139911897593600] [client XXXXXX:13416] AH01079: failed to make connection to backend: httpd-UDS

The output of:

ls -all /var/run/php/php7.4-fpm.sock

srw-rw---- 1 www-data www-data 0 Apr  8 00:54 /var/run/php/php7.4-fpm.sock

So there is the file, owned by www-data, correct.

The output of service status showing that it is running:

service php7.4-fpm status:

● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-04-08 00:37:01 UTC; 8min ago
       Docs: man:php-fpm7.4(8)
    Process: 5625 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.4/fpm/pool.d/www.conf 74 (code=exited, status=0/SUCCESS)
   Main PID: 5613 (php-fpm7.4)
     Status: "Processes active: 0, idle: 0, Requests: 0, slow: 0, Traffic: 0req/sec"
      Tasks: 1 (limit: 18847)
     Memory: 9.7M
     CGroup: /system.slice/php7.4-fpm.service
             └─5613 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)

So, it is running and it is using /etc/php/7.4/fpm/pool.d/www.conf and /run/php/php-fpm.sock as socket path.

I confirmed that if I stoped the php7.4-fpm and started again, the socket file device is removed and recreated without any errors. Same as running php7.4-fpm with no-deamonize, no errors.

The content of www.conf is:

listen = /run/php/php7.4-fpm.sock
.
.
listen.owner = www-data
listen.group = www-data
;listen.mode = 0660

So it is using www-data, correct too.

And the output of:

ls -all /run/php/php-fpm.sock

lrwxrwxrwx 1 root root 30 Apr  7 21:31 /run/php/php-fpm.sock -> /etc/alternatives/php-fpm.sock

Now owned by root. But as they are sym link to a device, I can’t chown. I don’t think it is the problem though because the listener path configured on apache is owned by www-data. But I may be wrong.

And the content of /etc/apache2/sites-enabled/000-default.conf is:

<VirtualHost *:80>

        ServerAdmin [email protected]
        DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

     <IfModule mod_fcgid.c>
         Options +ExecCGI
         FcgidConnectTimeout 20
         AddType  application/x-httpd-php         .php
         AddHandler application/x-httpd-php .php
         Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
         ProxyPassMatch " ^/(.*.php(/.*)?)$" "unix:listen = /var/run/php/php7.4-fpm.sock|fcgi://localhost/var/www/html/"
     </IfModule>

</VirtualHost>

The output of:

ls -all /var/run/php/php7.4-fpm.sock

srw-rw---- 1 www-data www-data 0 Apr  8 00:54 /var/run/php/php7.4-fpm.sock

So Apache is pointing to the right socket file owned by www-data and Apache is running using www-data.

Yet… 503 errors just on php.

Source: Ask PHP

LEAVE A COMMENT