symdesign
3/5/2015 - 7:24 PM

Virtual Hosts

Setting up a virtual hosts or subdomains for localhost

Virtual hosts on XAMPP / MAMP

#1 Hosts File

On Mac: Open Terminal and open + edit

$ sudo nano /etc/hosts

On Windows: Open Explorer and open + edit

C:\Windows\System32\drivers\etc\hosts
127.0.0.1   localhost
127.0.0.1   local

127.0.0.1   virtual-host
127.0.0.1   virtual.host
127.0.0.1   virtualhost.whatever

#2 httpd.conf

On Mac: Open Finder and open + edit

MAMP > conf > apache > httpd.conf

On Windows: Open Explorer and open + edit

xampp > apache > conf > httpd.conf
# Virtual Hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

#3 httpd-vhosts.conf

On Mac: Open Finder and open + edit

MAMP > conf > apache > extra > httpd-vhosts.conf

On Windows: Open Explorer and open + edit

xampp > apache > conf > extra > httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot "/root"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/root/friedrich-schultheiss.de"
    ServerName friedrich-schultheiss.local
    <Directory "/root/friedrich-schultheiss.de">
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
        AllowOverride all
    </Directory>
</VirtualHost>