Emulating the web production environment with an Apache HTTP server running on a Windows 7 development machine
To minimize overhead costs of my website, I would restrain myself from buying a hosted plan until my website is launch-able. In the process of developing my website, I will want my tests to be as close to the real thing as possible.
This meant that when I type the domain of my website in my browser location bar, my browser will connect to my development web server, instead of the web server which my domain is being parked at.
I was using Windows 7 and an instance of Apache HTTP server as my development environment when I managed to achieve that. That instance of Apache HTTP server was listening at port 80.
There are two main steps to achieving such an objective:
- Routing HTTP requests, made to the actual domain, to my local machine
- Configuring Apache HTTP server to service HTTP request directed to the domain name
Routing HTTP requests, made to the actual domain, to my local machine
By default, my Windows 7 machine uses the services of a domain name server to map domain names into actual ip addresses in order to connect to another machines such as web servers. To emulate a hosted environment with my own Windows 7 machine, I tell it to map the domain name which I had bought into the loopback address.
To do so, I looked for the
hosts file at the
C:/Windows/System32/drivers/etc/ folder and added the following lines of configurations in the file:
127.0.0.1 techcoil.com 127.0.0.1 www.techcoil.com
When I do that, I had instructed my Windows 7 machine to return the loop back address (127.0.0.1) when my browser tries to access
www.techcoil.com. This result in my browser accessing my local Apache HTTP server with the domain name that I had bought.
Configuring Apache HTTP server to service HTTP request directed to the domain name
Directing my browser to connect to my local Apache HTTP server fulfills one part of the equation. The other part will be to configure my local Apache HTTP server to service HTTP requests directed to my domain name. To do so, I added the following lines of configurations in my
<VirtualHost *:80> ServerName techcoil.com ServerAlias www.techcoil.com DirectoryIndex index.php DocumentRoot "T:/techcoil.com" <Directory "T:/techcoil.com"> Order allow,deny allow from 127.0.0.1 </Directory> </VirtualHost>
The first two lines after the
VirtualHost directive tell Apache HTTP server that the configurations enclosed within are for HTTP requests which are directed at either
DirectoryIndex directive tells Apache HTTP server to send a HTTP response from
index.php in the event when the browser tries to access a folder.
DocumentRoot maps HTTP requests to the domain to the
T:/techcoil.com folder in my local filesystem.
Directory directive then instructs Apache HTTP server to limit accesses to files within
T:/techcoil.com to only those made from my development machine. Without configurations provided in the
Directory directive, my Apache HTTP server will return 403 Forbidden for requests hitting
Posts that may interest you
- Debugging PHP on Apache HTTP Server on Windows Server 2008
- Make your PHP webpage loads faster by aggregating external CSS scripts
- PHP codes to tell browsers to open the download dialog box for users to download a file