,

How to Install Let’s Encrypt SSL For FREE on an Apache Server (LAMP Stack)

How to Install Let’s Encrypt SSL For FREE on an Apache Server (LAMP Stack)

If you’re running a website on a LAMP stack, securing it with HTTPS is one of the most important steps you can take. HTTPS encrypts the connection between your website and its visitors, helps protect sensitive information, and prevents browsers from displaying security warnings about an unencrypted connection.

The good news is that you don’t need to purchase an SSL certificate to get started. Let’s Encrypt provides free SSL/TLS certificates, and Certbot makes installing and renewing them straightforward.

In this guide, we’ll walk through installing Let’s Encrypt on a Linux server running Apache, configuring your website to use HTTPS, and testing automatic certificate renewal.

What You’ll Need

Before getting started, make sure you have:

Your website should already be accessible using its domain name over HTTP. If you’re hosting a site at example.com, replace that domain with your actual domain throughout this guide.

Step 1: Update Your Server

Connect to your server over SSH and update the package lists and installed packages.

sudo apt update
sudo apt upgrade -y

This helps ensure your server has current security updates before you configure HTTPS.

Step 2: Install Snapd and Certbot

Certbot is the tool we’ll use to request and install the certificate. The Certbot project recommends its Snap distribution for many supported Linux systems because it provides a current release and includes automatic renewal scheduling.

First, install Snap if it isn’t already available:

sudo apt install snapd -y

On Debian, you may also need to install the Snap Store’s snapd snap and ensure the service is ready. Follow the instructions for your distribution if required.

Next, install Certbot:

sudo snap install certbot --classic

Make sure the command is accessible from your terminal:

sudo ln -s /snap/bin/certbot /usr/local/bin/certbot

If /usr/local/bin/certbot already exists, don’t overwrite it blindly. Check which Certbot installation your system is using first.

Verify the installation:

certbot --version

You should see the installed Certbot version.

Step 3: Verify Your Apache Website Configuration

Before requesting a certificate, make sure Apache is running and your domain resolves to the correct server.

Check Apache’s status:

sudo systemctl status apache2

If necessary, start Apache and enable it to start automatically at boot:

sudo systemctl enable --now apache2

Check the configuration for errors:

sudo apache2ctl configtest

A successful configuration test should return:

Syntax OK

Next, confirm that your Apache virtual host includes your domain name. On Ubuntu and Debian, site configurations are commonly stored in:

/etc/apache2/sites-available/

For example, your HTTP virtual host might contain:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/example-error.log
    CustomLog ${APACHE_LOG_DIR}/example-access.log combined
</VirtualHost>

Adjust the document root and domain names to match your website. If you use a separate virtual host file, make sure it is enabled.

sudo a2ensite example.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

Replace example.conf with your actual configuration filename.

Step 4: Configure Your Firewall

Let’s Encrypt needs to validate that you control the domain. With the standard HTTP validation method, your server must be reachable on port 80. Visitors also need access to port 443 to use HTTPS.

If you’re using UFW, check its current rules:

sudo ufw status

If UFW is enabled and the appropriate rules are missing, allow HTTP and HTTPS:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

If you’re using a cloud firewall, router, or hosting-provider security group, make sure those rules also allow the required traffic.

Do not enable UFW remotely without checking that your SSH connection will remain permitted.

Step 5: Request and Install Your Let’s Encrypt Certificate

Now you’re ready to request the certificate.

Run:

sudo certbot --apache -d example.com -d www.example.com

Replace example.com and www.example.com with the domain names you want covered.

Certbot will contact Let’s Encrypt, verify domain control, request the certificate, and configure Apache to use it. It may ask for an email address, agreement to the terms of service, and whether you want HTTP traffic redirected to HTTPS.

If you don’t use the www version of your domain, omit that domain from the command.

Once the process completes successfully, your website should be available at:

https://example.com

Step 6: Test Your HTTPS Configuration

Open your website in a browser using its HTTPS address.

Confirm that:

  • The browser reports a secure connection.
  • The certificate matches your domain name.
  • The page loads without certificate errors.
  • Any HTTP-to-HTTPS redirect you selected works correctly.

You can also inspect the certificate from the terminal:

sudo certbot certificates

This displays the certificates Certbot manages, including their domains and expiration dates.

To verify the HTTPS response from your server, run:

curl -I https://example.com

A successful response will generally include an HTTP status such as 200 OK or a redirect status, depending on your website configuration.

Step 7: Test Automatic Certificate Renewal

Let’s Encrypt certificates are short-lived, so automatic renewal is essential. Certbot’s Snap installation provides renewal scheduling, but you should still verify that renewal works.

Run:

sudo certbot renew --dry-run

This performs a renewal simulation rather than replacing your live certificate. If the test succeeds, Certbot can successfully complete a renewal using the current configuration.

You can inspect available systemd timers with:

systemctl list-timers --all

The exact renewal mechanism depends on how Certbot was installed. Avoid creating a second renewal cron job unless you’ve confirmed that an existing renewal mechanism is not working.

Step 8: Troubleshooting Common Problems

Domain validation fails

Double-check that your domain’s DNS records point to the correct public IP address. If you use both the root domain and www, verify that both resolve correctly.

Also check that port 80 is reachable from the public internet. If your server sits behind a router, ensure the required port forwarding is configured.

Apache fails to reload

Test the configuration:

sudo apache2ctl configtest

If the test reports an error, fix the relevant configuration file before reloading Apache.

The certificate installs, but the browser still shows warnings

Check that you’re visiting the correct domain over HTTPS. If the certificate is valid but the browser reports mixed content, your page may be loading images, scripts, stylesheets, or other resources over HTTP. Update those resource URLs to use HTTPS.

Renewal fails

Run a simulation to see the error:

sudo certbot renew --dry-run

Check DNS, firewall rules, web server configuration, and any changes made since the original certificate was issued.

Final Thoughts

Installing Let’s Encrypt on a LAMP server is a straightforward way to secure your website without paying for a commercial certificate. With Certbot configured correctly, Apache can serve your site over HTTPS while certificate renewal runs automatically.

Once HTTPS is working, consider reviewing your website’s security headers, keeping your server packages updated, and making sure your application uses secure cookies and HTTPS URLs.

For the latest installation instructions and supported configurations, visit the official Certbot instructions and Ubuntu Server TLS certificate documentation.

Remember: HTTPS encrypts traffic between your visitors and your server, but it does not replace regular updates, secure application code, strong passwords, or backups.