Can't have Wordpress websites to work with nginx on subdomain, connect() to unix:/run/php/php7.2-fpm.sock failed error

February 10, 2019 1.2k views
Nginx WordPress PHP Ubuntu 18.04

Hello,
I’m using a droplet to run a couple of static websites, each on their own domains, like:

mydomain.com
otherdomain.com
thirddomain.com

and so on.

Then, I use the same droplet to test other websites (mainly Wordpress sites), using subdomains this way:

website.mydomaincom
website2.otherdomain.com
... 

For each of these I added an A record on the dns records management section in the DigitalOcean admin and then a nginx configuration file for each website like this one:

server {
        root /var/www/website.com
        index index.php index.html index.htm;

        server_name website.mydomain.com;

        location / {
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

        location ~ \.php$ {
              include snippets/fastcgi-php.conf;
              include fastcgi_params;
              fastcgi_pass unix:/run/php/php7.2-fpm.sock;
              fastcgi_param SCRIPT_FILENAME /var/www/website.com$fastcgi_script_name;
              fastcgi_param PHP_VALUE post_max_size=20M;
              fastcgi_param PHP_VALUE upload_max_filesize=20M;
        }
}

When trying to access the url website.domain.com I get an error 404.
In the logs there’s this:

2019/02/10 18:26:47 [crit] 9914#9914: *30 connect() to unix:/run/php/php7.2-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 77.11.130.163, server: website.domain.com, request: “GET /favicon.ico HTTP/1.1”, upstream: “fastcgi://unix:/run/php/php7.2-fpm.sock:”, host: “website.domain.com”
2019/02/10 18:26:47 [error] 9914#9914: *30 open() “/usr/share/nginx/html/50x.html” failed (2: No such file or directory), client: 77.11.130.163, server: website.domain.com, request: “GET /favicon.ico HTTP/1.1”, upstream: “fastcgi://unix:/run/php/php7.2-fpm.sock”, host: “website.domain.com”

I’m not sure what to do.
The thing is that till a couple of days ago this setup was actually working. What I did was upgrading the certbot. In doing so I might’ve broken something without realizing it.

Thanks for your help.

1 Answer

Hi

It’s possible php-fpm isn’t started up. Try this. Locate the php-fpm service like this:

systemctl|grep php-fpm

Then start it up:

systemctl start php7.2-fpm

Replace php7.2-fpm with the actual service name from the systemctl listing.

Cheers

  • Hi,
    thanks for your answer.

    I got no output from this:

    systemctl | grep php-fpm
    

    I tried anyway the other command and I got some errors:

    systemctl start php7.2-fpm
    
    Job for php7.2-fpm.service failed because the control process exited with error code.
    See "systemctl status php7.2-fpm.service" and "journalctl -xe" for details.
    

    And here’s what I get from the first suggested command:

    systemctl status php7.2-fpm.service
    
    php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager
       Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor prese
       Active: failed (Result: exit-code) since Mon 2019-02-11 10:30:31 CET; 4min 27
         Docs: man:php-fpm7.2(8)
      Process: 28242 ExecStart=/usr/sbin/php-fpm7.2 --nodaemonize --fpm-config /etc/
     Main PID: 28242 (code=exited, status=78)
    

    The second is a long a list of stuff like this:

    Feb 11 10:29:57 Balene systemd[28108]: Reached target Sockets.
    -- Subject: Unit UNIT has finished start-up
    -- Defined-By: systemd
    -- Support: http://www.ubuntu.com/support
    --
    -- Unit UNIT has finished starting up.
    --
    -- The start-up result is RESULT.
    
    

    I can paste it all if needed, but doesn’t seem to contain anything useful

    • Try running it manually like this:

      usr/sbin/php-fpm7.2 --nodaemonize --fpm-config /etc/path/to/7.2/php-fpm.conf
      

      Hopefully the error output helps.

      Cheers

      • I got this:

        ERROR: [/etc/php/7.2/fpm/pool.d/www.conf:37] unknown entry '#listen'
        ERROR: Unable to include /etc/php/7.2/fpm/pool.d/www.conf from /etc/php/7.2/fpm/php-fpm.conf at line 37
        ERROR: failed to load configuration file '/etc/php/7.2/fpm/php-fpm.conf'
        ERROR: FPM initialization failed
        

        Not sure why, but in thtat www.conf file there were these two lines:

        #listen = /run/php/php7.2-fpm.sock
        listen = 127.0.0.1:9000
        

        I replaced the # with a ; and now executing again your command I get another error:

        ERROR: failed to open error_log (/var/log/php7.2-fpm.log): Permission denied (13)
        ERROR: failed to post process the configuration
        ERROR: FPM initialization failed
        

        So I guess it’s a permission problem.

        These are the permissions on set on /var/log

        drwxr-xr-x 15 root  syslog 4096 Feb 11 06:25 log
        

        Inside it:

        -rw-r--r--   1 root      root                  0 Feb 11 06:25 php7.2-fpm.log
        -rw-r--r--   1 root      root                  241 Feb  5 17:42 php7.2-fpm.log.1
        -rw-r--r--   1 root      root                   76 Dec  2 06:25 php7.2-fpm.log.10.gz
        -rw-r--r--   1 root      root                   76 Nov 25 06:25 php7.2-fpm.log.11.gz
        -rw-r--r--   1 root      root                   76 Nov 19 06:25 php7.2-fpm.log.12.gz
        

        I tried changing user and group of php7.2-fpm.log to www-data, but I got the same error.

        Also, in the www.conf file there’s this:

        user = www-data
        group = www-data
        
        • Try this:

          1. Open php-fpm.conf and set the error_log entry like this:
          
          error_log = /var/log/php-fpm/error.log
          
          2. mkdir /var/log/php-fpm
          
          3. chown -R root.www-data /var/log/php-fpm
          
          4. chmod 770 /var/log/php-fpm
          
          5. systemctl restart php7.2-fpm
          

          Hopefully that helps.

          Cheers

Have another answer? Share your knowledge.