Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't start or stop php-fpm on Ubuntu

Tags:

php

I'm trying to install php-fpm for the first time on Ubunutu. I have installed it via

sudo apt-get install php5-fpm

When the install finishes, I run ps -waux | grep php5 to see if anything is running. I get the following:

root      9625  0.5  0.6 133612 12836 ?        Ss   22:49   0:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)

It looks like it is running, so I tried to stop it by executing:

sudo /etc/init.d/php5-fpm stop

This appears to do nothing. No error message is given on the command line and when I run ps again, the same process exists. I am able to get it to stop if I run:

sudo service php5-fpm stop

The first time I ran this command I got an error about not being able to find a directory, but the process did stop. When I start and stop the service again, it seems to work fine and I don't get an error message about a missing directory.

Can someone explain to me why the /etc/init.d/php5-fpm method does not work? All of the tutorials I've seen use this method to start and stop php5-fpm.

like image 517
CodeSmith Avatar asked May 05 '14 03:05

CodeSmith


People also ask

How do I start PHP-FPM service?

Log into WHM as root. Search “PHP-FPM” and select PHP-FPM service for Apache. Select Yes to restart the PHP-FPM service.

How do I know if PHP-FPM is installed?

Checking PHP version installed on your Linux and Unix serverOpen the terminal prompt and then type the following commands. Are you using php-fpm? Get php version using the php-fmp -v or php-fpm73 -v command.


3 Answers

Quick answer...you don't use the init.d scripts to control (stop / start /status etc) of php-fpm because it's controlled by the newer 'upstart'. Use the following service command to stop and restart etc. I think it's a bit of a 'bug' that it quietly exits without stating that it's now controlled by upstart.

More detailed look at this problem, that leads to above explanation.

I see exactly the same problem on Ubuntu 14.04, you can stop / start / get status of php5-fpm using the service commands: I.E these work fine :-

# sudo service php5-fpm status
php5-fpm start/running, process 18793
# sudo service php5-fpm stop
php5-fpm stop/waiting
# sudo service php5-fpm status
php5-fpm stop/waiting
# sudo service php5-fpm start
php5-fpm start/running, process 18949
# sudo service php5-fpm status
php5-fpm start/running, process 18949

BUT the /etc/init.d/php5-fpm command has no effect :-

# /etc/init.d/php5-fpm stop
# ps -ef | grep php
root     18949     1  0 12:15 ?        00:00:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)                    
www-data 18952 18949  0 12:15 ?        00:00:00 php-fpm: pool www                                                       
www-data 18953 18949  0 12:15 ?        00:00:00 php-fpm: pool www                                                       
root     18970 10051  0 12:17 pts/2    00:00:00 grep --color=auto php

Note nothing is returned, and the process is not stopped. Similarly for status and start versions, nothing is returned and the process is unaffected.

I found the line that it exits the init.d script on.... init_is_upstart:

# Don't run if we are running upstart
if init_is_upstart; then
    exit 1
fi

Surely it should state an error message here...like 'Use service commands to stop/start php-fpm'.

like image 162
user3647449 Avatar answered Sep 21 '22 13:09

user3647449


I had similar problem that relates to php5-fpm on Ubuntu 14.10. I have configured php5-fpm for one of the virtual hosts and when trying to browse the site i got the 503 Service Unavailable. Every time I tried

root@testupgrade:~# service php5-fpm restart
stop: Unknown instance:
php5-fpm start/running, process 2775

I got in the syslog the following:

