Today we will learn how to install ssl on ubuntu 18.04 & 16.04 Apache or Nginx web server. Let’s Encrypt is a certificate authority (CA) providing free SSL/TLS certificates. Let’s Encrypt provide free SSL certificate for your domain. The certificates can only be requested from there server where the domain is pointed. Let’s Encrypt do a DNS check for the domain, that domain is pointed to the current server. After that it issue certificate for you. This tutorial will help you to install Let’s encrypt client on your Ubuntu system and issue SSL certificate for the domain.
Step 1 – Prerequisites
Before starting work on this task, I assume you already have:
- Running Ubuntu system with sudo privileges shell access.
- A domain name registered and pointed to your server’s public IP address. For this tutorial, we use example.com and www.example.com, which is pointed to our server. If you don’t know how to point domain click here to know.
- Runningweb server with VirtualHost configured for example.com and www.example.com on Port 80.
Step 2 – Install Let’s Encrypt Client
certbot-auto Let’s Encrypt client and save under
/usr/sbin directory. Use the following command to do this.
sudo wget https://dl.eff.org/certbot-auto -O /usr/sbin/certbot-auto sudo chmod a+x /usr/sbin/certbot-auto
Step 3 – Get a SSL Certificate
You need to stop your Apache or Nginx web server if it already running
sudo service nginx stop
sudo service apache2 stop
Step 4 – Get a SSL Certificate
Let’s Encrypt do a strong Domain Validation automatically with multiple challenges to verify the ownership of the domain. Once the Certificate Authority (CA) verified the authenticity of your domain, SSL certificate will be issued.
sudo certbot-auto certonly --standalone -d example.com -d www.example.com
Above command will prompt for an email address, which is used for sending email alerts related to SSL renewal and expiration. Also, asks a few more questions. After completion, it will issue an SSL certificate and will also create a new VirtualHost configuration file on your system.
Step 5 – Check SSL Certificate
If everything goes fine. A new ssl will be issued at below location. Navigate to below directory and view files.
cd /etc/letsencrypt/live/example.com ls
cert.pem chain.pem fullchain.pem privkey.pem
Setp 6 – Configure SSL VirtualHost
Use the following configurations for Apache and Nginx web server. Edit virtual host configuration file and add below entries for the certificate.
ssl on; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
SSLEngine on SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
Step 6 – Start your web server
sudo service nginx start
sudo service apache2 start
Step 7 – Configure SSL Auto Renew
In the end, configure the following job on your server crontab to auto-renew SSL certificate if required.
0 2 * * * sudo /usr/sbin/certbot-auto -q renew
If you have any questions or thoughts to share, use the comment form below to reach us.