I assume you have setup your apache2 server and websites is running on http protocol.
Now you want to install SSL and get your website run on https only.
For this, you will need to purchase SSL certificate from any SSL provider.
Now if you have purchased the SSL you will need to follow few steps to
complete installation on apache webserver.
1- You need to generate a CSR and Private Key from terminal of the server.
It is required during configuration of the SSL certificate and this
configuration requires multiple information and you have to go
through multiple steps to complete SSL configuration. It also requires
domain validation where you will get a pre populated drop down of
emails and you need to choose one of them so that you receive an
email to authenticate the domain.
Generate CSR and Private key:
$cd ~
$openssl req -newkey rsa:2048 -nodes -keyout youdomain.com.key -out youdomain.com.csr
Here you will be asked to enter multiple information but the "Common Name"
is very important, for this you need to enter "yourdomain.com" and this
same name will be putted in "ServerName" in your web server remember
carefully.
2- Assume you have purchased SSL. Now login to your SSL provider and go
through the steps which are required to complete SSL setup. After
completion of this step, you would have certificates file
"yourdomain.com.crt" and "intermediate.crt".
3- Now login into your server using terminal window and upload your
certificates file on your webserver in a particular folder and then
open the "default-ssl.conf" file and keep below line of code to
refer the certificate files.
SSLEngine on
SSLCertificateFile /home/yourdomain.com.crt
SSLCertificateKeyFile /home/yourdomain.com.key
SSLCACertificateFile /home/intermediate.crt
Save and close the file.
4- Run the commands to enable SSL and activate SSL configuration.
$sudo a2enmod ssl
$sudo a2ensite default-ssl.conf
5- To transfer all of your traffic from http to https you need to
change the "000-default.conf" and keep the below line
after "VirtualHost *:80
Redirect "/" "https://www.youdomain.com/"
and restart apache2
$sudo service apache2 restart
Now try to open your website with https as https://www.yourdomain.com
and http://www.yourdomain.com and check whether it works properly or not.