This guide is focused towards step by step instructions on setting up a cron job on server to restart Apache/Nginx/Bitnami monthly once so your latest SSL certificate is always loaded up automatically on frontend site without having to manually restart server.
First of all, You need to have root SSH access to your server. Otherwise, this method would not be possible as server restart requires sudo privileges and not something possible with your basic / jailed SSH access offered on shared hosting environments.
Further steps explained below:
1. Login to your SSH console as root user.
2. In case of Apache or Nginx server, please run the below command to identify your service path and make note of the path.
which service
It will be something like /usr/sbin/service
3. Run the below command to see which cron jobs you are already running.
crontab -l
4. Start editing the crontab with nano editor using below command
crontab -e
5. Using the service path you have noted, add a new monthly cron job line (runs on date 1 of each month) at the bottom of crontab editor in a new line as below
0 0 1 * * /usr/sbin/service apache2 restart > /monthlycron.log 2>&1
If you are using Nginx server, the above line should be,
0 0 1 * * /usr/sbin/service nginx restart > /monthlycron.log 2>&1
If you are using Bitnami server / Apache Lightsail, the above line should be,
0 0 1 * * /opt/bitnami/ctlscript.sh restart apache > /monthlycron.log 2>&1
Note: Both success & errors are logged in monthlycron.log file of root directory which will be helpful for debugging if server restart fails.
Press CTRL + O to save the crontab & you are all set!. You can run crontab -l command to see the saved cron job.
CAUTION:
In rare cases, If there is any error / typo in your server config file or if certificate.crt, private.pem, cabundle.crt files don’t exists in keys/ directory of your WordPress directory, your server restart could fail and your site may become inaccessible on day 1 of month. In such case, you need to correct any error logged in monthlycron.log file, fix missing cert files in keys/ directory and restart server once manually.