lets-encrypt-logo

Secure AWS Lightsail blueprint with SSL

Securing the traffic to and from your site is essential in any modern website or web application. An SSL certificate adds this security and Let's Encrypt can issue a certificate for your site.

Install The Lego Client

We’re going to use the Lego Client to help us with the generation of the certificate.

Download the Lego Client

If you do not have the Lego Client installed on your instance, grab this first.

Check if you have it:

$~ lego -v

Install Lego:

$~ cd /tmp

$~ curl -Ls https://api.github.com/repos/xenolf/lego/releases/latest | grep browser_download_url | grep linux_amd64 | cut -d ‘”‘ -f 4 | wget -i –

$~ tar xf lego_vX.Y.Z_linux_amd64.tar.gz  (Replace the “X.Y.Z” placeholder with the version that was downloaded)

$~ sudo mkdir -p /etc/letsencrypt

$~ sudo mv lego /etc/letsencrypt/lego

Turn off Apache Services

$~ sudo service apache2 stop

Generate the Certificate

Request a New Certificate:

$~ sudo /etc/letsencrypt/lego run --tls --email="EMAIL-ADDRESS" --domains="DOMAIN" --domains="www.DOMAIN" --domains="ANOTHER_DOMAIN" --path="/etc/letsencrypt"

Relocate the Certificates

Remove old certs (if present):

$~ sudo rm /etc/ssl/certs/NAME_OF_CERT.crt 

$~ sudo rm /etc/ssl/private/NAME_OF_CERT.key

Move new certs:

$~ sudo mv /etc/letsencrypt/certificates/DOMAIN.crt /etc/ssl/certs/NAME_OF_CERT.crt

(repeat for other domain names)

$~ sudo mv /etc/letsencrypt/certificates/DOMAIN.key /etc/ssl/private/NAME_OF_CERT.key

(repeat for other domain names)

Configure the Web Server to use the Let's Encrypt Certificate

Access the configuration file:

$~ sudo vim /etc/apache2/sites-available/default-ssl.conf

Update (or add) the SLL Certificate file configuration:

SSLCertificateFile /etc/ssl/certs/NAME_OF_CERT.crt

SSLCertificateKeyFile /etc/ssl/private/NAME_OF_CERT.key

SSLCertificateChainFile /etc/ssl/certs/NAME_OF_CERT.crt

Save the configuration file:

$~ esc (button)

$~ :wq

Confirm SSL is active

$~ sudo a2enmod ssl

$~ sudo a2ensite default-ssl

Re-Start Apache Services

$~ sudo service apache2 start