I’ve seen many times where people (myself included) had trouble getting their Virtual Hosts configuration to work properly. There are several issues that can keep a Virtual Host from working, but many times the problem is directly related to the Virtual Hosts file itself.
Below is an example of a Virtual Hosts file that is working properly on one of my localhost testing servers via XAMPP on a Windows 7 Machine. This file will work the same directly in Apache from within Linux as well.
I’m not saying it’s the best configuration, I’m just saying it works. Anyway, I hope it helps someone.
All you have to do is change the paths, server names and whatever else is custom in your situation.
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/wordpress.local"
ServerName wordpress.local
ServerAlias www.wordpress.local
DirectoryIndex index.php
CustomLog "C:/xampp/htdocs/wordpress.local/logs/access.log" combined
ErrorLog "C:/xampp/htdocs/wordpress.local/logs/error.log"
<Directory "C:/xampp/htdocs/wordpress.local">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
##Second Virtual Host
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/modx"
ServerName modx
ServerAlias www.modx
DirectoryIndex index.php
CustomLog "C:/xampp/htdocs/modx/logs/access.log" combined
ErrorLog "C:/xampp/htdocs/modx/logs/error.log"
<Directory "C:/xampp/htdocs/modx">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Virtual Hosts Example
A working Virtual Hosts file example
I’ve seen many times where people (myself included) had trouble getting their Virtual Hosts configuration to work properly. There are several issues that can keep a Virtual Host from working, but many times the problem is directly related to the Virtual Hosts file itself.
Below is an example of a Virtual Hosts file that is working properly on one of my localhost testing servers via XAMPP on a Windows 7 Machine. This file will work the same directly in Apache from within Linux as well.
I’m not saying it’s the best configuration, I’m just saying it works. Anyway, I hope it helps someone.
All you have to do is change the paths, server names and whatever else is custom in your situation.
NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot C:/xampp/htdocs ServerName localhost </VirtualHost> <VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/wordpress.local" ServerName wordpress.local ServerAlias www.wordpress.local DirectoryIndex index.php CustomLog "C:/xampp/htdocs/wordpress.local/logs/access.log" combined ErrorLog "C:/xampp/htdocs/wordpress.local/logs/error.log" <Directory "C:/xampp/htdocs/wordpress.local"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> ##Second Virtual Host <VirtualHost *:80> DocumentRoot C:/xampp/htdocs ServerName localhost </VirtualHost> <VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/modx" ServerName modx ServerAlias www.modx DirectoryIndex index.php CustomLog "C:/xampp/htdocs/modx/logs/access.log" combined ErrorLog "C:/xampp/htdocs/modx/logs/error.log" <Directory "C:/xampp/htdocs/modx"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>