How to set up Let’s Encrypt with Apache on Ubuntu

Updated: January 20, 2024 By: Guest Contributor Post a comment

Introduction

Securing web traffic is crucial to ensure data privacy and protection against middle-man attacks. Let’s Encrypt is a widely acclaimed, free, automated, and open Certificate Authority that enables website administrators to obtain SSL/TLS certificates. This tutorial will guide you through setting up Let’s Encrypt with Apache on an Ubuntu system, ensuring your website traffic is securely encrypted.

Prerequisites

  • A running Ubuntu server (18.04 or later)
  • A registered domain name pointed to your server’s IP address
  • Apache installed on your server
  • Sudo privileges for the user

Step-by-Step Guide

Step 1: Install Certbot

Certbot is the software that automates the process of obtaining and renewing Let’s Encrypt SSL certificates. Install the Certbot software and its Apache plugin by running the following commands:

sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot python-certbot-apache

This will set up Certbot with the Apache plugin on your Ubuntu server.

Step 2: Obtain a Let’s Encrypt SSL certificate

With Certbot installed, you can now request an SSL certificate for your domain using the Apache plugin:

sudo certbot --apache

This command runs Certbot with the Apache plugin, which automates the challenge process to verify domain ownership and configures Apache to use the obtained SSL certificate automatically. During the process, Certbot will ask for an email address for important account notifications, agree to the terms of service, and if you’d like to redirect HTTP traffic to HTTPS (recommended).

Upon successful completion, you should see a message stating that the SSL certificate has been installed and your site is now accessible via HTTPS.

Step 3: Verify Auto-Renewal

Let’s Encrypt certificates are valid for 90 days, but Certbot can automate the renewal process. Verify that automatic renewal is set up:

sudo certbot renew --dry-run

This command will simulate a renewal process, ensuring that Certbot is properly scheduled to renew the certificate before it expires. If the dry run succeeds, you can be confident that your certificates will renew automatically.

Step 4: Advanced Configuration

Advanced users may wish to implement further optimizations such as HSTS (HTTP Strict Transport Security), OCSP Stapling, or customize the cipher suite to enhance the security and performance of their SSL configuration.

Editing Apache’s SSL configuration can achieve this. Here are some example directives that you may consider adding to your Apache configuration for better security:

<IfModule mod_headers.c>
    Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"
</IfModule>

SSLUseStapling on
SSLStaplingCache "shmcb:logs/stapling-cache(150000)"

Explanation:

  • he <IfModule mod_headers.c> block checks if the mod_headers module is loaded, and if so, sets the HSTS policy. This policy tells browsers to only connect to your server using HTTPS for the specified max-age period, including all subdomains, and requests inclusion in browsers’ HSTS preload lists.
  • SSLUseStapling on enables OCSP stapling for SSL, which can improve the SSL handshake’s performance.
  • SSLStaplingCache directive configures the cache for OCSP responses to avoid querying the OCSP server for each handshake. The shmcb:logs/stapling-cache(150000) sets the type and size of the cache.

Always ensure that you understand and test any additional configurations to avoid potentially damaging your SSL setup and server availability.

Conclusion

In this tutorial, we have successfully set up a Let’s Encrypt SSL certificate with Apache on an Ubuntu server. By following these guides, not only have you enhanced your website’s security, but you have also taken an essential step towards building trust with your visitors through encrypted connections.