Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Virtual Hosts with MAMP on OS X

Virtual Hosts

Update the hosts file in /etc/hosts to maintain multiple domains/hostnames on a local machine for 127.0.0.1 and setup a VirtualHost container in /Applications/MAMP/conf/apache/extra/httpd-vhost.conf via /Applications/MAMP/conf/apache/httpd.conf for a name-based virtual host.

Only suitable for MAMP users under OS X Lion, OS X Mountain Lion, and OS X Mavericks on Apache-Port 80 and MySQL-Port 3306.

Locate httpd.conf : httpd -V

SSL

Generate the certificate

  • Generate a private key: openssl genrsa -des3 -out server.key 2048
  • Generate certificate signing request: openssl req -new -key server.key -out server.csr (use server.dev for your Common Name)
  • Generate the certificate from the CSR for 5 years: openssl x509 -req -days 1825 -in server.csr -signkey server.key -out server.crt
  • Remove the password requirement from the server key: cp server.key server.tmp
  • Then: openssl rsa -in server.tmp -out server.key
  • Move the certificate files to /Applications/MAMP/conf/apache/cert/
sudo nano /etc/hosts
127.0.0.1 localhost
127.0.0.1 local.dev
# Include virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
# Secure (SSL/TLS) connections
Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf
# Setup local.dev
<VirtualHost local.dev:443>
SSLEngine on
SSLCertificateFile /Applications/MAMP/conf/apache/cert/server.crt
SSLCertificateKeyFile /Applications/MAMP/conf/apache/cert/server.key
ServerAdmin info@website.com
DocumentRoot "/Applications/MAMP/htdocs/sites/website"
ServerName local.dev
DirectoryIndex index.php
<Directory "/Applications/MAMP/htdocs/sites/website">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
# Name-based virtual hosting
NameVirtualHost 127.0.0.1
# Setup local.dev
<VirtualHost 127.0.0.1>
ServerAdmin info@website.com
DocumentRoot "/Applications/MAMP/htdocs/sites/website"
ServerName local.dev
DirectoryIndex index.php
<Directory "/Applications/MAMP/htdocs/sites/website">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment