Lets suppose we want to have 2 virtual hosts in our server wich will be accesible via http://web1.com and http://web2.com and their content will be stored respectively in:
/Users/user/Documents/Webs/web1.com
and
/Users/user/Documents/Webs/web2.com
Firts we have to configure web1.com y web2.com to be resolved to our computer. We could configure a DNS server for that task but it’s much simpler to edit the /etc/hosts
file and add:
127.0.0.1 web1.com
127.0.0.1 web2.com
Check in a terminal that doing ping to those names they are resolved as 127.0.0.1:
$ ping web1.com
PING web1.com (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.044 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.068 ms
Download XAMPP and install it.
Edit /Applications/XAMPP/etc/httpd.conf
and change User and Group parameters to your user name and staff
group.
User user
Group staff
Uncomment the line that includes the virtual hosts configuration file:
# Virtual hosts
Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf
Edit Applications/XAMPP/etc/extra/httpd-vhosts.conf
and delete 2 example VirtualHost that come by default and add the following:
ServerAdmin webmaster
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
ServerName localhost
ServerAlias localhost
ErrorLog "logs/localhost-error_log"
CustomLog "logs/localhost-access_log" common
ServerAdmin webmaster
DocumentRoot "/Users/user/Documents/Webs/web1.com"
ServerName web1.com
ServerAlias web1.com
ErrorLog "logs/web1.com-error_log"
CustomLog "logs/web1.com-access_log" common
DirectoryIndex index.html
#IndexOptions +FancyIndexing NameWidth=*
#Options Includes FollowSymLinks Indexes
#AllowOverride All
Order allow,deny
Allow from all
ServerAdmin webmaster
DocumentRoot "/Users/user/Documents/Webs/web2.com"
ServerName web2.com
ServerAlias web2.com
ErrorLog "logs/web2.com-error_log"
CustomLog "logs/web2.com-access_log" common
DirectoryIndex index.html
#IndexOptions +FancyIndexing NameWidth=*
#Options Includes FollowSymLinks Indexes
#AllowOverride All
Order allow,deny
Allow from all
As you can see there is also a VirtualHost for the root of XAMPP thus we can access status info of the server and phpMyAdmin console opening http://localhost.
Put inside our 2 web folders a index.html
file with some content, start XAMPP and check you can access both virtual hosts URLs and that you see index.html
content. You can change DirectoryIndex
value to a list of files and XAMPP will load the first one it finds. For example to try loading first index.php
and then index.html
:
DirectoryIndex index.php index.html
If you want to access the folder content of the directories just uncomment first 3 lines in ...
tag. Other way you would get a 403 error.