Install free SSL by using certbot for ubuntu apache

Karan Goyal
2 min readNov 27, 2020

--

With this method, you can make your domain HTTPS for free on any ubuntu server like digital ocean, AWS, Linode, etc

You can get a $100 bonus for 2 months using my referral on digital ocean droplet, it’s worth trying cloud hosting for 2 months
Click here for bonus

  1. SSH into the server, using the command
ssh root@ip_address

2. Type these commands

sudo snap install core; sudo snap refresh core

3. Remove any Certbot OS packages( if present)

sudo apt-get remove certbot

4. Install Certbot

sudo snap install --classic certbotsudo ln -s /snap/bin/certbot /usr/bin/certbotsudo a2enmod sslsystemctl restart apache2

5. You need to add a domain to the droplet or instance. Make sure you changed nameservers of the domain pointing to the digital ocean or aws

After this, you need to modify apache settings

Previous settings look like this

You need to change it to:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
Alias /static /myproject/code_folder/static
<Directory /myproject/code_folder/static>
Require all granted
</Directory>
<Directory /myproject/code_folder/wsgi_folder>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
WSGIDaemonProcess myproject python-home=/myproject/venv python-path=/myproject/code_folderWSGIProcessGroup myprojectWSGIScriptAlias / /myproject/code_folder/wsgi_folder/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<VirtualHost *:443>
ServerAdmin webmaster@localhost
Alias /static /myproject/code_folder/static
<Directory /myproject/code_folder/static>
Require all granted
</Directory>
<Directory /myproject/code_folder/wsgi_folder>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>

6. Restart your server

systemctl restart apache2

7. Get and install your certificates.

sudo certbot --apache

Enter your email address and domain like

example.com www.example.com

You will see a success message like

8. Test automatic renewal

sudo certbot renew --dry-run

Your website should now work with HTTPS.

--

--

Karan Goyal
Karan Goyal

Written by Karan Goyal

Full Stack Developer, Top Rated on Upwork, Worked on 90+ jobs in past 9 months and all jobs are rated 5 stars, coding is fun, and always looking forward to code

No responses yet