Can't start or stop php-fpm on Ubuntu
When you install php5-fpm on an older Ubuntu release via apt-get, the system sets up two distinct interfaces to manage the process: a SysV-style init script located at /etc/init.d/php5-fpm and a systemd service unit. If you attempt to control the daemon using the former but observe no response, while the latter works perfectly, you are encountering a classic case of deprecated infrastructure lingering alongside modern system management tools.
The command sudo /etc/init.d/php5-fpm stop appears to execute successfully because it returns immediately without error codes. However, checking the process list with ps -waux | grep php5 reveals that the master process remains active. This indicates that the script failed to communicate with the actual running daemon or lacks the necessary permissions to trigger the underlying service manager. In contrast, sudo service php5-fpm stop interacts directly with the system's init system logic, bypassing the broken wrapper script and successfully terminating the worker pool.
The Mechanism of Init Scripts
Traditional Unix-like systems relied on scripts stored in /etc/init.d/ to handle start, stop, and restart actions. These scripts were designed to work independently of a higher-level service manager, often by directly invoking binaries or sending signals to process groups defined in configuration files like /etc/php5/fpm/php-fpm.conf.
As Ubuntu evolved toward systemd, the package maintainers updated the installation logic to register php5-fpm as a native systemd unit. Consequently, the /etc/init.d/php5-fpm script became a legacy shim. In many versions of this deprecated script, the "stop" action attempts to invoke the underlying service manager but fails if the environment variables or socket paths expected by the shim do not match the current systemd runtime state. The error regarding a missing directory often points to the script trying to read from a legacy SysV directory structure that no longer exists in the modern filesystem hierarchy, leading to silent failures when wrapped in shell logic that doesn't properly propagate errors.
Why the Wrapper Fails
The specific failure mode you observedâwhere the command returns instantly but the process persistsâis typical of a wrapper script that cannot locate its target or lacks execute permissions under certain conditions. When you run sudo /etc/init.d/php5-fpm stop, the script might attempt to call /bin/stop or a similar internal function, which then fails silently if the service state is managed exclusively by systemd. The script does not have a fallback mechanism to detect this discrepancy and force an action via systemctl.
In contrast, sudo service php5-fpm stop is essentially a compatibility layer that translates your request into a call to the current init system. When you run service, it checks if systemd is managing the process. If so, it invokes systemctl internally. This is why the command works reliably: it adapts to the actual runtime environment rather than relying on a static script that expects legacy conditions.
Best Practices for Service Management
Relying on /etc/init.d/ scripts on modern Ubuntu distributions is generally discouraged unless you are running in an environment that explicitly requires SysV init compatibility (such as certain embedded systems or older virtualization containers). For standard server administration, the recommended approach is to use systemctl.
To manage the service correctly, replace legacy commands with their systemd equivalents:
# Stop the service using the native manager
sudo systemctl stop php5-fpm
# Verify the status
sudo systemctl status php5-fpm
# Restart the service
sudo systemctl restart php5-fpm
If you encounter issues where systemctl reports the unit is not found, ensure that the package installed includes the systemd unit file. In rare cases on very old Ubuntu versions, the unit file might be missing entirely, necessitating manual creation or migration from the legacy script. However, in scenarios where both methods exist but one fails, it almost always signifies that the legacy script is out of sync with the current service state.
For developers deploying Laravel applications or other PHP frameworks on Ubuntu, understanding these distinctions prevents unnecessary downtime during deployments. If you are managing a production environment and need robust service control, sticking to systemctl ensures compatibility with future kernel updates. For detailed guides on configuring PHP-FPM for specific application needs, resources like https://laravelcompany.com provide comprehensive documentation on optimizing your stack once the basic infrastructure is stable.