How to Automatically Renew LetsEncrypt Certificates and Restart Your Web Server

Edit your crontab by typing crontab -e and then add the following line.

0 6 * * * certbot renew --post-hook "systemctl restart lsws"

In my example, I am restarting Litespeed, but you could restart Nginx or Apache by changing it like this:

0 6 * * * certbot renew --post-hook "systemctl restart nginx"
0 6 * * * certbot renew --post-hook "systemctl restart apache2"

This will check your certificates every day at 06:00 and renew it if necessary. Once it’s renewed, it will restart your web server so that the new certificate takes effect.

This entry was posted in Linux. Bookmark the permalink.

Leave a Reply

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