Setting up Virtual Host in MAMP
Posted on Feb 27, 2017, 12:12 PM
This tutorial will help you to set up a Virtual Host using MAMP without using console. Follow these steps:
Open the file
/etc/hosts. You will be prompted to enter your login password.Navigate to line line containing
127.0.0.1 localhostand enter the following in the next new line:127.0.0.1 example.devSave the file and exit. Now you will be redirected to
127.0.0.1when you enterexample.devin your browser. You can do this for any number of addresses.Now open the file
/Applications/MAMP/conf/apache/httpd.confand navigate to the lines containing:# Virtual hosts # Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.confRemove the hash(#) before the line that starts with
Includeso that it looks like:# Virtual hosts Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.confOpen the file at
/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf. You can see examples of how to define Virtual Hosts. You can either edit this or add one of your own. Add this configuration to define your virtual host:<VirtualHost *:80> DocumentRoot /Applications/MAMP/htdocs ServerName localhost </VirtualHost> <VirtualHost *:80> DocumentRoot "/path/to/site" ServerName example.dev </VirtualHost>Close the file and restart the servers to get into action.
Now if you enter the URL
http://example.devin your browser, you will be served the files at path/path/to/siteyou had entered in the configuration. You can add more Virtual Hosts as and when needed.
Virtual Hosts helps in making workflow easier.