PHP Script to monitor Apache/php-fpm

I moved a web site to new dedicated server. But for some reason, php-fpm crashed. I increased the max_children settings, but it happend again. I do not want down time while i am investigating the problem. So i created a PHP script, that will check if site is working or not.

Script have 2 part.


It is simple PHP script, that get a param and print it.

This file is placed on root of your web site, so it can be accessed using URL http://yoursite/health-check.php



Add following content

On the script, replace YOUR_DOMAIN_HERE with your actual domain name.

systemctl restart apache2 is for restart apache web server. If you use nginx, replace it. systemctl restart php7.2-fpm restart php-fpm, if you have differnt version of php, you need to change it.

The script is generate a random number, pass it to health-check.php script. Compared the value returned with generated random number to make sure the value is correct. If web server or php-fpm fail, this check will fail.

Now set a cronjob


Related Posts

Server Monitoring

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *