Saturday, June 1, 2013

Serve Multiple Sites from Singe IP Address on Apache

If you want to run multiple sites on one Apache web server say several PHP frameworks - this is how you need to set up the XAMPP server. For WAMP server you need to keep in mind that there are two httpd.conf files and two httpd-vhosts.conf files so you need to modify the right ones.
Don't forget to include DirectoryIndex index.php line in your virtual hosts 'cause some frameworks will not work without it.
This is ideal for development environments such as Magento that requires a dot in URL. The only modification you need to make in httpd.conf file is to uncomment line that defines file for virtual hosts.
See code below.

File: c:\xampp\apache\conf\httpd.conf
...
# Virtual hosts
Include "conf/extra/httpd-vhosts.conf"
...
File: c:\WINDOWS\system32\drivers\etc\hosts
127.0.0.1               localhost
127.0.0.1               cakephp2.local
127.0.0.1               cakephp12.local
127.0.0.1               zend.local
File: c:\xampp\apache\conf\extra\httpd-vhosts.conf
NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot c:/xampp/htdocs
    ServerName localhost
    ErrorLog "logs/error.log"
    CustomLog "logs/access.log" combined
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot c:/xampp/htdocs/cakephp2/app/webroot
    ServerName cakephp2.local
    DirectoryIndex index.php
    ErrorLog "logs/c2error.log"
    CustomLog "logs/c2access.log" combined    
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot c:/xampp/htdocs/cakephp12/app/webroot
    ServerName cakephp12.local
    DirectoryIndex index.php
    ErrorLog "logs/c12error.log"
    CustomLog "logs/c12access.log" combined    
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot c:/xampp/htdocs/zend/public
    ServerName zend.local
    DirectoryIndex index.php
    ErrorLog "logs/zerror.log"
    CustomLog "logs/zaccess.log" combined    
</VirtualHost>
Separating error and access logs is also good idea. Place virtual host directories inside localhost's directory.

No comments:

Post a Comment