Set up SSL on a virtual host on MAMP

April 3, 2019

To set up SSL on a virtual host on MAMP you would need to edit the apache configuration files which are located on the /Applications/MAMP/conf folder, and to create a self-signed certificate.

Locate the file /Applications/MAMP/conf/apache/httpd.conf and open it with a text editor.

Then proceed to uncomment the following line:

#Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf

Generate Self-Signed Certificate

Now we generate the certificate files.

Open a Terminal window, and go the apache configuration folder.

cd /Applications/MAMP/conf/apache/

We start by generating the private key file "server.key"

openssl genrsa -des3 -out server.key 2048

The command will request us to enter a password.

Then, generate the certificate signing request

openssl req -new -key server.key -out server.csr

After that, we generate the certificate

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

And at last we remove its password

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

Update Virtual Host Configuration

Edit the file /Applications/MAMP/conf/apache/extra/http-ssl.conf.

Find the following line.

Listen 443

And replace it with these lines.

Listen 8890
NameVirtualHost *:8890
SSLStrictSNIVHostCheck off

Also find the following tag.

<VirtualHost _default_:443>

And replace it with this.

<VirtualHost _default_:8890>

Find the following lines.

DocumentRoot "/Applications/MAMP/Library/htdocs"
ErrorLog "/Applications/MAMP/Library/logs/error_log"
TransferLog "/Applications/MAMP/Library/logs/access_log"

And replace them with these lines.

DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost:8890
ErrorLog "/Applications/MAMP/logs/error_log"
TransferLog "/Applications/MAMP/logs/access_log"

Finally, at the bottom of the file, add the VirtualHost entries for the sites you want to use https://

<VirtualHost *:8890>
    DocumentRoot "/Applications/MAMP/htdocs/"

    <Directory "/Applications/MAMP/htdocs/">
        Options FollowSymLinks
        AllowOverride All

Now, restart your MAMP server, and you can open your local secure site, on the 8890 port.