I do this thing around 10th time, how to create a Virtual Host for MAMP stack setup on my Mac. Seems I still need to Google after for some details, so let this article stand for this issue till the end of the times.
So I want to setup a domain alias – a so called Virtual Host – called sandbox.blog.eppz.eu that maps to my local folder ~/MAMP/blog.eppz.eu while all the existing localhost features still working.
Three simple steps: Change default MAMP port to :80, introduce host for OSX, then introduce host for Apache.
Change default MAMP port
Watch out for Skype, it usually sets itself to port :80, better to put it to another one.
Edit hosts file in Mac OSX
Almost every material around suggests to use that weird terminal text editor nano that really chills me out. I prefer use Sublime text for such alterations, “the text editor you’ll fall in love with” they say.
So in finder hit ⇧⌘+G (Go to Folder…), then type /private/etc/hosts.
Configure Virtual Host for MAMP (Apache actually)
First include the Virtual Hosts MAMP (Apache) configuration file into the main configuration file. Again, hit ⇧⌘+G then go to /Applications/MAMP/conf/apache/httpd.conf.
Once opened you’ll probably find these lines:
# Virtual hosts
So simply uncomment the Include. If you don’t find it, do not hesitate to paste it from here.
# Virtual hosts
Now you’re ready to edit the actual Virtual Host MAMP (Apache) configuration file. Go to /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf.
Being there for the first time you’ll find some examples, so you can simply edit them. Make sure that you create a Virtual Host for localhost itself, too. Also check port numbers to have them :80 as you configured in MAMP settings.
# Use name-based virtual hosting.
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost< block.
CustomLog ‘logs/localhost.access_log’ common
CustomLog ‘logs/sandbox.blog.eppz.eu.access_log’ common
There it goes. Once start you servers, you can see it working like a charm!
Hit like below, whether you’re logged in.