Get an SSL certificate from Let’s Encrypt and connect it to Apache for Centos 7

Initial data:

  • Apache is already installed on the server
  • Opened ssl port (443)

Add EPEL repository and install mod-ssl

[[email protected]]# yum install epel-release mod_ssl

Install certbot (Let’s Encrypt client)

[[email protected]]# yum install python-certbot-apache

We get an ssl certificate

[[email protected]]# certbot --apache -d itdraft.ru -d www.itdraft.ru

During the installation process, an e-mail will be requested, and then the script will ask whether to redirect from http to https

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A
-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: Y
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

After the installation is complete, the following message will appear:

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/itdraft.ru/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/itdraft.ru/privkey.pem
   Your cert will expire on 2018-09-17. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:
   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Auto renewal of ssl certificate

Editing crontab:

[[email protected]]# crontab -e

Add a line:

0 0 * * 1 /usr/bin/certbot renew >> /var/log/sslrenew.log

Or run manually:

[[email protected]]# certbot renew
Saving debug log to /var/log/letsencrypt/letsencrypt.log
-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/itdraft.ru.conf
-------------------------------------------------------------------------------
Cert not yet due for renewal
-------------------------------------------------------------------------------
The following certs are not due for renewal yet:
  /etc/letsencrypt/live/itdraft.ru/fullchain.pem expires on 2018-09-17 (skipped)
No renewals were attempted.
-------------------------------------------------------------------------------
Sidebar