Skip to content

Instantly share code, notes, and snippets.

@lauhakari
Forked from jentanbernardus/vhost.md
Created December 6, 2021 14:48
Show Gist options
  • Save lauhakari/c527fd774875fe1df501442ef5486e25 to your computer and use it in GitHub Desktop.
Save lauhakari/c527fd774875fe1df501442ef5486e25 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.

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