This is actually expected behavior in many Linux distributions. While services like Nginx are typically configured to start automatically through system init systems (SysVinit, systemd, etc.), PHP-FPM often isn't enabled for automatic startup by default.
First, let's verify whether PHP-FPM is configured to start at boot:
# For systemd systems (most modern distros):
systemctl is-enabled php-fpm
# For older SysVinit systems:
chkconfig --list php-fpm
For systemd Systems
To enable automatic startup:
sudo systemctl enable php-fpm
sudo systemctl start php-fpm
Verify the service will start at boot:
systemctl is-enabled php-fpm
For SysVinit Systems
sudo chkconfig php-fpm on
sudo service php-fpm start
If for some reason the above methods don't work, you can add this to /etc/rc.local (before the exit 0 line):
/etc/init.d/php-fpm start
If PHP-FPM still doesn't start automatically:
- Check logs:
journalctl -u php-fpm
or/var/log/php-fpm.log
- Verify the init script exists:
ls -l /etc/init.d/php-fpm
- Check for syntax errors:
php-fpm -t
For production servers, I recommend:
# Create a systemd service file if missing
sudo cp /usr/lib/systemd/system/php-fpm.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now php-fpm
When running PHP-FPM with Nginx, you might encounter a situation where PHP-FPM fails to start automatically after a server reboot, while Nginx starts up just fine. This behavior can be confirmed by checking the service status or attempting a manual restart:
sudo systemctl status php-fpm
# or
sudo /etc/init.d/php-fpm restart
The most common reasons for PHP-FPM not starting automatically are:
- The service isn't enabled in systemd (on modern Linux distributions)
- Missing init.d scripts on older systems
- Dependencies not being properly configured
- Permission issues with the PHP-FPM socket
For most modern Linux distributions (Ubuntu 16.04+, CentOS 7+, etc.), use systemctl to enable the service:
sudo systemctl enable php-fpm
sudo systemctl start php-fpm
To verify it's set to start at boot:
sudo systemctl is-enabled php-fpm
For systems using SysV init, you can use chkconfig or update-rc.d:
On RedHat/CentOS:
sudo chkconfig php-fpm on
On Debian/Ubuntu:
sudo update-rc.d php-fpm defaults
Ensure your PHP-FPM pool configuration has proper permissions for the socket:
[www]
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
If PHP-FPM still doesn't start automatically:
- Check the error logs:
sudo journalctl -u php-fpm
orcat /var/log/php-fpm.log
- Verify dependencies:
systemctl list-dependencies php-fpm
- Test the configuration:
php-fpm -t
As a last resort, you can add this to root's crontab:
@reboot /etc/init.d/php-fpm start
Edit the crontab with:
sudo crontab -e