Enable HTTPS: A comprehensive guide to installing Certbot and setting up free SSL certificates for Apache on Ubuntu.
Estimated Time: Approximately 30 - 45 minutes
In today's digital landscape, securing your website with HTTPS (Hypertext Transfer Protocol Secure) is no longer optional—it's essential. HTTPS encrypts communication between your server and users' browsers, protecting sensitive data, improving user trust, and boosting your search engine rankings.
Let's Encrypt is a free, automated, and open Certificate Authority (CA) that provides trusted SSL/TLS certificates. Certbot is a free software tool, maintained by the Electronic Frontier Foundation (EFF), that automates the process of obtaining and renewing these certificates.
This guide will walk you through installing Certbot and configuring Apache on your Ubuntu server to use Let's Encrypt SSL certificates, ensuring your website is secure and trustworthy.
30 - 45 minutes
Beginner to Intermediate
Assumes familiarity with terminal commands and a basic understanding of web servers and domain names.
sudo
privileges.Before installing new software, always ensure your system's package list is up-to-date.
sudo apt update && sudo apt upgrade -y
Certbot needs to communicate with Let's Encrypt servers over HTTP/HTTPS to verify your domain. Ensure your firewall (UFW) is correctly configured to allow this traffic.
sudo ufw status
For Certbot's Apache plugin to work effectively and cleanly, you should have an Apache Virtual Host file configured for your domain, including the `ServerName` and `ServerAlias` directives.
Create a new virtual host file: (If you were previously using `/var/www/html` with the default `000-default.conf`, this is a good time to create a dedicated file.)
sudo nano /etc/apache2/sites-available/yourdomain.com.conf
Paste the following basic HTTP virtual host configuration. This tells Apache how to serve your site on port 80. You can point `DocumentRoot` to `/var/www/html` or a new directory like `/var/www/yourdomain.com`.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/html # Or /var/www/yourdomain.com if you created it
ErrorLog ${APACHE_LOG_DIR}/yourdomain.com-error.log
CustomLog ${APACHE_LOG_DIR}/yourdomain.com-access.log combined
<Directory /var/www/html> # Or /var/www/yourdomain.com
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Save and exit (`Ctrl+O`, `Enter`, `Ctrl+X`).
Enable the new virtual host and disable the default one (if applicable):
sudo a2ensite yourdomain.com.conf
sudo a2dissite 000-default.conf
# Only if you're replacing the default site
Test Apache configuration and reload:
sudo apache2ctl configtest
sudo systemctl reload apache2
The recommended way to install Certbot on modern Ubuntu versions is via `snap`, which provides a self-contained and up-to-date version.
Ensure snapd is up to date:
sudo snap install core
sudo snap refresh core
Install Certbot:
sudo snap install --classic certbot
Create a symbolic link for easy access:
sudo ln -s /snap/bin/certbot /usr/bin/certbot
Certbot will configure Apache's `mod_ssl` to handle HTTPS traffic. Ensure this module is enabled.
sudo a2enmod ssl
Restart Apache for the module to take effect:
sudo systemctl restart apache2
Now, run Certbot with the Apache plugin. It will automatically detect your configured virtual hosts, obtain certificates, and modify your Apache configuration.
sudo certbot --apache
You will be prompted to provide some information:
After Certbot completes, it's time to verify that your site is now serving over HTTPS.
1. Browser Check: Open your web browser and navigate to `https://yourdomain.com` (and `https://www.yourdomain.com`).
2. Online SSL Checker: Use an online tool like SSL Labs SSL Server Test. Enter your domain name to get a detailed report on your SSL configuration and grade (aim for A or A+).
3. Command Line Check: For a quick check from your server:
sudo curl -vI https://yourdomain.com
Let's Encrypt certificates are valid for 90 days. Certbot automatically sets up a systemd timer or cron job to renew them well before expiration, so you typically don't need to do anything manually.
Check the renewal timer status:
sudo systemctl status snap.certbot.renew.service
Test the renewal process (dry run): This command simulates a renewal without actually changing your certificates.
sudo certbot renew --dry-run
Ensure all aspects of your HTTPS setup are functional:
Congratulations! Your website is now secured with free SSL/TLS certificates from Let's Encrypt, automatically managed by Certbot. This is a significant step forward in securing your web presence.
Here are some advanced steps and considerations for further security and optimization: