How to Setup SSL in Ubuntu 20

You are currently viewing How to Setup SSL in Ubuntu 20

This article is for people who are looking to set up SSL in ubuntu 20. The SSL protocol encrypts the traffic between a browser and server, preventing third parties from eavesdropping on sensitive information. This guide will show you how to set up SSL in ubuntu 20 without any hassle.

First set up an EC2 instance using the following article of mine. While choosing the AMI type, select Ubuntu 20.04 LTS.

Then we need to install Apache 2 and PHP 8

Install Apache 2 and PHP 8

Update the apt using the following command.

sudo apt-get update

When your APT is updated then add this apt repository which holds PHP installing .deb packages.

sudo add-apt-repository ppa:ondrej/php

So now as we set the repository for the php8, please run the below command to install PHP8

sudo apt-get install php8.0 -y

Next, reboot the apache server.

sudo systemctl restart apache2

Set apache to restart automatically when the system reboots.

sudo systemctl enable apache2

Create a VirtualHost

After setting up the Apache 2 server, then you need to create a virtual host to map your domain with the server. An example of a virtual host configuration is given below.

<VirtualHost *:80>

  # REQUIRED. Set this to the host/domain/subdomain that
  # you want this VirtualHost record to handle.

  ServerName watchanalyzer.com

  # Optional. You can specify additional host names that
  # serve up the same site. This can be top-level, domains,
  # sub-domains, and can even use wildcard subdomains such
  # as *.yourdomain.com - just separate each host name
  # with a single space.

  ServerAlias www.watchanalyzer.com

  # REQUIRED. Set this to the directory you want to use for
  # this vhost site's files.

  DocumentRoot /var/www/smm

  # Optional. Uncomment this and set it to your admin email
  # address, if you have one. If there is a server error,
  # this is the address that Apache will show to users.

  ServerAdmin [email protected]

  # Optional. Uncomment this if you want to specify
  # a different error log file than the default. You will
  # need to create the error file first.

  #ErrorLog /var/www/vhosts/logs/error_log

  # REQUIRED. Let's make sure that .htaccess files work on 
  # this site. Don't forget to change the file path to
  # match your DocumentRoot setting above.
  
  <Directory /var/www/>
    AllowOverride All
  </Directory>

</VirtualHost>

Copy the example configuration and change the domain name to yours.

Then run the following command to create the configuration file.

sudo vi /etc/apache2/sites-available/000-default.conf

Add the confirmation text for your domain name over there.

Now copy the IP address of your server and set the A record. Wait 5-10 mins for DNS propagation.

Then browse the domain name and then you should see a default apache page, which means the installation process went well.

Add a PHP file “index.php” with the following code which will show the details of PHP and apache version and default values.

<?php 
phpinfo();

Install Certbot

Once you have completed the setup of Apache 2, then you need to install Certbot.

In Ubuntu, Snapd is already installed. So you don’t need to do anything here. But for other OS, you need to first install SNAPD.

Then run the following command to install “core”

sudo snap install core; sudo snap refresh core

Next, install the certbot using the following command.

sudo snap install --classic certbot

Once you have installed the certbot then it’s time to issue the SSL certificate by running the following command.

sudo certbot --apache

This will issue an SSL certificate for you using Letsencrypt and will make the necessary changes in the “.conf” file.

Conclusion

Setting up SSL encryption on a website is important to protect the users who visit your site. There are many ways you can encrypt your data, and we’ve covered some of them in this post.

One way that seems popular among developers is to use Let’s Encrypt with Ubuntu 20. The process for installing it varies depending on which server software they’re using, but if you need help getting set up or have any questions about these instructions please leave a comment below!

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

This Post Has 3 Comments

  1. Mozammel

    Hi! I read your post. I hope it will help me ton increase my knowledge?
    I have one question. Can YOU kindly tell me how way (basically SSL certificate) to secure a website?

    Thanks in advance

Leave a Reply