Sounds Plausible.

Enable SSL in MAMP 2.0.5


Enable SSL in MAMP 2.0.5

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.

    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.

    
    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:

    # 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

Then, find line 537:

    # 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

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:
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:

<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:

    #   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:

    #   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!

  • Pingback: Configuring SSL for Apache on OS X Lion using MAMP « Frankie Inguanez

  • Pingback: Virtual Hosts on Apache « Frankie Inguanez

  • http://www.olij.co.uk Oliver

    Great guide, thank you. However I have one issue – apache now only responds to requests via https. No pages will load over http. I’ve followed the instructions to the letter, but still get this issue.

    Any ideas?
    Thanks.

  • Pingback: Configuring MAMP v2+ for SSL (the free version) | OliJ

  • http://URL Ludo

    Hey
    Thanks for the tutorial, it helped me have both http://blog and https://blog work fine

    Yet, now I no longer have access to the MAMP welcome page, so

    I’ve tried to change the apache port from 8888 to 80 in the preferences, but it did not change a thing …

    I keep having the error 404 when I click on the “Show welcome page ” button (sorry for the translation, I’m not using the English version, but the button should display something similar )

    Can you help me solve this issue ?
    Thx.

    • http://find.brentshepherd.com Brent Shepherd

      If Apache won’t start, you can try to start it from terminal using this command:

      sudo /Applications/MAMP/Library/bin/apachectl start

      The advantage of doing it that way is that it will print out the error stopping it from starting (and you can fix accordingly).

  • http://brittneykernan.com Brittney

    @Oliver – I had the same issue. When my http was not working with SSL enabled, it was because my virtual hosts were not specifying ports. NameVirtualHost *

    Once I changed to
    NameVirtualHost *:80
    and

    https and http could be accessed at the same time

  • http://ayme.ufolo.gy nunj

    @Ludo

    Hello ! I added this to my /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf :

    ServerName mamp
    DocumentRoot /Applications/MAMP/bin/mamp

    update your hosts files with:

    127.0.0.1 mamp

    you should be able to access the MAMP pages on http://mamp

  • Pingback: Enable SSL in MAMP | My Coding Journal

  • http://URL Name*Nikhilesh

    I followed the steps exactly, but i am still getting this error

    “Not Found
    The requested URL / was not found on this server.”

  • Rachel

    In “httpd-ssl.conf,” the document root is listed as so:

    “/Applications/MAMP/Library/htdocs”

    But I’m running MAMP 2.2 and htdocs is directly in the MAMP folder. Do I need to edit this line to read:

    “/Applications/MAMP/htdocs”

    for ssl to work?

  • http://rdlnk.co/MOV19 gf sprague

    Hmm it seems like your blog ate my first comment (it was super long) so I
    guess I’ll just sum it up what I wrote and say, I’m thoroughly enjoying
    your blog. I as well am an aspiring blog writer but I’m still new to everything.

    Do you have any helpful hints for beginner blog writers?
    I’d definitely appreciate it.

  • http://URL Youngkyu

    Thanks a lot!!
    I succeed at the first time as following your instructions.
    really appreciate it!