In this tutorial we will learn how to install free certificate for your website hosted on ubuntu. I assume you have access to your SSH with sudo privilege.

First we need to update our server packages by following command.

sudo apt-get update

 

Now we need to enable SSL mode by following command.

sudo a2enmod ssl

sudo service apache2 restart

Second command is for restarting apache server to take effect of enabled module. It is necessary to restart apache when we enable/disable any module.

Now we will create Free SSL Certificate from Zero SSL site (https://zerossl.com/ – It will give 3 months certificate, you need reissue at every 3 months*)  you can generate online certificate using “FREE SSL Certificate Wizard” either by verifying HTTP or DNS. Once you verify this it will give you certificates, download them and store on safe place.

We will now create a directory on server to store generated certificates. Use following command to create a directory.

sudo mkdir /etc/apache2/ssl

Upload your certificate files over there. We can now configure these files with virtual hosts files.

If you have already created Virtual host for you domain than you need to use that .conf file from sites-available folder e.g. example.com.conf or subdomain.example.com.conf (for subdomain). Now open that file with sudo privileges.

sudo nano /etc/apache2/sites-available/example.com.conf

It will look like something this, replace your domain with example.com

<VirtualHost example.com:443>

ServerAdmin admin@example.com

DocumentRoot /var/www/html/

ServerName example.com

ServerAlias www.example.com


SSLEngine on

SSLCertificateFile /etc/apache2/ssl/example.crt

SSLCertificateKeyFile /etc/apache2/ssl/example.key


ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined


</VirtualHost>

 

Save this file and enable virtual host by following command.

sudo a2ensite example.com.conf

Again we need to restart apache server.

sudo service apache2 restart

Now you can access your domain with SSL certificate which we have assigned to it.

If you see https with red mark then make sure you have updated all URLs with https in code or do not use any protocol to access URL in both protocol (http and https) e.g //path/style.css

Hope you have enjoyed this article and post your comment here if you find any difficulty or question. I will try to reply as soon as possible.

*We will see how to setup free SSL auto renewable with Certbot and let’s encrypt in next tutorial.

Want to work with us? We're hiring!