How to Enable SSL in Apache2 on Ubuntu

In this tutorial, I’ll explain you that how to enable the SSL for your website under Apache2 on Ubuntu Server. For this, I’m assuming:

1. That you have a working apache2 setup on your Ubuntu Server.

2. You have correctly configured the dns records for your domain.

3. You already got a certificate from a trusted certificate authority (CA) such as Godaddy,Verisign, Comodo, etc.

Let’s verify our web server that it is up and running, before beginning this tutorial:


Create a directory inside the /etc/apache2/ directory,where we’ll save the private key, public key certificate and bundle certificate:

cd /etc/apache2/ 
sudo mkdir ssl


Transfer the private key, public key certificate and bundle certificate inside the /etc/apache2/ssl/ directory and verify it:

cd ssl


We want to configure the apache in such a way that it’ll run on HTTPs and for this we need to enable ssl Apache2 module with a2enmod:

sudo a2enmod ssl


It will suggest you to restart apache,ignore that message for now.

Edit the ports.conf file:

sudo nano /etc/apache2/ports.conf


Ensure that port 443 is defined as follows and add the NameVirtualHost for port 443,comment other lines:

NameVirtualHost *:443
Listen 443


Open up the SSL config file:

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


Fill in the correct ServerAdmin email address,add the ServerName line and adjust the path in the DocumentRoot line. Also make sure that we have a valid path for the SSL:


Now we need to configure the SSL site:

sudo a2ensite default-ssl


Restart the Apache service:

sudo /etc/init.d/apache2 restart


Now we should be able to connect to the server through SSL using Chrome or any other browser:


Verify the Certificate, that it’s the same that we got from a trusted certificate authority (CA) and configured:


Our Web Server is also working with http (port 80).But, we don’t want that users access it through http, we only want to access it through https. To fix this, we need to edit the /etc/apache2/sites-available/default file:

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


Delete everything and add a redirection:

RedirectPermanent /


Note: Also execute this command:

sudo a2enmod rewrite

Restart the apache2 service:

sudo /etc/init.d/apache2 restart


Now if we go to, it will redirect us to

Enjoy :-)

Hope this will help you!

Please Remember me in your prayers!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: