How to Restart Apache using Cron Job
Have you notice your server ram usage is sometime very close to your max ram installed on your server? It’s possible because of memory leak and resource hogging web applications. One way is to add more ram. Another way is automatically restart apache regularly using crontab. Below is how to setup a cron job to restart apache every 24 hours:
1) login as root using SSH Client such as PuTTY
2) Type “crontab -l” to display list of cron jobs.
crontab -e Edit your crontab file, or create one if it doesn’t already exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.
3) Type “crontab -e” to edit the crontab.
4) Go to the last line and add
0 12 * * * /etc/init.d/httpd restart >/dell/null 2>&1
5) Control O to save the crontab. Control X to quit.
6) Type “top” to observe the memory used.
7) Type “/etc/init.d/httpd restart” to restart apache.
Type “top” again and check the memory used.
You will notice that the memory used in step 8 is much lesser than the one used in step 6.

