monit is an open source software that monitor services on your server. It can restart if any of the service go down.
Download latest version of file from
cd /usr/local/src wget http://mmonit.com/monit/dist/monit-5.0.3.tar.gz tar -zxvf monit-5.0.3.tar.gz cd monit-5.0.3 ./configure make make install
Copy control file to /etc
cp monitrc /etc/
At the end of the file add or uncomment
Now to monitor Apache, create a file /etc/monit.d/apache
Add following content
check process httpd with pidfile /var/run/httpd.pid group apache start program = "/etc/init.d/httpd start" stop program = "/etc/init.d/httpd stop" if failed host 127.0.0.1 port 80 protocol http and request "/phpinfo.php" then restart if 5 restarts within 5 cycles then timeout
You can change
and request "/phpinfo.php"
To any file on your web server. I do have a phpinfo file on my server, so i used it.
Some says phpinfo.php is a security risk, to me it is only a security risk if you run vlunerable application on your web server. If you use update software on your server, some one seeing your phpinfo is not a security issue.
To run monit, edit /etc/rc.local
/usr/local/bin/monit -d 60 -v -c /etc/monitrc -p /var/run/monit.pid -l /var/log/monit.log