Scotts Web Dev Banner
Did you notice... every article on this site has an associated video? Consider subscribing to Scotts Web Dev on YouTube! :)

How to Set up SSL on WSL on Localhost

You’re going to want to set up SSL on localhost so that you can properly mirror your production website environment. Everything on the internet is now SSL and you need to be able to have SSL locally as well.

In this video we set up SSL on localhost on WSL Ubuntu so that we can use https for our local domains.

Update your package list and upgrade your packages

sudo apt update
sudo apt upgrade

Install Open SSL

sudo apt install openssl

Enable ssl on apache

sudo a2enmod ssl

Restart apache

sudo systemctl restart apache2

Create an ssl folder in /etc/apache2

sudo mkdir /etc/apache2/ssl/

Generate your certificate and key files
(replace the .key and .crt files with your domain instead of mysite1.local.key or mysite1.local.crt)

sudo openssl req -x509 -nodes -days 9999 -newkey rsa:2048 -keyout /etc/apache2/ssl/mysite1.local.key -out /etc/apache2/ssl/mysite1.local.crt

Fill out the prompts.

Edit your apache configuration file for your site to include SSL certificate and keys.

cd /etc/apache2/sites-available

Edit your site file, here it’s mysite1.local.conf

Change the port from port 80 to port 443 for ssl. Turn SSLEngine On and add key file and certificate file. It should end up looking something like this:

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  ServerName mysite1.local
  DocumentRoot /var/www/html/mysite1

  SSLEngine On
  SSLCertificateFile /etc/apache2/ssl/mysite1.local.crt
  SSLCertificateKeyFile /etc/apache2/ssl/mysite1.local.key

  <Directory /var/www/html/mysite1>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

Enable the site in apache

sudo a2ensite mysite1.local

Restart apache

sudo systemctl reload apache2

View your local site in your browser using https

Related Content

We got here by setting up a wordpress site on localhost and then by adding an apache virtualhost to have a local domain. Check out those videos if you need help there.