MAMP with SSL (https)

Well I cannot guarantee the accuracy of this article, I can confirm that my local MAMP installation is now serving both http and https. This is really important if you're doing any work on sites that require SSL certificates, and is a nice 'hidden' feature of MAMP. To get things working properly, I followed this webopius article (my article mirrors much of their content), but had to make some final tweaks before my sites started loading.

Step 1 – Gitify Your MAMP Config Files

Before you do anything, go ahead and turn your MAMP configuration folder into a local GIT repository. If you're not into using GIT, then at least make some kind of backup of this folder.

cd /Applications/MAMP/conf/
git init
git add .
git commit -m "initial backup of my MAMP config files"

Step 2 – Generate a Self Signed SSL Certificate

We need to create a self signed SSL certificate that we can use with MAMP. This process is a little cryptic if you've never done it before, but if you follow the steps below everything should be fine.

cd ~

# generate a private key (will request a password twice)
openssl genrsa -des3 -out server.key 1024

# generate certificate signing request (same password as above)
openssl req -new -key server.key -out server.csr

# Answer the questions
Country Name (2 letter code) [AU]: CA
State or Province Name (full name) [Some-State]: Quebec
Locality Name (eg, city) []: Montreal
Organization Name (eg, company) [Internet Widgits Pty Ltd]: Your Company
Organizational Unit Name (eg, section) []: Development
Common Name (eg, YOUR name) []: localhost
Email Address []: your_email@domain.com
A challenge password []: # leave this empty
An optional company name []: # leave this empty

# generate the certificate
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

# remove the password from the server key
cp server.key server.tmp
openssl rsa -in server.tmp -out server.key

# Move the certificate into your MAMP configuration folder
mkdir /Applications/MAMP/conf/ssl
cp server.crt /Applications/MAMP/conf/ssl
cp server.key /Applications/MAMP/conf/ssl

Step 3 – Edit the MAMP Apache SSL Configuration

Now we need to open up the MAMP configuration files and enable SSL.

# I'm using Textmate, but use whatever editor you prefer
mate /Applications/MAMP/conf/apache/ssl.conf

# Near the top of the file, we need to comment out <IfDefine SSL>
# <IfDefine SSL>

# Near the bottom of the file, we need to comment out the closing tag
# </IfDefine>

# Completely remove the existing VirtualHost entry (around 165 lines)
# and replace it with a more simple one. Notice we are now pointing
# MAMP to our self signed SSL keys
<VirtualHost *:443>
        SSLEngine on
        SSLCertificateFile /Applications/MAMP/conf/ssl/server.crt
        SSLCertificateKeyFile /Applications/MAMP/conf/ssl/server.key
</VirtualHost>

Step 4 – Edit the MAMP Apache Configuration

The last step! We need to make sure we are actually loading our SSL config file and that we have our NameVirtualHost entries setup properly.

# open the main configuration file in your favourite text editor
mate /Applications/MAMP/conf/apache/httpd.conf

# near the top of the file, set your Listen to port 80
Listen 80

# tell MAMP to load the ssl_module by commenting out <IfDefine SSL>
# <IfDefine SSL>
LoadModule ssl_module modules/mod_ssl.so
# </IfDefine>

# set your ServerName to localhost:80
ServerName localhost:80

# Replace your NameVirtualHost line with the following 2 lines
NameVirtualHost *:80
NameVirtualHost *:443

# Ensure your main virtual host entry looks similer to this. Notice that
# my document root is not the default. This is probably an optional change.
<VirtualHost *:80>
        ServerName localhost:80
                 ServerAlias emerson.local
        DocumentRoot "/Users/emerson/Sites/"
</VirtualHost>

Restart MAMP

You should now be able to restart MAMP (apache) and visit https and http. This is what worked for my local setup, but I cannot assure that it will work for you. Either way, good luck getting SSL up and running.

  1. 384313f278c2d51be44c0a47595ae720

    Walle

    12:39 PM on Thursday, August 4th, 2011

    Works great!

  2. 15481aae36a1e9deab03b95a97945c6f

    mike

    7:20 PM on Monday, November 21st, 2011

    Nice writeup, used it a few times - works.

  3. 293483efb70550905e798b74acc5af5c

    ElJefe

    10:23 PM on Saturday, December 10th, 2011

    I do not have an ssl.conf file within the apache directory. Do you know why this might be the case?