php-fpm will restart if you send a USR2 signal to the main process:
sudo kill -USR2 php-fpm_main_process_id
So we just need to instruct php-fpm to record its pid somewhere. In this example, I'll assume you want to save it at /etc/private/php-fpm.pid, and that php-fpm runs as user _php. First, add this line to the configuration file:
pid = /etc/php-fpm.pid
Then create the file /etc/php-fpm.pid, and make sure php-fpm has permission to modify it:
For me I had just upgraded via apt and the service restart wasn't working. I ended up needing to kill the existing processes before it worked using: killall php5-fpm
To allow the PHP-FPM restart script to work, you must use specify a PID file in your php-fpm.conf file. i.e.
pid = /var/run/php-fpm/php-fpm.pid
The default value for pid in php-fpm.conf is nothing, which means to not create a PID file, which means that the restart script can't tell which process to end during the restart.
sudo systemctl enable php-fpm // Just incase is disabled. Also ensures it starts automatically with the server
sudo systemctl start php-fpm // Start the service
sudo systemctl stop php-fpm // Stop the service
sudo systemctl status php-fpm // View status
Note: prepend
sudo
if not rootUsing SysV Init scripts directly:
Using service wrapper script
Using Upstart (e.g. ubuntu):
Using systemd (newer servers):
Or whatever the equivalent is on your system.
For Mac OS X, this is what I do:
Make a script
/usr/local/etc/php/fpm-restart
:Then:
make sure /usr/local/sbin is in your $PATH
then just call it from the terminal fpm-restart and BOOM!!
Usually,
service php5-fpm restart
will do fine, on an up-to-date distribution.But somtimes, it fails, telling you
restart: Unknown instance:
(or such).Now, if you do not like to reboot your server, just kill the processes and have a fresh start (edited as of here):
This should work:
For Mac OSX
brew services restart php56
worked for me.I had a problem restarting php7-fpm, because I didn't knew how exactly the service was named. This function gave me the answer:
service --status-all
php7-fpm service in my Ubuntu was called
php7.0-fpm
, so I did:service php7.0-fpm restart
php-fpm will restart if you send a USR2 signal to the main process:
So we just need to instruct php-fpm to record its pid somewhere. In this example, I'll assume you want to save it at
/etc/private/php-fpm.pid
, and that php-fpm runs as user _php. First, add this line to the configuration file:Then create the file
/etc/php-fpm.pid
, and make sure php-fpm has permission to modify it:Now, next time php-fpm starts, you'll be able to get its pid and restart it like this:
Or you can combine these into a single command:
For me I had just upgraded via apt and the service restart wasn't working. I ended up needing to kill the existing processes before it worked using: killall php5-fpm
To allow the PHP-FPM restart script to work, you must use specify a PID file in your php-fpm.conf file. i.e.
The default value for pid in php-fpm.conf is nothing, which means to not create a PID file, which means that the restart script can't tell which process to end during the restart.
On CentOS 7