https://torbjornzetterlund.com/wp-content/uploads/2015/12/MAMPlogo-960x600_c.jpg

How to get SSL working on MAMP for OS X


I’m doing a fair deal of development in the area of RESTFul API  features, all of which use Secure Sockets Layer (SSL) to ensure the security of personal information being transmitted over the internet.

I have my development environment running locally within a Mac OS X based system running MAMP. When you install MAMP default configuration is applied and doesn’t have the configuration settings to allow Apache to run with SSL support so this guide is intended to show you how to change that and run as localhost with support for both http:// and https:// connections.

This guide will tell you how to configure MAMP to use ports 80 (http) and 443 (SSL). We will also be changing the configuration to allow you to stop and start both http and https services using the standard MAMP console rather than having to use the command line.

Before you start anything backup your apache conf/apache/httpd.conf and conf/apache/extra/httpd-ssl.conf files as we will be editing these, so you are aware I have myMAMP installed on my Mac OS X at /Applications/MAMP/, so all reference will be accordingly to that location, you may have installed i in a different location, so lets get started.

Step 1: Stop any other web server running on your machine
Because we are going to change the port that MAMP uses for https traffic, you need to make sure that no other process is currently using ports 80 and 443. You can check this by typing netstat at the terminal.

Step 2. Create a self signed SSL certificate
For development purposes, you need to create an SSL certificate. Of course for your production environment, you will need to purchase an authenticated certificate, for development purposes you can create your own free SSL certificate as follows:

Generate a private key

From the iTerm, type:

openssl genrsa -des3 -out server.key 1024
enter a password (twice)

Generate Certificate Signing Request (CSR)

openssl req -new -key server.key -out server.csr
enter the password you used above for the server key

You will need to answer the questions it asks you, an example is shown below. The MOST important field is the Common Name which must match the domain name you are using locally (e.g. localhost)

Country Name (2 letter code) [AU]:NL
State or Province Name (full name) [Some-State]:Noord Holland
Locality Name (eg, city) []:Amsterdam
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Thunderbear Design
Organizational Unit Name (eg, section) []:Development
Common Name (eg, YOUR name) []:localhost
Email Address []:[email protected]
A challenge password []:
An optional company name []:

(You can leave the challenge password blank)

Generate the Certificate

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
enter the password you used for the private key

Remove password from the server key

cp server.key server.tmp
openssl rsa -in server.tmp -out server.key

Move the Certificate and key into the MAMP configuration

cp server.crt /Applications/MAMP/conf/apache cp server.key /Applications/MAMP/conf/apache

Step 3. Edit MAMP Apache Configuration to support SSL
Tell MAMP to support SSL each time that it starts. Normally, you would tell Apache to do this from the command line by typing apachectl startssl but we need the convenience of starting MAMP from the standard MAMP dashboard or application window.

Edit the MAMP httpd.conf file (/Applications/MAMP/conf/apache/httpd.conf)

  • Comment out the line that looks for SSL secure connection
# Secure (SSL/TLS) connections
Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf

Edit the MAMP httpd-ssl.conf file (/Applications/MAMP/conf/apache/extra/httpd-ssl.conf)

Check the VirtualHost settings

#   General setup for the virtual host
DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost:443
ServerAdmin [email protected]
ErrorLog "/Applications/MAMP/Library/logs/error_log"
TransferLog "/Applications/MAMP/Library/logs/access_log"

Validate that your generate certificate files are correctly configured.

SSLCertificateFile /Applications/MAMP/conf/apache/server.crt
SSLCertificateKeyFile /Applications/MAMP/conf/apache/server.key

Step 4. Restart Apache
Finally, stop the existing MAMP Apache process and restart.

You should now be able to view http://localhost AND https://localhost.

10 Responses

  • Angel on April 19, 2016, 06:40:37

    Hi, first… thanks for the article, i’m writing because i had an error. I’m following all steps with no errors until i visit https://localhost and i get a 404 error:

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

    Can you help me with this?

    Reply to Angel
  • John on June 20, 2016, 09:53:22

    Torbjorn
    Thanks for this, my friend. Great instructions.

    Just for clarity, this line:

    Comment out the line that looks for SSL secure connection
    # Secure (SSL/TLS) connections
    Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf

    I think you should say ‘remove the #’ or ‘re-activate’ because I looked at the original code which had this line already commented out like this:
    #Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf

    Anyway, other than that slight misunderstanding on my part, it worked like a charm on Chrome.
    (I did get the ‘it’s not safe’) message, but I was kind of expecting this. (should I have got that message?)

    Reply to John
  • Moeen on July 26, 2016, 23:38:56

    thread is old, but it helped me.
    I am on mac, whenever i used to uncomment the httpd-ssl.conf, the mamp server was not starting. there was no log which i can find, so did nt know what was happening. To check the ERRORS, you can go to the MAMP bin directory, and find startappache , run ./startAppache , it will through error with line number.

    I hope that is helpful to anyone.

    My issue was, the default document root was not existing, make sure error logs path also exits, put _default as well, While server key is being generated, use 4 letter password… i missed a lot of things… spent 3 days to figure out whats missing… :(

    Reply to Moeen
  • Sandeep on September 19, 2016, 03:29:07

    Thank you for this tutorial. It really helped me.

    The only hiccup I had was in the last step restarting Apache from MAMP console on OSX El Capitan.

    I got an error saying Apache cannot be started and you need to check the configuration files.

    I tried to restart Apache from Terminal using below command worked.
    sudo /Applications/MAMP/Library/bin/apachectl start

    For more information: http://stackoverflow.com/questions/28252124/why-wont-apache-server-start-in-mamp

    Reply to Sandeep
  • sujan on October 26, 2016, 07:07:33

    Thank you for the article.
    Followed all steps and went without any problem but while visiting https://localhost i get the error

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

    I checked Document Root and its pointing correctly. But still the same.

    Reply to sujan
  • Farghana Hussain on April 18, 2017, 15:43:36

    This was amazing! Worked like a charm. Thanks a lot for making it so simple! :)

    Reply to Farghana
  • MD on November 9, 2017, 18:44:43

    I’d like to clarify for others, that the line:
    “Validate that your generate certificate files are correctly configured” refers to the the httpd-ssl.conf file. These two lines should already be in the file:
    SSLCertificateFile /Applications/MAMP/conf/apache/server.crt
    SSLCertificateKeyFile /Applications/MAMP/conf/apache/server.key
    You just have to validate that the paths are correct.

    Reply to MD

Menu