To set up a virtual host on MAMP you would need to edit the apache configuration files which are located on the /Applications/MAMP/conf/apache folder.
But before that, let’s create a folder on our apache root folder, that will be used for our virtual host.
The root folder is /Applications/MAMP/htdocs so go there and create a new folder.
Open a terminal window and type the following commands:
cd /Applications/MAMP/htdocs mkdir mysite
Also, on that new folder, create an index.html file (with the editor of you preference) and type the following content:
<html> <head> <title>My Site</title> </head> <body> <h1>Hello World!</h1> </body> </html>
Now, we can proceed to edit the /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf file.After the line:
Add the line:
And, at the end of the file, add the following text:
<VirtualHost *:8888> DocumentRoot "/Applications/MAMP/htdocs" ServerName localhost </VirtualHost> <VirtualHost *:8888> DocumentRoot "/Applications/MAMP/htdocs/mysite" ServerName mysite.localhost <Directory "/Applications/MAMP/htdocs/mysite"> Options FollowSymLinks AllowOverride All </Directory> </VirtualHost>
Then, proceed to edit the /Applications/MAMP/conf/apache/httpd.conf file.
Locate the following line:
And remove the pound/hash symbol (#) at the beginning of the line, so that it will look like this:
As a final step we need to update the system’s hosts file in order to be able to use our virtual host domain.
Open a terminal window, and edit the /etc/hosts file. (You need admin privileges to edit this file so you will have either to sign in as root user or use the sudo command)
At the end of the file type the following:
Now restart your MAMP server, and open the http://mysite.localhost:8888 url on your browser.
You should be seeing this:
If the url does not work correctly make sure to check the apache logs file for any syntax or typo errors, at /Applications/MAMP/logs/apache_error.log