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.
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.
cd /Applications/MAMP/conf/ git init git add . git commit -m "initial backup of my MAMP config files"
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.
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 : firstname.lastname@example.org 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
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.
/Applications/MAMP/conf/apache/httpd.conf in your preferred code editor and go to
# Virtual hosts # Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Uncomment it (remove the ‘#’) so it looks the same as below:
# Virtual hosts Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
# Secure (SSL/TLS) connections # Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf
Uncomment it as shown below:
# Secure (SSL/TLS) connections Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf
If you haven’t yet set up a virtual host servername in your local hosts file, you may want to do that next.
/private/etc/and click ok.
127.0.0.1 localhost, where ‘blog’ is the name of your desired servername:
Now we just need to pay a visit to each of the files that we just included and add a few settings.
/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
DocumentRoot directives to the virtual host name and path that works with your environment:
<VirtualHost *:80> ServerName blog DocumentRoot /Users/davekiss/Sites/soundsplausible.com </VirtualHost>
Last step! In
/Applications/MAMP/conf/apache/extra/httpd-ssl.conf, find this code block around line 76:
# General setup for the virtual host DocumentRoot "/Applications/MAMP/Library/htdocs" ServerName www.example.com:443 ServerAdmin email@example.com ErrorLog "/Applications/MAMP/Library/logs/error_log" TransferLog "/Applications/MAMP/Library/logs/access_log"
and edit in your
# General setup for the virtual host DocumentRoot "/Users/davekiss/Sites/soundsplausible.com" ServerName blog:443 ServerAdmin firstname.lastname@example.org 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!