18

I'm running PHP-FPM and Nginx, occasionally, for whatever reason, I have to reboot the server. Once the server is running again, the nginx service automatically starts, however, PHP-FPM does not. This can be seen when I run the command sudo /etc/init.d/php-fpm restart immediately after a reboot and get the result:

$ sudo /etc/init.d/php-fpm restart
Stopping php-fpm:                                          [FAILED]
Starting php-fpm:                                          [  OK  ]

Is this expected behaviour? What is the best way to make PHP-FPM automatically start? Is there a config option anywhere, or do I have to add the command to one of the Linux startup scripts?

Thanks.

2
  • Which linux distribution are you using? How did you installed php-fpm? From a package or from sources?
    – Lætitia
    Dec 20, 2012 at 16:20
  • It's running on an Amazon EC2 Linux instance, PHP-FPM was installed using yum install -y php-fpm
    – SteveEdson
    Dec 20, 2012 at 16:25

4 Answers 4

28

So set it up to start at boot:

chkconfig php-fpm on
3
  • 1
    As simple as that, brilliant! Cheers
    – SteveEdson
    Dec 20, 2012 at 16:27
  • bash: chkconfig: command not found Dec 7, 2021 at 20:14
  • Solution for chkconfig: command not found: update-rc.d php-fpm enable (you may need to specify the specific fpm, like php8.3-fpm). stackoverflow.com/a/23708174/4249483
    – Aldo
    Dec 7, 2023 at 8:03
8

I just ran into this very problem on Ubuntu 16.04 and I'm leaving my answer here for future users from Google who stumble onto the problem. Since chkconfig is mostly specific to CentOS, it obviously doesn't exist on Ubuntu. Apparently, to get a custom-built PHP (php-fpm SAPI) to start at boot under systemd, which is new to Ubuntu 16.04 (previously, Upstart), it needs to be registered with the system beyond just dropping the init.d script into /etc/init.d/. To register the script, I ran:

update-rc.d php-fpm defaults

A reboot and subsequent ps aux confirmed that php-fpm was indeed starting at boot. It was also added to /etc/init.d/.depend.start.

Other thoughts: Ubuntu Upstart was nice enough so that I never had to run update-rc.d after placing an init.d script - it just worked. Completely forgot about that command.

3
  • 2
    The original question being about Amazon Linux, I can't say how many Ubuntu users will see it. As for 16.04 and systemd, the thing to do is use a proper systemd unit rather than the old-style upstart or ancient init script. You ought to be able to find a usable systemd unit with the distro package, or elsewhere. Aug 6, 2016 at 9:41
  • 1
    I'm a Ubuntu 14.04 user and this helped me, thank you! PS: sudo might be needed for that command. Jan 22, 2017 at 21:52
  • If you get an error regarding auoms is broken -- update the init info block in /etc/init.d/auoms per this release: github.com/microsoft/OMS-Auditd-Plugin/pull/62
    – Crayons
    Jan 18, 2021 at 18:01
5

Since CentOS 7 you simply need to enable the services via systemctl:

systemctl enable php-fpm

You can check if it's running afterwards via:

systemctl status php-fpm
-1

You could add some commands to the .bashrc startup script:

Open .bashrc:

nano .bashrc

Paste some command to be run at startup:

(check which commands work for you)

# Start fpm-services
sudo /etc/init.d/php-fpm start
sudo /etc/init.d/php8.3-fpm start
sudo /etc/init.d/php8.2-fpm start
sudo /etc/init.d/php8.1-fpm start
sudo /etc/init.d/php8.0-fpm start
sudo /etc/init.d/php7.4-fpm start

1
  • 1
    this will only start the services after user login. If you really still have ancient init.d scripts the answer by CubicleSoft is the proper way. Dec 7, 2023 at 8:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .