Search code examples
apachesslmamp

How to include SSL certificate files in Apache Server running using MAMP


I have created SSL certificate in order to use https instead of http for localhost. The instructions I followed are here: https://medium.freecodecamp.org/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec

I still have the last step which is to include the certificate files (server.crt and server.key) in server.

I tried to rely on the following configuration to make it work which I got from: How to install SSL certificate in apache server in ubuntu

LoadModule ssl_module modules/mod_ssl.so
Listen 443
<VirtualHost *:443>
    # maybe additional config here

    ServerName www.example.com

    SSLEngine on
    SSLCertificateFile "/path/to/www.example.com.cert"
    SSLCertificateKeyFile "/path/to/www.example.com.key"

</VirtualHost>

I am currently using MAMP on a mac, and using Apache as server. I edited the file httpd.conf located in Applications/MAMP/conf/apache, and I added the following at the bottom of the file:

LoadModule ssl_module modules/mod_ssl.so
Listen 443
<VirtualHost *:443>

    ServerName localhost:443

    SSLEngine on
    SSLCertificateFile "~/server.crt"
    SSLCertificateKeyFile "~/server.key"

</VirtualHost>

Note my SSL files are located in ~ directory. I also updated the 8888 entries with 443 in this file, which are:

Listen 443
ServerName localhost:443

When I restarted the server, it fails to start again!


Solution

  • Here is a video providing the solution: https://www.youtube.com/watch?v=886Pea2ljm0&t=2s

    IMPORTANT: If you get the following error when restarting the server from MAMP:

    Apache couldn't be started. Please check your MAMP installation and configuration.

    Run the following command on terminal and it works:

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