• Creating Subdomain in Localhost on windows using Apache / XAMPP

    Posted on July 5, 2012 by in Other Programming

    Creating subdomain(s) in any web development environment is essential. Assume a situation where you have a multisite wordpress website on your local machine, you can test this out creating subdomains. For a multisite installation such as qnownow.com you can create subdomains such as http://technico.local/,http://political.local/,http://finance.local/ etc. For this tutorial, I will be focusing on how this accomplished in the Apache install that is part of XAMPP. These steps should also work for a standalone install of Apache except that the file locations may be different.

    I am going to assume that you have already downloaded and installed XAMPP ,the example paths I’m going to be using are assuming that you’ve installed XAMPP, using the default install paths.If you have XAMPP installed in a different location, then change any paths to files accordingly.

    First thing you need to do is setup a virtual host by editing httpd-vhosts.conf file which is located at C:\xampp\apache\conf\extra\

    <VirtualHost *:80>
        ServerName localhost
        DocumentRoot "C:/xampp/htdocs/qnownow"
     
        DirectoryIndex index.php
     
        <Directory "C:/xampp/htdocs/qnownow">
            Options Indexes FollowSymLinks Includes ExecCGI
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>
     
    <VirtualHost *:80>
        ServerName technico.localhost
        DocumentRoot "C:/xampp/htdocs/qnownow"
     
        DirectoryIndex index.html index.php
     
        <Directory "C:/xampp/htdocs/qnownow">
            Options Indexes FollowSymLinks Includes ExecCGI
            AllowOverride All
            Order allow,deny
            Allow from all
        </Directory>
    </VirtualHost>
    

    You need to change the servername and document root as required.

    You need to also update the hosts file for this work, the hosts file is located at C:\Windows\System32\drivers\etc\hosts, the location might vary by OS. Open the file in a text editor like a notepad and add the following lines at the end of the file

    127.0.0.1 technico.local
    127.0.0.1 political.local
    127.0.0.1 finance.local
    

    Restart Apache and go to http://technico.local in your browser and you should be good to go.

    Be Sociable, Share!
      Post Tagged with , ,

    Written by

    Vanamali Juvvadi is a Web enthusiast and loves all things design and technology. Founded qnownow with a group of friends to share anything/everything they know/find on the internet.

    View all articles by

    Email : [email protected]

    Leave a Reply