Dec  7 14:08:53 testupgrade kernel: [  230.711612] init: php5-fpm main process (2775) terminated with status 78
Dec  7 14:08:53 testupgrade kernel: [  230.711639] init: php5-fpm main process ended, respawning
Dec  7 14:08:53 testupgrade kernel: [  230.866617] init: php5-fpm main process (2783) terminated with status 78
Dec  7 14:08:53 testupgrade kernel: [  230.866643] init: php5-fpm main process ended, respawning
Dec  7 14:08:54 testupgrade kernel: [  231.027522] init: php5-fpm main process (2791) terminated with status 78
Dec  7 14:08:54 testupgrade kernel: [  231.027548] init: php5-fpm main process ended, respawning
Dec  7 14:08:54 testupgrade kernel: [  231.137792] init: php5-fpm main process (2799) terminated with status 78
Dec  7 14:08:54 testupgrade kernel: [  231.137807] init: php5-fpm main process ended, respawning
Dec  7 14:08:54 testupgrade kernel: [  231.221146] init: php5-fpm main process (2807) terminated with status 78
Dec  7 14:08:54 testupgrade kernel: [  231.221161] init: php5-fpm main process ended, respawning
Dec  7 14:08:54 testupgrade kernel: [  231.301859] init: php5-fpm main process (2815) terminated with status 78
Dec  7 14:08:54 testupgrade kernel: [  231.301874] init: php5-fpm main process ended, respawning
Dec  7 14:08:54 testupgrade kernel: [  231.381635] init: php5-fpm main process (2823) terminated with status 78
Dec  7 14:08:54 testupgrade kernel: [  231.381649] init: php5-fpm main process ended, respawning
Dec  7 14:08:54 testupgrade kernel: [  231.469211] init: php5-fpm main process (2831) terminated with status 78
Dec  7 14:08:54 testupgrade kernel: [  231.469225] init: php5-fpm main process ended, respawning
Dec  7 14:08:54 testupgrade kernel: [  231.548950] init: php5-fpm main process (2839) terminated with status 78
Dec  7 14:08:54 testupgrade kernel: [  231.548964] init: php5-fpm main process ended, respawning
Dec  7 14:08:54 testupgrade kernel: [  231.628781] init: php5-fpm main process (2847) terminated with status 78
Dec  7 14:08:54 testupgrade kernel: [  231.628795] init: php5-fpm main process ended, respawning
Dec  7 14:08:54 testupgrade kernel: [  231.711933] init: php5-fpm main process (2855) terminated with status 78
Dec  7 14:08:54 testupgrade kernel: [  231.711947] init: php5-fpm respawning too fast, stopped

What I tried then is to check if my php5-fpm configuration for this virtual host pool is actually working. It was configured to listed on a TCP port with the following configuration in /etc/php5/fpm/pool.d/www.conf I have correctly instructed the pool to listed as follows:

listen = 127.0.0.1:9000

I tried restarting few more times with the service command and since it did not work I decided checking the startup scripts. I edited the /etc/init/php5-fpm.conf and I noticed that I already have the latest bug-fixed version of the line "reload signal USR2". Then I noticed the following line:

pre-start exec /usr/lib/php5/php5-fpm-checkconf

I checked the /usr/lib/php5/php5-fpm-checkconf script and noticed the syntax check that is appended to the $errors variable:

/usr/sbin/php5-fpm --fpm-config /etc/php5/fpm/php-fpm.conf

I executed it in the shell and noticed the following:

root@testupgrade:~# /usr/sbin/php5-fpm --fpm-config /etc/php5/fpm/php-fpm.conf
[07-Dec-2014 13:46:14] ERROR: [pool www] 'slowlog' must be specified for use with 'request_slowlog_timeout'
[07-Dec-2014 13:46:14] ERROR: failed to post process the configuration
[07-Dec-2014 13:46:14] ERROR: FPM initialization failed

This means that I have touched my php-fpm.conf and messed it up however the error was nowhere to be found and I had no indication that this is the reason for the php5-fpm service to fail starting. I fixed the syntax in the /etc/php5/fpm/pool.d/www.conf file and then tried restarting again with the service command. The service started and opened a tcp listener on the required port 9000. The vhost also started working. So always check the php-fpm syntax and configuration with the above command to avoid issues with the service not starting.

like image 30
st0ma Avatar answered Sep 20 '22 13:09

st0ma


Typically an init script will not always spit out the problem causing the situation to happen. Your best option is to cat /etc/init.d/php5-fpm and find the command it is trying to run and then use that command to start the process manually.

Speaking from experience with FPM start-up scripts, FPM will normally spit out the error you cannot see or are missing from random log files and then you'll be able to find and fix that error. Once resolved, your init script should be good to go afterwards.

like image 1
Diemuzi Avatar answered Sep 21 '22 13:09

Diemuzi