0

System: LEMP running on Ubuntu 14.04

I'm trying to configure the tool Monit to restart Nginx or PHP-FPM if ever there is a problem. It is correctly monitoring Nginx however under status for PHP-FPM it says "Not Monitoring". Apparently I'm having it check the wrong location.

Here is my Nginx configuration for PHP-FPM that is running on a socket:

location ~ \.php$ { ## Execute PHP scripts
    if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss

    expires off; ## Do not cache dynamic content
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params; ## See /etc/nginx/fastcgi_params

    fastcgi_keep_conn on; #hhvm param
}

Here is my Monit configuration for both Nginx and PHP-FPM:

## Check Nginx
check process nginx with pidfile /var/run/nginx.pid
    start program = "/etc/init.d/nginx start"
    stop program = "/etc/init.d/nginx stop"
## Check PHP-FPM
check process php-fpm with pidfile /var/run/php-fpm/php-fpm.pid
  group www-data #change accordingly
  start program = "/etc/init.d/php5-fpm start"
  stop program  = "/etc/init.d/php5-fpm stop"
  if failed unixsocket /var/run/php-fpm/php-fpm.sock then restart
  if 3 restarts within 5 cycles then timeout

I went with the suggested start and stop recommendations despite always restarting with "service php5-fpm restart".

My group - according to /etc/php5/fpm/pool.d/www.conf - is "group = www-data". I checked my php-fpm.conf and noticed that the PID file is being created at /var/run/php5-fpm.pid so I changed that. Then Monit said "Initializing" followed by "Connection failed". Any suggestions?

0

Ok, I was able to solve it myself. There were a number of problems. "php5" needed to replace almost every instance of "php". The bad connection I was receiving was referring to the unixsocket so I had to update that as well. Also the new PID location changed it looks like with PHP5-FPM. Here is the final configuration.

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

This is the configuration I've been using for a long time and works great

check process php5-fpm with pidfile /var/run/php5-fpm.pid
  group phpcgi
  if not exist for 2 cycles then restart
  start program = "/usr/sbin/service php5-fpm start"
  stop program  = "/usr/sbin/service php5-fpm stop"
  if not exist for 2 cycles then restart
  if failed unixsocket /var/run/php5-fpm.sock then restart
  if 5 restarts within 5 cycles then timeout

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.