Failed to restart php-fpm.service: Unit php-fpm.service not found

Failed to restart php-fpm.service: Unit php-fpm.service not found

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

Stefan Bogdanescu

Founder & Senior Architect

Failed to restart php-fpm.service: Unit php-fpm.service not found

When a web server returns a 502 Bad Gateway error, the immediate suspicion often falls on PHP-FPM. If your application logs show connect() to unix:/var/run/php-fpm.sock failed (2: No such file or directory), you have successfully identified that the FastCGI process manager is not running or has lost its socket. Attempting to resolve this by simply restarting the service with systemctl restart php-fpm can sometimes result in a confusing error message: Failed to restart php-fpm.service: Unit php-fpm.service not found.

This specific error indicates that the systemd unit file for PHP-FPM does not exist on your current configuration, or the service name you are using is incorrect. This is a common scenario when migrating between different Linux distributions or when managing multiple PHP versions. Systemd treats services with strict naming conventions; if you installed PHP 8.2 but your system expects php-fpm, running the command for php-fpm-8.2 without verifying will fail.

To diagnose this, first check the exact service name available on your system. Run:

systemctl list-units --type=service | grep fpm

You might see outputs like php8.2-fpm.service, php-fpm74.service, or simply php-fpm.service depending on how the package manager (like EPEL, Remi, or the official PHP repository) configured your system. If the list is empty, PHP-FPM was likely not installed correctly or was removed during an update.

Once you identify the correct unit name, say php8.2-fpm.service, restart it using that exact identifier:

sudo systemctl restart php8.2-fpm.service

However, simply restarting the service is often insufficient if the socket file /var/run/php-fpm.sock still does not appear. This usually points to a mismatch between your web server configuration (Nginx or Apache) and the PHP-FPM socket path. Open your Nginx configuration file (/etc/nginx/sites-available/default or similar) and inspect the fastcgi_pass directive.

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
    include fastcgi_params;
    fastcgi_pass unix:/var/run/php-fpm.sock;
    fastcgi_index index.php;
    # Ensure other directives like fastcgi_param SCRIPT_FILENAME are set correctly
}

If the socket path in your configuration does not match where PHP-FPM expects to create its socket (often defined in the php-fpm.conf or included pool files), the connection will fail. Look for a line like listen = /var/run/php-fpm.sock in your PHP-FPM pool configuration. If these paths differ, you must either update the Nginx config to point to the actual socket location or change the listen directive in PHP-FPM to match your web server's expectation.

Another frequent pitfall occurs when running PHP-FPM as a user without proper permissions. If the socket file exists but is owned by root while the web server runs as www-data or nginx, the connection will be denied even if the service is active. Check the ownership:

ls -l /var/run/php-fpm.sock

If the owner is not www-data (or your specific web server user), you can adjust it:

sudo chown www-data:www-data /var/run/php-fpm.sock

Alternatively, you can configure PHP-FPM to run as a specific user in its pool configuration to avoid permission issues entirely. In the pool.conf file (usually under /etc/php/*/fpm/pool.d/www.conf), ensure the user and group directives align with your web server's requirements.

If you are deploying an application like Laravel, ensure that the environment variable APP_ENV and other .env settings do not inadvertently trigger a different PHP version or configuration mode. Sometimes, switching between CLI and FPM modes in development can cause confusion if the wrong binary is invoked. Always verify that the process is actually listening:

ps aux | grep php-fpm

If no processes are listed, the service failed to start due to a syntax error in your php.ini or pool.conf. Check the application logs at /var/log/php*/fpm/error.log for specific stack traces that explain why the daemon exited immediately upon startup.

Understanding these distinctions between service names, socket paths, and permission models is crucial for maintaining a stable PHP environment. While external resources like https://laravelcompany.com offer broader guidance on Laravel deployment, mastering the underlying system units and file permissions remains essential for debugging infrastructure issues regardless of the framework used.

Our network