Virtual host for MAMP on Mac OSX
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:
1
2
|
# Virtual hosts
#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
|
So simply uncomment the Include. If you don’t find it, do not hesitate to paste it from here.
1
2
|
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd–vhosts.conf
|
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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# 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.
#
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot ‘/Users/eppz/MAMP’
ServerName localhost
ErrorLog ‘logs/localhost.error_log’
CustomLog ‘logs/localhost.access_log’ common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@blog.eppz.eu
DocumentRoot ‘/Users/eppz/MAMP/blog.eppz.eu’
ServerName sandbox.blog.eppz.eu
ErrorLog ‘logs/sandbox.blog.eppz.eu.error_log’
CustomLog ‘logs/sandbox.blog.eppz.eu.access_log’ common
</VirtualHost>
|
There it goes. Once start you servers, you can see it working like a charm!
Hit like below, whether you’re logged in.