Giter Club home page Giter Club logo

ssl's Introduction

SSL

Certbot auto certificate renewal using Php.

Upload the ssl_renewal_check.php file to your server in the /usr/share/tools folder or wherever you prefer, replacing https://google.com in the $url with the domain name that you want to check and set a cronjob to run it automatically at 1 minute past midnight every day.

Cron job: 1 0 * * * /usr/bin/php /usr/share/tools/ssl_renewal_check.php > /dev/null 2>&1

You can also run it directly from the command line with /usr/bin/php /usr/share/tools/ssl_renewal_check.php once it's uploaded but it is probably not going to be very useful to you to run it manually.

We read the SSL certificate that is installed on the server for the domain name listed in $url and from the result we get the valid from and valid to dates from the certificate. We then check if the date/time is less than the current date/time, a sure indicator that your certificate has expired when this becomes true.

If we are updating the certificate(s), remember that certbot renew will renew any certificates that are out of date, we end the current session, carry out the renewal and then restart sessions to prevent any session attacks or interference from outside sources as a security precaution.

One useful thing to note here is that we are not requesting new certificates from Letsencrypt (certbot) unless the current one is out of date, this means that we won't trigger any usage limitations because we don't actually check the certificate every day, only when the current one is obsolete.

I am using a Linux Ubuntu server, your requirements may vary slightly. Certbot is installed on the server. /usr/bin/php is the path to my Php binaries. It would be usual to use the -q switch with certbot renew but since we are sending any output to /dev/null in the cronjob we don't need the switch. You can upload the file to wherever you wish, just remember to correct the path to the file in your cronjob. Usr/share/tools seems like a reasonable place to store the file but it is up to you, if you move it elsewhere you may need to adjust the file/folder permissions in order for cron to be able to execute it on demand.

There is also a Shoutcast version. This was what originally caused us a problem. Certbot was renewing the certificates automatically but Shoutcast doesn't detect the new certificate(s) until it is restarted which meant rebooting the server just to get Shoutcast to read the new certificate. The Shoutcast version updates the certificate if required and then restarts sc_serv for you. In my case sc_serv is located in /etc/shoutcast, you may need to adjust the path to suit your servers file locations.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.