you’re reading...


Configuring Apache server for Development to mimic production setup.

Your Ad Here

Most of the time a developer will need to test his programs against the production setup, to closely monitor the performance of the developed programs or if it will perform as expected when put into production. The best thing to do it is to enable Apache to mimic the production server setup so that the only thing a developer need to do is to transfer the files to the production server.

This is easily accomplished in Apache server using the virtual host configuration, wherein we can setup a server instance which exactly matched our production server. We just need to enable all the modules that we need and proceed in configuring the virtual host file.

Why do we need to enable virtual host?, you would say but apparently virtual host is needed if:

* you´re on multiple domains
* you need to test your projects with same configuration with the server
* test your projects without touching your public server
* you´re just organizing your projects into groups
* or setup a local copy of your blog or website

What do we need?, we need a server or a local computer running Apache either in Windows or Linux. Since most of us are developing using Windows we might as well use Windows using Apache Xampp for this setup.

1. In Apache we usually edit the httpd.conf to configure the virtual host file, but in Xampp it is a separate file being called inside the apache httpd.conf. You will find your httpd.conf in your drive where you installed Xampp in my case it’s in my D: drive under the xampp folder navigate through D:\xampp\apache\conf you will find there your httpd.conf.

2. Inside our D:\xampp\apache\conf directory we will see a folder named extra. These folder holds additional configuration for our apache server. Before the functions can be configurable inside the httpd.conf but now it is just being called inside the httpd.conf when we start the server. Configuration in this manner is much simple since we will immediately know in which part of the configuration, we have committed an error if our server suddenly doesn’t start. It is always a good idea to create a backup of the original file for reference or to restore it to original state if we commit an error.

3. In the folder extra look for the file named httpd-vhost.conf this is what we need to configure to enable our virtual host environment. We will used name-based virtual hosting for these. There are two configurations for virtual host name-based and ip-based.

When you open the httpd-vhost.conf you will see something like the following code below as a sample code:

# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any block.
# ServerAdmin webmaster@local
# DocumentRoot D:/xampp/htdocs/www
# ServerName local
# ServerAlias local
# ErrorLog @rel_logfiledir@/cabsites-error_log
# CustomLog @rel_logfiledir@/cabsites-access_log common


# Options Indexes FollowSymLinks
# AllowOverride All
# Order allow,deny
# Allow from all

#DocumentRoot D:/xampp/htdocs/www/
#ServerName localhost

DocumentRoot “D:/xampp/htdocs”
ServerName localhost

DocumentRoot “D:/xeroxss/app/webroot”

Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all

Order allow,deny
Allow from all
Order deny,allow
Deny from all

I just configured my development server to use D:/xeroxss/app/webroot as my webroot folder wherein, I will put my webfiles. Localhost configuration reflects my default Xampp configuration folder for localhost so that my server will still be accessible through localhost with my default configuration, useful in accessing our PhpMyadmin installation.

My virtual host will actually use my drive D:/xeroxss/app/webroot and all my web documents will be served in that directory.

4. We are not done yet since we need to configure our computer to recognize the domain that we add remember that this domain is not registered and therefore will not be accessible in any DNS servers. So with all computers we need to configure our own computer so that it will search its own host file first before querying any DNS servers.

In Windows the host file is located under C:\WINDOWS\system32\drivers\etc\host so we need to edit this file and add the domain that we created to it for it to be recognized as valid domain by our computer. When you open it you will see:

# Copyright (c) 1993-1999 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a ‘#’ symbol.
# For example:
# # source server
# # x client host localhost

Put our configuration there save and restart the Apache server. If you encounter an error make sure that you follow the exact code above and check your syntax. To test just save an index.html in your created virtual host folder and it will be accessible in your virtual host server. Or try to ping your created domain in your command prompt first to make sure that your computer recognized your host file. You will be able to ping your domain and see something like this.

Pinging virtual host

Pinging virtual host



One comment for “Configuring Apache server for Development to mimic production setup.”

  1. […] 1. Configure httpd-vhosts.conf to work with standard virtual host http access at port 80. -A detailed explanation on how to do step 1 is here:… […]

    Posted by EG-DesignStudio | Setting Up XAMPP with SSL on Virtual Host in your Windows 7 Development Machine or Linux | March 30, 2012, 2:06 pm

Post a comment

You must be logged in to post a comment.



Register and Participate

Registration to this website is free. Feel free to use and explore the features of the website. You are welcome to participate and interact with us in the forum. If you have concerns that you want us to know you can easily contact us using this link. By registering in this website, your account will allow you to login and participate in the forum and to access additional information that is only available to registered users. We are keeping this website to be informative for us and to our users.