How to automatically restart apache every day, week or month

Your server might be more stable if you restart the apache service once a day, once a week or once a month. You can do this by adding a single line of text in the «Cron» service on your apache server.




This command restarts the Apache service every morning 04:00 AM. That’s properly when there are few visitors. Takes a few seconds and properly is the users not noticing the downtime.


Start Cron. First time you run this command you will probably be asked which text editor you want to use. I recommend that you choose Nano.

sudo crontab -e

In the text editor Nano, just add the following line. Then save and close the text editor Nano. That’s all

0 4 * * 4 root service apache2 restart > /dev/null 2>&1

This command will restart apache at 4 in the morning every Thursday.

To check if this work use the command:

sudo service apache2 status