NGINX: connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory)

NGINX: connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory)

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

NGINX: connect() to unix:/var/run/php7.0-fpm.sock failed (2: No such file or directory)

You are seeing the error connect() to unix:/var/run/php7.0-fpm.sock failed because, despite what ls -l /var/run/php suggests, the socket file you expect does not actually exist at the path NGINX is trying to reach.

The confusion stems from how Linux handles directory listings versus absolute paths. When you run ls -l /var/run/php, the output shows a symbolic link named php7.0-fpm.sock. However, this link points to /var/run/php5/fpm.sock (or similar), not /var/run/php7.0-fpm.sock. The ls command displays the target of the symlink when listing contents of the directory it resides in, but if you try to access that specific file path directly—either by typing ls /var/run/php7.0-fpm.sock or configuring NGINX to use that path—the system cannot find a file with that exact name at that location.

The root cause is almost always that the PHP-FPM pool configuration was not updated when you upgraded from PHP 5 to PHP 7. The package manager installed php7.0-fpm, which creates its socket in /var/run/php7.0/ or, more commonly on Ubuntu, expects it at a path defined by the listen directive in the FPM pool configuration. By default, PHP-FPM often defaults to listening on a Unix socket that might not match the hardcoded path in your NGINX configuration, or the symlink created during installation points to an old PHP version's directory.

Verifying the Actual Socket Path

Before modifying NGINX, you must locate where PHP 7 is actually listening. Run the following commands to inspect the running FPM process and its environment variables:

ps aux | grep php7.0-fpm
systemctl status php7.0-fpm

If systemctl is not available (common in older setups like Ubuntu 16.04), check the PID file location:

ls -l /var/run/php/

Look for a socket file inside /var/run/php/. If you see a symlink, follow it to see where it points. If there is no symlink and only a .pid file, PHP-FPM might be configured to listen on 127.0.0.1:9000 instead of a Unix socket, or the socket path is defined dynamically in /etc/php/7.0/fpm/pool.d/www.conf.

Check the pool configuration:

ls -l /etc/php/7.0/fpm/pool.d/
cat /etc/php/7.0/fpm/pool.d/www.conf | grep listen

You will likely see a line like listen = /var/run/php7.0-fpm.sock or listen = unix:/var/run/php7.0-fpm.sock. If the directory /var/run/php7.0/ does not exist, you may need to create it and ensure permissions are correct:

sudo mkdir -p /var/run/php7.0
sudo chown www-data:www-data /var/run/php7.0
sudo chmod 755 /var/run/php7.0

Then restart PHP-FPM:

sudo service php7.0-fpm restart

Fixing the NGINX Configuration

Your Ansible playbook likely uses a template file nginx.conf that references /var/run/php7.0-fpm.sock. If the socket does not exist at that path, you have two options: create the symlink or update the configuration to match the actual socket location.

If PHP-FPM is configured to listen on a different path (e.g., /var/run/php/php7.0-fpm.sock), update your NGINX fastcgi_pass directive accordingly. In your Ansible template, ensure the path matches exactly:

location / {
    try_files $uri $uri/ =404;
    include fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php7.0-fpm.sock; # Ensure this matches reality
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

Alternatively, if you want to keep the path as /var/run/php7.0-fpm.sock, create a symbolic link from the actual socket location:

sudo ln -s /path/to/actual/socket /var/run/php7.0-fpm.sock
sudo chown www-data:www-data /var/run/php7.0-fpm.sock
sudo chmod 666 /var/run/php7.0-fpm.sock

After making changes, restart NGINX as your playbook does:

sudo service nginx restart

Common Pitfalls in Automation

When automating this setup with Ansible, be cautious about handler definitions. Your playbook references restart php5-fpm in the notify section for PHP 7 configuration changes. This is a critical bug; it will attempt to restart the wrong PHP version service. Update your handlers and notify blocks to strictly reference php7.0-fpm.

Additionally, ensure that the www-data user owns both the NGINX worker processes and the PHP-FPM pool. Mismatched ownership can cause permission denied errors even if the socket file exists. Finally, verify that fastcgi_params includes all necessary variables for Laravel's autoloading, especially if using a specific version of FastCGI parameters that differs from the default provided by the package.

By aligning the actual socket path with your NGINX configuration and correcting the service management logic in your automation scripts, you can resolve the connect() error and get your PHP application serving requests correctly.

Our network