How to setup websites(virtual hosts) on mac using MAMP

MAMP PRO allows you to setup website directly through provide GUI (Graphical User Interface) but in MAMP (free), you will have to setup it up manually. There following 3 steps are needed to setup a local site or Virtual Host in MAMP.

 

  1. Setup local host first, issue the following command in Terminal (command prompt)
    sudo pico/etc/hosts

    Add a new entry at the bottom in the following form

    127.0.0.1      mysitename
    

    mysitename can be any name that you want to choose. You will access you site by tying mysitename in URL.

  2. Edit httpd.conf. Select Finder->Go->”Go to folder”. Type /Applications/MAMP/conf/apache/httpd.conf. Open this file in your favorite text editor. I use textmate. Go to line #569 or search for Virtual hosts. Comment out the following line so that it looks like this
    # Virtual hosts
    Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
    
  3. Now go to https-vhosts.config, which is sitting inside the same folder in the ‘extra’ subfolder. Edit the file as the following


    <VirtualHost *:8888>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/Users/work/Sites/MySite"
    ServerName mysitename
    ServerAlias mysitename
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common
    </VirtualHost>

Notice that I used port 8888. The default port is 80. It is not required if you want to use default port, you can simply use * that would indicate any port.

Last thing, you should copy the following above the first virtual host that we entered above. This way you can access localhost:8888 correctly.


<VirtualHost *:8888>
DocumentRoot "/Applications/MAMP/htdocs" 
ServerName localhost 
</VirtualHost>

Do not forgot to restart the webserver (both apache and mysql). Also make sure you access the site by speccing the port 8888, like this

mysitename:8888

Issue connecting to MySQL DB

I had an issue connecting to mysql DB even though the supplied username and password were correct. I fixed that by simply creating a new user, giving it all privileges, by going to privilege tab in myphpadmin:8889.

MAMP PRO to MAMP

On thing I noticed when my MAMP PRO trial (15 days) expired, it deleted the database that I had created in mysql as well. Not sure if this is a bug in the MAMP PRO, but you may want to watch out for it.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*