How To Setup Let’s Encrypt SSL Certificate with Apache on CentOS 8 / RHEL 8 & CentOS 7 / RHEL 7

Let’s Encrypt is a widely known certificate authority that provides free SSL certificates for websites, launched in April 2016.

With the help of Certbot client, certificate creation, validation, signing, implementation, and renewal of certificates are fully automated.

Prerequisites

Follow the links to have either LAMP stack or only Apache web server installed on your system.

READ: How To Install LAMP Stack on CentOS 8 / RHEL 8

READ: How To Install LAMP Stack on CentOS 7 / RHEL 7

Install Certbot Client

To generate and install a certificate for any domain, you should have terminal access, and Certbot ACME client installed on the system. Certbot client automates certificate issuance and installation with no downtime.

Certbot client is available on EPEL repository for CentOS 7 / RHEL 7. But, we need to download Certbot client manually for CentOS 8 / RHEL 8 from its official site.

### CentOS 8 / RHEL 8 ###

yum install -y httpd mod_ssl

curl -O https://dl.eff.org/certbot-auto

mv certbot-auto /usr/local/bin/certbot-auto

chmod 0755 /usr/local/bin/certbot-auto

### CentOS 7 ###

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

yum install -y certbot python2-certbot-apache

### RHEL 7 ###

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

subscription-manager repos --enable rhel-7-server-optional-rpms

yum install -y certbot python2-certbot-apache

Create Virtual Host

We will create a virtual host for the domain: www.itzgeek.net.

This virtual host handles the HTTP version of your domain.
vi /etc/httpd/conf.d/www.itzgeek.net.conf

Use the below information.

<VirtualHost *:80>
  ServerName itzgeek.net
  ServerAlias www.itzgeek.net
  DocumentRoot /var/www/www.itzgeek.net
  
  <Directory /var/www/www.itzgeek.net>
      Options -Indexes +FollowSymLinks
      AllowOverride All
  </Directory>

  ErrorLog /var/log/httpd/www.itzgeek.net-error.log
  CustomLog /var/log/httpd/www.itzgeek.net-access.log combined
</VirtualHost>

Create a document root to place your HTML files.

mkdir -p /var/www/www.itzgeek.net

Place the HTML file inside the document root of your domain.

echo "This is a test site @ www.itzgeek.net" > /var/www/www.itzgeek.net/index.html

Change the permission of the directory.

chown -R apache:apache /var/www/www.itzgeek.net

Restart the Apache service.

systemctl restart httpd

Create / Update DNS Record

Go to your domain registrar and create an A/CNAME record for your domain. Ex: www.itzgeek.net.

Update DNS Record

Wait for some time to let the record propagate.

Check the DNS propagation using Nslookup yum install -y bind-utils utility.

Name Resolution

Install Let’s Encrypt SSL Certificate

Use the certbot command to generate and install Let’s Encrypt certificate.

### RHEL 8 ###

/usr/local/bin/certbot-auto --apache

### CentOS 7 / RHEL 7 ###

certbot --apache

Follow the interactive prompt and install the certificate.

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): itzgeek.web@gmail.com  << Enter Email address to receive notifications

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A  << Agree to Terms of Sevice

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y  << Subscribe to Newsletter

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: itzgeek.net
2: www.itzgeek.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 2  << Choose the domain to install Let's Encrypt SSL certificate
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for www.itzgeek.net
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/httpd/conf.d/www.itzgeek.net-le-ssl.conf
Deploying Certificate to VirtualHost /etc/httpd/conf.d/www.itzgeek.net-le-ssl.conf

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  << Redirect from HTTP to HTTPS
Redirecting vhost in /etc/httpd/conf.d/www.itzgeek.net.conf to ssl vhost in /etc/httpd/conf.d/www.itzgeek.net-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://www.itzgeek.net

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=www.itzgeek.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/www.itzgeek.net/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/www.itzgeek.net/privkey.pem
   Your cert will expire on 2019-11-10. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again with the "certonly" option. To non-interactively renew *all*
   of your certificates, run "certbot-auto renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - 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

Firewall

Configure the firewall to allow HTTPS requests.

firewall-cmd --permanent --add-port=443/tcp

firewall-cmd --reload

Verify Let’s Encrypt Certificate

Verify the Let’s Encrypt certificate by visiting the HTTPS version of your website.

http://your-http-web-site

OR

https://your-https-web-site

You should now get an HTTPS version of your site.

Let’s Encrypt SSL Certificate

Test Let’s Encrypt SSL Certificate

Test your SSL certificate for problems and its security ratings by going to the below URL.

https://www.ssllabs.com/ssltest/analyze.html?d=www.itzgeek.net
Test let’s Encrypt SSL Certificate

Renew Let’s Encrypt Certificate

Let’s Encrypt certificate is valid for 90 days from the date of issuance, and it needs to be renewed before it expires.

In CentOS 7 / RHEL 7, by default, the certbot client creates a cron scheduler entry to renew Let’s Encrypt certificates automatically.

Unfortunately, for CentOS 8 / RHEL 8, we need to configure the cron scheduler manually.

echo "0 0,12 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && /usr/local/bin/certbot-auto renew" | sudo tee -a /etc/crontab > /dev/null

You can also simulate the certificate renewal process with the below command to ensure the renewal goes smooth.

### CentOS 8 / RHEL 8 ###

/usr/local/bin/certbot-auto renew --dry-run

### CentOS 7 / RHEL 7 ###

certbot renew --dry-run
To renew the Let’s Encrypt certificate, execute the above command without --dry-run option.

Output:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/www.itzgeek.net.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator apache, Installer apache
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for www.itzgeek.net
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of apache server; fullchain is
/etc/letsencrypt/live/www.itzgeek.net/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates below have not been saved.)

Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/www.itzgeek.net/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.

If the output does not report any problem, then the certificate renewal will work as expected.

Conclusion

That’s All. I hope you learned how to setup Let’s Encrypt SSL Certificate with Apache on CentOS 8 / RHEL 8 & CentOS 7 / RHEL 7. Share your feedback in the comments section.

apachecentos 7centos 8letsencryptrhel 8web server
Comments (0)
Add Comment