Recently I need to maintain multiple websites’ source code (PHP) at the same time at local host. Every time I need test another website, I need to modify the httpd.conf configuration file and restart the Apache server. After some researches on the internet, I manage to find a way to setup multiple virtual host.
- Modify httpd.conf to add in the following code after the “LoadModule xxx” lines:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
DocumentRoot "C:\php\site1"
ServerName site1
</VirtualHost>
<VirtualHost 127.0.0.1>
DocumentRoot "C:\php\site2"
ServerName site2
</VirtualHost>- Where “C:\php\site1” and “C:\php\site2” is the path to files for virtual host “site1” and “site2” respectively.
- Restart Apache Httpd service.
- Edit the file in “C:\[Windows]\System32\drivers\etc\hosts and add in the following lines:
127.0.0.1 site2
127.0.0.1 site1- Point your browser to “http://site1/” or “http://site2” and will be execute to both site1 and site2 code.
Hope this bookmark help you too.
Kien says
It’s save my time. Thanks.