Posted on Monday 20 December 2004
I write a lot of php/mySQL apps on a Windows environment. Instead of deploying scripts to a test server, I test them locally through an installation of Apache with PHP and MySQL. I was getting tired of changing the httpd.conf file every time I switched projects, so I did some research and found a nice little trick.
You probably already know that “localhost” is the same as 127.0.0.1, the loopback address. In fact, all of the addresses of the form 127.0.0.* are loopback addresses. Plugging these IPs into Apache’s Virtual Host facility, you can benefit from several virtual local servers. Here, I’ve set localhost’s document root to a generic test folder, and other folders to different addresses in section 3 of httpd.conf, Apache’s configuration file:
<VirtualHost 127.0.0.2>
ServerAdmin you@yourdomain.com
DocumentRoot "E:/phpmyadmin-2.5.7"
ServerName 127.0.0.2
Options Indexes FollowSymlinks MultiViews
</VirtualHost>
<VirtualHost 127.0.0.3>
ServerAdmin you@yourdomain.com
DocumentRoot "E:/projects/5etdemi"
ServerName 127.0.0.3
Options Indexes FollowSymlinks MultiViews
<Directory />
Options Indexes FollowSymlinks MultiViews ExecCGI
AllowOverride All AuthConfig
</Directory>
</VirtualHost>
Here, I’ve set 127.0.0.2 to an installation of phpMyAdmin, and 127.0.0.3 to my project files for this site. This way, by typing 127.0.0.2 into my browser, I get phpMyAdmin, and by typing 127.0.0.3, I get my site. Both of these have distinct roots so all the links work like they will online. You can see that you can specify extra options for one of these virtual hosts using the Directory command.



Sorry, the comment form is closed at this time.