How to add a new vhost with mamp on mac osx

April 12, 2010    add a vhost on mac osx apache vhosts local website on a mac osx virtual host

Adding a new vhost is something I have to do on a regular basis when working on new projects locally.
Its a fairly straight forward task as well.

Download and install:- MAMP

Once you have done this navigate either with a finder window or via terminal to /Applications/MAMP/htdocs/

Once here create a folder again either with finder or terminal e.g mkdir myfirstsite

cd myfirstsite - to enter that folder and create another folder: mkdir http

Lets also add a test landing page so add a file called index.html into your http directory either in finder window or just by the following command in terminal.

Cd /Applications/MAMP/htdocs/myfirstsite/http/
vim index.html
hit 'i' to insert
type "Hello this is my first site"
hit escape-key + type ':wq'

Now we want to do 2 things, firstly add the virtual host to the httpd.conf file:

Navigate to: cd /Applications/MAMP/conf/apache/httpd.conf

Once here either open the text file in a text editor or simply enter it with: vim httpd.conf in terminal if your familiar with this method.

Scroll the very bottom and add the following:


DocumentRoot /Applications/MAMP/htdocs/myfirstsite/http
ServerName myfirstsite

Then secondly you need to add the site to the your local OS X machines host file with the following command via terminal window only.

printf "127.0.0.1tmyfirstsiten" | sudo tee -a /etc/hosts

After that restart MAMP by 'stop servers' and then start servers option.

Then open up your browser pop into the address bar:- http://myfirstsite:8888/ and with any luck you'll be on your way.


blog comments powered by Disqus