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 my MAMP 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 let us 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 []:admin@localhost
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 admin@localhost
ErrorLog "/Applications/MAMP/Library/logs/error_log"
TransferLog "/Applications/MAMP/Library/logs/access_log"

Validate that your generated 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.


Posted

in

, , ,

by

Comments

10 responses to “How to get SSL working on MAMP for OS X”

  1. Angel Avatar
    Angel

    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?

    1. torbjornzetterlund Avatar

      I looks like doucmentroot is not pointing to a webpage – please check in httpd.conf file

      Check the changes you made, if there is any typo – misspelled words

      restart apache

      check the logs if you have any errors in the logs

    2. torbjornzetterlund Avatar

      Have you checked the php.ini what is the site root

  2. John Avatar

    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?)

  3. Moeen Avatar
    Moeen

    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… 🙁

  4. Sandeep Avatar
    Sandeep

    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

  5. sujan Avatar

    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.

    1. torbjornzetterlund Avatar

      What version of iOS are you using to run MAMP?

      Have you checked that you load the correct php.ini for your version of MAMP, and check the document root for that version points correctly. I had an issue that I switch the PHP version in MAMP and then my localhost did not work with SSL.

      You could also check this out – For more information: http://stackoverflow.com/questions/28252124/why-wont-apache-server-start-in-mamp

  6. Farghana Hussain Avatar
    Farghana Hussain

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

  7. MD Avatar
    MD

    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.

Leave a Reply to torbjornzetterlund Cancel reply

Your email address will not be published. Required fields are marked *