Skip to content
Field note

How to Test with HTTPS (SSL) Enabled On A Local Machine For Multiple Sites

Introduction

June 15, 2017·1 min read·Abhai Sasidharan, Axelerant Alumni/ Field correspondent
How to Test with HTTPS (SSL) Enabled On A Local Machine For Multiple Sites

Introduction

Some issues can be fixed only by replicating your live site exactly as it is on your local machine, especially if your site is using HTTPS. (An example that comes to mind was when the addthis js file was being blocked by the browser because it was an HTTP script that was loading over an HTTPS website.)

This means having to enable SSL on your local server for testing website servers over SSL or HTTPS. This is actually quite simple.

First, enable the SSL module:

sudo a2enmod ssl

sudo service apache2 restart

Then create the directory:

sudo mkdir /etc/apache2/ssl

You probably have more than one local setup on your machine. In that case, it is best if you put each certificate in a separate folder.

sudo mkdir /etc/apache2/ssl/drupal7

Now that you have your folders, you can run the following to create self signed SSL certificates in the folders.

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/drupal7/apache.key -out /etc/apache2/ssl/drupal7/apache.crt

After you have successfully created the certificate, you need to add it to your VirtualHost configuration file, which looks like this:

<VirtualHost *:80>

ServerName drupal7.local

ServerAlias www.drupal7.local

ServerAdmin yoda@drupal7.local

DocumentRoot /home/vader/public_html/drupal-7

<Directory /home/vader/public_html/drupal-7>

AllowOverride All

Require all granted

</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

To enable SSL, your VirtualHost config file should look like this:

<VirtualHost *:80>

ServerName drupal7.local

ServerAlias www.drupal7.local

ServerAdmin yoda@drupal7.local

DocumentRoot /home/vader/public_html/drupal-7

<Directory /home/vader/public_html/drupal-7>

AllowOverride All

Require all granted

</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

<IfModule mod_ssl.c>

<VirtualHost _default_:443>

ServerAdmin yoda@drupal7.local

ServerName drupal7.local

ServerAlias www.drupal7.local

DocumentRoot /home/vader/public_html/drupal-7

<Directory /home/vader/public_html/drupal-7>

AllowOverride All

Require all granted

</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLEngine on

SSLCertificateFile /etc/apache2/ssl/drupal7/apache.crt

SSLCertificateKeyFile /etc/apache2/ssl/drupal7/apache.key

<FilesMatch "\.(cgi|shtml|phtml|php)$">

SSLOptions +StdEnvVars

</FilesMatch>

<Directory /usr/lib/cgi-bin>

SSLOptions +StdEnvVars

</Directory>

BrowserMatch "MSIE [2-6]" \

nokeepalive ssl-unclean-shutdown \

downgrade-1.0 force-response-1.0

BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

</VirtualHost>

</IfModule>

Run ‘sudo service apache2 restart’, and now you can access your local site on https://.

Did you find this post helpful? Let us know in the comments below.

Companion brief

Bring this dispatch into a working session - one page in, scoping memo out.

Brief Foyer
Pressure-test "Field note" with a partner

If this dispatch landed, bring it into a room with us.

The argument in "How to Test with HTTPS (SSL) Enabled On A Local Machine For Multiple Sites" is ours - but every situation breaks the argument differently. Send the situation in one page and a named partner will reply inside one business day with a scoping memo: where the argument holds for you, where it bends, and what we'd actually do in the first two weeks.

One-pager · Field note

By submitting this form you acknowledge that you have read Axelerant's Privacy Policy and agree to its terms.

Replied to by a named partner within one business day.