Monit configuration for php-fpm

I am trying to find a monit configuration for php-fpm that works.

Here is what I tried:

### Monitoring php-fpm: the parent process. check process php-fpm with pidfile /var/run/php-fpm/php-fpm.pid group phpcgi # phpcgi group start program = "/etc/init.d/php-fpm start" stop program = "/etc/init.d/php-fpm stop" ## Test the UNIX socket. Restart if down. if failed unixsocket /var/run/php-fpm.sock then restart ## If the restarts attempts fail then alert. if 3 restarts within 5 cycles then timeout 

But it fails because there is no php-fpm.sock (Centos 6)

+8
php monit
source share
5 answers

I am using the ping.path directive in php-fpm to check if it works ...

and configured it on nginx.conf (I don't know if this is your setting)

 location /ping { access_log off; allow 127.0.0.1; deny all; root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; include fastcgi_params; } 
+3
source share

For anyone else with this problem on Centos 6, the php-fpm socket is in /var/run/php-fpm/php-fpm.sock

Therefore, the final configuration will be as follows:

 check process php-fpm with pidfile /var/run/php-fpm/php-fpm.pid group phpcgi #change accordingly start program = "/etc/init.d/php-fpm start" stop program = "/etc/init.d/php-fpm stop" if failed unixsocket /var/run/php-fpm/php-fpm.sock then restart if 3 restarts within 5 cycles then timeout 
+14
source share

Instead:

 if failed unixsocket /var/run/php-fpm.sock then restart 

you can try:

 if failed port 9000 type TCP then restart 

It does not require editing the configuration of lighttpd / nginx, as in the case of location /ping .

My /etc/monit/conf.d/php-fpm.conf on Ubuntu looks like this:

 check process php-fpm with pidfile /var/run/php5-fpm.pid stop program = "/sbin/start-stop-daemon --stop --pidfile /var/run/php5-fpm.pid" start program = "/sbin/start-stop-daemon --start --pidfile /var/run/php5-fpm.pid --exec /usr/sbin/php5-fpm" if failed port 9000 type TCP then restart 
+4
source share

Here is a way to check php-fpm over a TCP connection (which is more reliable than a simple .pid):

 # Empty FastCGI request if failed port 8101 # Send FastCGI packet: version 1 (0x01), cmd FCGI_GET_VALUES (0x09) # padding 8 bytes (0x08), followed by 8xNULLs padding send "\0x01\0x09\0x00\0x00\0x00\0x00\0x08\0x00\0x00\0x00\0x00\0x00\0x00\0x00\0x00\0x00" # Expect FastCGI packet: version 1 (0x01), resp FCGI_GET_VALUES_RESULT (0x0A) expect "\0x01\0x0A" timeout 5 seconds then restart 

Source: http://richard.wallman.org.uk/2010/03/monitor-a-fastcgi-server-using-monit/

+1
source share

This on my debian 7 runs nginx and php5-fpm;

 check process php5-fpm with pidfile /var/run/php5-fpm.pid group php #change accordingly start program = "/etc/init.d/php5-fpm start" stop program = "/etc/init.d/php5-fpm stop" if failed unixsocket /tmp/php-fpm.sock then restart if 3 restarts within 5 cycles then timeout 
0
source share

All Articles