If you are at all serious about PHP development on OSX, then you are probably familiar with the usefulness of having MAMP installed. In under 20 minutes, you can set up multiple local development environments all managed by git and accessible through virtual hosts with little to no configuration. Add another 10 minutes, and you can easily enable SSL in MAMP 2.0.5
I am working with several sites that utilize HTTPS, and I wanted to make the development process reflect the live environment as much as possible. MAMP Pro makes this process a snap; all you have to do is click the ‘Enable SSL’ checkbox in the most recent versions and you are set. For those of us without $59.95 to spend at the moment, it is possible to enable SSL in MAMP 2.0.5 – it just requires a little manual editing.
Most articles on enabling SSL in MAMP are pretty outdated and are no longer accurate due to files moving and/or being removed. Luckily, MAMP has actually made things easier for us to set up SSL by using includes and allowing us to put the proper configuration code in relevant files. We will be following a lot of the same steps from this older article, but here I’ll show you how to do it with the newest version.
Step 1: Back that MAMP up!
Before you do anything, go ahead and back up your MAMP configuration folder /Applications/MAMP/conf/
by either turning it into a local GIT repository or making some kind of backup/duplicate of this folder. If you have GIT installed, enter the following commands in terminal.
1234; html-script: false ] cd /Applications/MAMP/conf/ git init git add . git commit -m "initial backup of my MAMP config files"
Step 2: Generate an SSL Certificate
Now, 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. In terminal, enter the following commands.
123456789101112131415161718192021222324252627282930; html-script: false ] 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 apache configuration folder cp server.crt /Applications/MAMP/conf/apache cp server.key /Applications/MAMP/conf/apache
Step 3: Uncomment the Includes
There are a few files we need to include in apache in order to get everything up and running. In my case, I am creating virtual hosts for each of my sites so I can access them with a simpler URL than the default htdocs/mysite.com
, so I’ll be including the virtual hosts configuration file as well as the ssl configuration file.
Open /Applications/MAMP/conf/apache/httpd.conf
in your preferred code editor and go to line 525
:
12; html-script: false ] # Virtual hosts # Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Uncomment it (remove the ‘#’) so it looks the same as below:
12; html-script: false ] # Virtual hosts Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Then, find line 537
:
12; html-script: false ] # Secure (SSL/TLS) connections # Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf
Uncomment it as shown below:
12; html-script: false ] # Secure (SSL/TLS) connections Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf
Step 4: Add your Virtual Host
If you haven’t yet set up a virtual host servername in your local hosts file, you may want to do that next.
In finder, select ‘Go to Folder’ from the ‘Go’ dropdown menu.In the dialog box, enter /private/etc/
and click ok.Open the hosts file in your text editor and add the following code on a new line under 127.0.0.1 localhost
, where ‘blog’ is the name of your desired servername:
1; html-script: false ]127.0.0.1 blog
Now we just need to pay a visit to each of the files that we just included and add a few settings.
In /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
, add the following code to the bottom of the file (somewhere near line 44
). Of course, you’ll need to change the ServerName
and DocumentRoot
directives to the virtual host name and path that works with your environment:
1234; html-script: false ]<VirtualHost *:80> ServerName blog DocumentRoot /Users/davekiss/Sites/soundsplausible.com</VirtualHost>
Step 5: Edit the SSL Configuration
Last step! In /Applications/MAMP/conf/apache/extra/httpd-ssl.conf
, find this code block around line 76:
123456; html-script: false ] # General setup for the virtual host DocumentRoot "/Applications/MAMP/Library/htdocs" ServerName www.example.com:443 ServerAdmin you@example.com ErrorLog "/Applications/MAMP/Library/logs/error_log" TransferLog "/Applications/MAMP/Library/logs/access_log"
and edit in your DocumentRoot
and ServerName
settings:
123456; html-script: false ] # General setup for the virtual host DocumentRoot "/Users/davekiss/Sites/soundsplausible.com" ServerName blog:443 ServerAdmin you@example.com ErrorLog "/Applications/MAMP/Library/logs/error_log" TransferLog "/Applications/MAMP/Library/logs/access_log"
And there you have it! Since the certificate we generated isn’t actually a valid certificate, you’ll need t add it as a security exception in your browser for https to work. And of course, when using SSL online, be sure to purchase your certificate from a reliable vendor.
Happy secure MAMPing!