Journal » Post
|
|
Lately I've been handling more and more sites for my clients, that translates to more testing and updating of scripts on my end. To increase productivity and efficiency I often test the stuff on my local machine before I upload them to the actual server. So I decided to make use of virtual hosts to emulate the sites that I am working on. Just to be clear, I'm using Apache 2.2.x (note: I don't use WAMP or the like.) on a Win32 machine. So first up open your httpd.conf and uncomment the line:
Include conf/extra/httpd-vhosts.conf
httpd-vhosts.conf will be where we put our virtual host settings and is located within your apache install directory in /conf/extra. After this we will create a folder where all our virtual hosts will be pointing to e.g. C:\virtualhosts, then we make sure we can access it later via http by adding this to the httpd.conf
Now open your httpd-vhosts.conf so we can set our virtual hosts. There are 2 ways we can access our vitual host namely via it's server name or port, I'll be showing you both but first we will be using the ServerName method. This is done by adding the following lines in your httpd-vhosts.conf: In this example i will be making a virtual host for my PhpMyAdmin installation.
Then open your hosts file in Windows which is usually located at C:\WINDOWS\system32\drivers\etc and add the following line at the bottom
127.0.0.1 phpma.local
Notice that we used the SeverName phpma.local on the hosts file that way we can access it on our browser by simply typing in phpma.local. Note that we cannot use any other ports aside from 80 since we cannot specify ports in the hosts files, if you want to have a specific port for your virtual host so it can be access via your ip:port we just add the following to your httpd-vhosts.conf
After you finish making the necessary alterations to the config files, restart your apache server.Now I can access phpmyadmin by either typing in phpma.local or 127.0.0.1:2082 on my browser. This can be done repeatedly depending on how many virtual hosts you'll be needing. This is especially useful to me since I test out a lot of things. I hope this helps someone, happy coding! |



