Setting up virtual hosts in Apache is a fairly straight forward process, and these steps will help you get there.
Find this section of code in the httpd.conf file and uncomment the virtual hosts configuration file
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Open the host file. Details are below.
File: hosts (there is no file extension)
Directory: C:\WINDOWS\system32\drivers\etc
Make the necessary entries for the virtual hosts that you will be running as shown in the example below.
127.0.0.1 localhost 127.0.0.1 application 127.0.0.1 brentknigge
In the httpd-vhosts.conf we need to set up our localhost the same way that we did in httpd.conf.
<VirtualHost *:80> ServerAdmin <a href="mailto:brent@localhost">brent@localhost</a> DocumentRoot "C:/MyWebpages" ServerName localhost ErrorLog logs/localhost_error.log </VirtualHost>
Next we need to set up application. This virtual host will be used to store applications, e.g. phpMyAdmin, SQLite Manager, PHPDocumentor etc.
<VirtualHost *:80> ServerAdmin <a href="mailto:brent@localhost">brent@localhost</a> DocumentRoot "C:/MyWebApplications" ServerName application ErrorLog logs/application_error.log <Directory "C:/MyWebApplications"> Require ip 127.0.0.1 </Directory> </VirtualHost>
Note that the server name application is also the same name that was added to the hosts file. What this set up means is that I can now navigate to a webpage on my local machine as http://application/phpMyAdmin. Notice that the directory for localhost is separate from application which means that I can keep web specific applications like phpMyAdmin separate from the websites that I'm working on.
Continue following the step above for each of the virtual hosts that you have created. Just remember to restart Apache!
From Apache 2.4 onwards, a new Require directive has replaced the Order allow,deny. You can read more about this in the upgrade notes.
Comments
Add new comment