Install SSL Certificate In Ubuntu

Install SSL Certificate In Ubuntu 20.04 – AWS SSL Setup

Today I’ll walk you through the steps to Install an SSL certificate in our ubuntu server. By which we can use HTTPS connection in our server which is a secure connection.

The web server we are going to use in this tutorial is installed on Amazon EC2 and in this we have used Ubuntu 20.04.

Now let us see how we can install SSL in our Ubuntu web server step by step. For this, first we will create an instance in our Amazon AWS console in which we will install ubuntu 20.04 .

Create a New Ubuntu Server

installing ubuntu in a aws server

1. To create a new ubuntu server we will first go to EC2 Management Console of amazon aws and click on Launch Instance button there. After that, we have to select a Machine Image where we will select Ubuntu Server 20.04 LTS and click on Next.

2. Now we will select t2.micro for Instance Type because we are making this server in free tier of amazon aws. If you want to select any other then you can do that but keep in mind that you can Afford the one you want to select. After that we will click on Next – configure instance details.

3. In Configure instance details we will not change anything, just 2 things we have to change is iam role where we have to select a role. To create a new role, click on Create new role on the side. After that we have to select Enable termination protection after which we will click on Next – add storage.

4. We will allow the storage to remain 8GB, after which we will click on Next – Add Tags.

5. Here we will type “project” in key option and in value we will type “ssl-ubuntu” and then after that we will click on next – configure security group in it.

6. In the security group, we will give the security group name “web-server“. After that we will click on the Add rule button below and there we will select “HTTP” make Source Anywhere. We will add one more rule to it which will be HTTPS and it will be source anywhere, after that we will click on Review and launch.

7. Here we will select a keypair and then click on launch. In 1 minute your instance will be created in which ubuntu will be installed.

Add Elastic IP to the Server

Now we will assign an elastic IP address to our ec2 instance so that if ever we stop this instance then our IP will not change.

To make the IP address elastic, we will first go to Network and Security from the menu and from there we will click on Elastic IP.

Here we will click on Allocate Elastic IP address and then click on Allocate which will give us an Elastic IP address.  

Now we will click on that IP address and there will be the option of associate IP address, on which we will click and then select the instance we just created and then click on associate IP address. We have now assigned our instance an elastic IP address.

Point Webserver to Domain

To point the domain to the website, we first have to go to Instances where we will select our instance and then copy the public IP address of that instance.

Now we will go to the DNS settings of our domain provider and then in the DNS settings we will add an A record which will point above this IP address.

Connect to the instance

To connect to the instance, we will first go to the instances and then select the instance we have and here we will get the option of connect, on which we will click, after clicking on it, we will click on the session manager and then click on connect. This will allow us to open Cloudshell in our browser and run commands without having to use SSH or putty.

Install Apache2 and php8

1. After logging in to the Cloudshell we’ll have to first update our index packages.

sudo apt-get update

2. After this we will enter another command. With this command we will add an apt repository to the server.

sudo add-apt-repository ppa:ondrej/php

3. Now we will install PHP 8 in our server, for which we will type this command. Now apache and php8 are installed in our web server.

sudo apt-get install php8.0 -y

4. After this we have to restart our server, for which we will type this command. By typing this command, our apache server will restart.

sudo systemctl restart apache2

5. Now we have to enter a command to start apache automatically on rebooting our apache server. With the help of this command if we ever reboot our apache server, then with the help of this command our apache server will be enabled automatically.

sudo systemctl enable apache2

Create Virtual Host in the Webserver

Now we have to put some code in a configuration file which I have given below, you just have to enter your domain name instead of yourdomain.com.

<VirtualHost *:80>
  ServerName yourdomain.com
  ServerAlias www.yourdomain.com

    DocumentRoot /var/www/smm
    ServerAdmin [email protected]

    ErrorLog /var/www/vhosts/logs/error_log

  <Directory /var/www/>
  AllowOverride All
  </Directory>
</VirtualHost>

Copy the line of this code and then type the command given below.

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

And click Enter, after which the vim editor will open here, where we have to paste the above config file code we have copied here. Now save it and then restart the apache server.

Now we have to create a folder

sudo mkdir /var/www/smm
cd /var/www/smm
ls

Install Certbot and Install SSL

First of all, we have to install Core, for which you will type this command.

sudo snap install core; sudo snap refresh core

After which you will install Certbot. For this use this command.

sudo snap install --classic certbot

After Certbot is installed, we will run Certbot for which we will use this command.

sudo certbot --apache

Now certbot will ask us for an email which you can enter any of your email after which it will ask 2 questions which we have to click on Y. And then it will ask us the names of the domains on which we want to install SSL.

Select the domain and press enter after selecting it. Now it will generate and issue SSL certificate for that domain.

We have now installed SSL in our ubuntu server.

And finally we will create an index.php file for which we will type this command.

sudo vi index.php

After this, a php file will be created and saved in it. And this is how we can install SSL certificate in our ubuntu web server which is hosted on amazon aws, that too for absolutely free.

Leave a Comment

Your email address will not be published. Required fields are marked *