Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jentanbernardus
Last active January 19, 2024 08:40
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save jentanbernardus/7930e5b5968073d6f55080399fd03d54 to your computer and use it in GitHub Desktop.
Save jentanbernardus/7930e5b5968073d6f55080399fd03d54 to your computer and use it in GitHub Desktop.
Setting Up Virtual Hosts in MAMP on Windows

1. Edit MAMP Apache configuration to include Virtual Hosts configuration

In File Explorer, go to C:\MAMP\conf\apache and open httpd.conf with your text editor.

Find this line:

# Virtual hosts
# Include conf/extra/httpd-vhosts.conf

Uncomment this line:

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

2. Allow SymLink override

Find this line in that same httpd.conf file.

<Directory />
    Options FollowSymLinks ExecCGI
    AllowOverride none
    Order deny,allow
    Allow from all
</Directory>

Change AllowOverride from none to all

<Directory />
    Options FollowSymLinks ExecCGI
    AllowOverride all
    Order deny,allow
    Allow from all
</Directory>

3. Add the virtual host path

I have found that MAMP is a bit odd here. Your Virtual Hosts directive goes into C:\MAMP\conf\apache\httpd.conf. However, the actual httpd-vhosts.conf file is located at C:\MAMP\bin\apache\conf\extra\httpd-vhosts.conf, that is, in the bin directory. Not sure why.

In File Explorer, go to C:\MAMP\bin\apache\conf\extra and open httpd-vhosts.conf with your text editor.

All the way at the end of the httpd-vhosts.conf file, you're going to place a code that signifies a virtual host and specifies the path. Place this code at the end of the document.

<VirtualHost *:80>
  ServerName example.local
  DocumentRoot "C:/MAMP/htdocs/example"
</VirtualHost>

Change the DocumentRoot to wherever your project is located.

4. Edit host to allow your computer to recognize your local domain

In File Explorer, go to C:\WINDOWS\system32\drivers\etc and open hosts with your text editor. At the bottom of the file, type the name of your virtual host.

127.0.0.1 example.local

Make sure to restart the servers on MAMP after making any changes! If you don't reset the server to apply the changes, nothing will work even though you know you've done everything right.

@gl2007
Copy link

gl2007 commented Oct 23, 2022

Can't thank you you enough!! I was struggling with the vhosts not working through the vhosts file vas working directly from the httpd conf. Not sure why MAMP has this oddity or really frustrating issue of keeping the unused vhosts.conf or not pointing to the correct one in its httpd.conf file. Thanks a bunch!!

@jentanbernardus
Copy link
Author

Glad to hear this helped you get things sorted out, thanks! ✌️

@timoostrich
Copy link

Can't help you enough!! I was struggling with the vhosts not working through the vhosts file vas working directly from the httpd conf. Not sure why MAMP has this oddity or really frustrating issue of keeping the unused vhosts.conf or not pointing to the correct one in its httpd.conf file. Thanks a bunch!!

I had the same problem. Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment