How to Apply SSL Certificate (non-self) on EC2 with Linux/Ubuntu having Apache Server.

Assuming you are well aware of What is an SSL certificate? Why we need it? here I am going to guide you for How you can apply an SSL certificate for your website hosted on Linux or Ubuntu Server using Apache 2 server.
You can either purchase a new SSL certificate or can generate it for free on sslforfree.com which authorized by Letsencrypt the first non-profit CA.

After Purchasing or getting your SSL certificate you have actually 2 SSL files, Certificate and Private Key.
You can upload both SSL files (certificate.crt and private.key) on the server:
  • Create a new folder in Directory `/home/user-name/.ssh`.
  • Create or upload files certificate (.cert) file as certificate.crt and Private key (.key) as private.key in the folder created earlier.
Now edit Virtual Host configuration for the website for which you want to apply the SSL certificate.

sudo nano /etc/apache2/sites-enabled/{yourwebsitedomain.com}.conf

Add the following code to website vhost config file:

<VirtualHost *:443>
    ServerName yourwebsitedomain.com
    ServerAlias yourwebsitedomain.com
    ServerAdmin admin@yourwebsitedomain.com
    DocumentRoot /var/www/html/yourwebsite/public/
    SSLEngine on
    SSLCertificateFile "/home/user-name/.ssh/ssl/certificate.crt" //path of SSL certificate file
    SSLCertificateKeyFile "/home/user-name/.ssh/ssl/private.key" //path of SSL private key file
</VirtualHost>

Enable SSL module on apache server:

sudo a2enmod SSL
 
Now restart apache server

sudo service apache2 restart

All Done! Now browse your website over HTTPS. Feel free to comment below if you are facing any issue.

Comments

Popular posts from this blog

Using Virtual Columns in Laravel - Accessors and Appends

How to Show Cookie Policy Consent or GDPR Popup in Laravel using Cookie.

Postman Collection Run - How to Test File Uploading API on CircleCi or Jenkins