For this lab, you need to have apache already installed and running on your virtual server.

1. If this is not the case, you can download it with this command:

sudo apt-get install apache2

2. Activate the SSL Module
sudo a2enmod ssl

3. Restart Apache
sudo service apache2 restart

4. We need to create a new directory where we will store the server key and certificate 
sudo mkdir /etc/apache2/ssl 

5. Create a Self Signed SSL Certificate

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

With this command, we will be both creating the self-signed SSL certificate and the server key that protects it, and placing both of them into the new directory.

This command will prompt terminal to display a lists of fields that need to be filled in.

The most important line is "Common Name". Enter your official domain name here or, if you don't have one yet, your site's IP address. 

6. Set Up the Certificate
Now we have all of the required components of the finished certificate.The next thing to do is to set up the virtual hosts to display the new certificate.

Open up the SSL config file:

 nano /etc/apache2/sites-available/default-ssl


Within the section that begins with <VirtualHost _default_:443>, quickly make the following changes.

Add a line with your server name right below the Server Admin email:

 ServerName example.com:443

Replace example.com with your DNS approved domain name or server IP address (it should be the same as the common name on the certificate).

Find the following three lines, and make sure that they match the extensions below:

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key

7. Activate the New Virtual Host

Before the website that will come on the 443 port can be activated, we need to enable that Virtual Host:

sudo a2ensite default-ssl


Restarting your Apache server will reload it with all of your changes in place.

sudo service apache2 reload


In your browser, type https://youraddress, and you will be able to see the new certificate.