Clone Online Site In Apache

Sometimes, it is useful to replicate the online site in a local machine for development purposes. In this article we will see, how to configure Apache to serve the clones of the online sites.

Creating sites.conf

In this step, we will create sites.conf. The sites.conf contains the config options for all the sites you want to develop in your local machine.

First , we should find <apache> location and decide what will be the <sites> location:

  • <apache> is the, location, where Apache Server is installed.
    Example : C:/Program Files/apache

  • <sites> is the location, where sites.conf, the content and the logs of your sites are located.
    Example : C:/sites

Now, follow these steps:

  1. Open <apache>/conf/httpd.conf config file and add the following line in its end.

    Include "<sites>/sites.conf"

  2. Create the newly included file <sites>/sites.conf

Adding a site

In this step, we will add the new site.

First, you should know <site-domain> and generate a unique <site-name>:

  • <site-domain> - The domain, where the site is located.
    Example : ,

  • <site-name> - A unique name, which identifies the site. A simple strategy to generate this name: use name.
    Example for, use of the demo. uses the name_subdomain.
    Example for use demo_s1.

Now, follow these steps:

  1. create a new <sites>/<site-name> directory, create the following sub directories inside:

    • www - This directory will contain the actual content of the site that should be served by apache.
    • log - This directory will contain the logs related to the site.

  2. Add the config snippet, given below, to the <sites>/sites.conf,
    1. <VirtualHost> ServerName  
    2.     <site-domain> ErrorLog "  
    3.         <sites>/  
    4.             <site-name>/log/error.log" TransferLog "  
    5.                 <sites>/  
    6.             <site-name>/log/transfer.log" DocumentRoot "  
    7.         <sites>/  
    8.     <site-name>/www"  
    9.   <Directory "<sites>/<site-name>/www"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Require all granted </Directory>  
    10. </VirtualHost>  
  3. Add a new mappings of IP addresses to the <site-domain> in the hosts file. This file is usually located in C:\Windows\System32\drivers\etc, <site-domain>

  4. Start/Restart apache

Example: Suppose we want to develop , , on our local machine.

  1. We decide that our sites directory will be C:/sites.
  2. We create the following directory structure:


  3. We edit sites.conf, as shown below:
    1. <VirtualHost>   
    2. ServerName   
    3. DocumentRoot "C:/sites/demo/www"   
    4. ErrorLog "C:/sites/demo/log/error.log"   
    5. TransferLog "C:/sites/demo/log/transfer.log"   
    6. <Directory "C:/sites/demo/www">   
    7. Options Indexes FollowSymLinks Includes ExecCGI   
    8. AllowOverride All   
    9. Require all granted   
    10. </Directory>   
    11. </VirtualHost>   
    13. <VirtualHost>   
    14. ServerName   
    15. DocumentRoot "C:/sites/demo_s1/www"   
    16. ErrorLog "C:/sites/demo_s1/log/error.log"   
    17. TransferLog "C:/sites/demo_s1/log/transfer.log"   
    18. <Directory "C:/sites/demo_s1/www">   
    19. Options Indexes FollowSymLinks Includes ExecCGI   
    20. AllowOverride All   
    21. Require all granted   
    22. </Directory>   
    23. </VirtualHost>   
    25. <VirtualHost>   
    26. ServerName   
    27. DocumentRoot "C:/sites/demo_s2/www"   
    28. ErrorLog "C:/sites/demo_s2/log/error.log"   
    29. TransferLog "C:/sites/demo_s2/log/transfer.log"   
    30. <Directory "C:/sites/demo_s2/www">   
    31. Options Indexes FollowSymLinks Includes ExecCGI   
    32. AllowOverride All   
    33. Require all granted   
    34. </Directory>   
    35. </VirtualHost>   
  4. We include it in <apache>/conf/httpd.conf.

    Include "C:/sites/sites.conf"

  5. We edit the hosts file.

  6. We start/restart apache.

Now, when we access :

  • , index.html under C:/sites/demo/www will be served
  • , index.html under C:/sites/demo_s1/www will be served
  • , index.html under C:/sites/demo_s2/www will be served

Read the article in my blog here, Clone online site in Apache.