1. Allow virtual hosts
Mac
Open the Apache configuration file with your text editor:
Applications > MAMP > conf > apache > httpd.conf
Find this line:
# Virtual hosts
#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Uncomment the code by removing the hash symbol.
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Windows
The location of the file is: C:/ > MAMP > conf > apache > httpd.conf
Find this line:
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
Uncomment the code.
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
2. Allow SymLink Override
Find this line in that same httpd.conf
file.
<Directory />
Options Indexes FollowSymLinks
AllowOverride None
</Directory>
Change None to All.
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
3. Add the virtual host path
Now we will modify the file:
/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
To add a virtual host for your site, the edited definitions should look like this:
<VirtualHost *:80>
ServerName example.test
DocumentRoot /path/to/directory
</VirtualHost>
Mac
DocumentRoot /path/to/directory
Windows
DocumentRoot C:/path/to/directory
4. Allow your computer to recognize your local domain
Mac
Type this in Terminal.
sudo nano /etc/hosts
You will be prompted for your password. After inserting your pasword you will see the content of the file.
Then type 127.0.0.1 example.test
in this file like in the example below. Then save (Ctrl+O) and exit (Ctrl+X)
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 example.test
Windows
Right click on Notepad and select “Open as Administrator”. Open this file in Notepad:
C:\WINDOWS\system32\drivers\etc\hosts
At the bottom of the file, type the name of your virtual host.
127.0.0.1 example.test
After restarting your MAMP server, you can go to http://example.test:8888
and you will reach your site.
5. Remove :8888 from custom server URL
If you want to remove the :8888 from the end of the URL.
Back in the httpd.conf file, find these two lines (they won’t be next to each other):
Listen 8888
ServerName localhost:8888
And change them:
Listen 80
ServerName localhost:80
Save the file.
Restart your servers and done!
Try http://example.test
in your browser.
If the above example doesn’t work, try removing :80
from the VirtualHosts tag, as this seemed to fix the problem for anyone having an issue.
You can repeat the code as many times as you want, for as many virtual hosts.
<VirtualHost *:80>
ServerName website1.dev
DocumentRoot "path/to/website1"
</VirtualHost>
<VirtualHost *:80>
ServerName website2.dev
DocumentRoot "path/to/website2"
</VirtualHost>