How to Set Up Custom Domains/URL's or Web Addresses on localhost/local computer

Introduction

In this tutorial, I'll explain you how to set up custom domains on server running on your local computer for different type of purposes. This tutorial will only help you in setting up those domains which does not end in TLDs such as "dot com", "dot net", "dot org" etc., which are owned by ICANN. I don't know whether this type of mapping would work with them too or not but this will definitely fulfill our basic requirement of testing our web focused projects on a top level type of domain such as "example.local", "example.run" etc. . Do not worry about complexity and system errors/bugs because this is very simple procedure that can be done easily without doing big changes in system configuration files. Lets end up our introduction part here and come directly to procedure that need to be followed.

I found this great information yesterday (26-12-2011) while reading some tutorials on "PHP Zend Framework", which is also a good tool if anyone wants to work in an organized manner without worrying about security issues such as SQL injection etc. . Zend Framework follows the principle of method of Popular MVC (Model View controller) format.

How to set up custom domains of URLs for your projects on localhost
How to set up custom domains of URLs for your projects on localhost | Source

Basic Requirements to SetUP custom URLs on localhost

  1. Windows XP, Vista, 7,
  2. Apache Web Server - You can download Xampp, which comes pre packaged with all the tools that are required in running a web server (Apache) including Mercury (An Email Client), Filezilla, Open SSL, PHPMyAdmin etc.

And that's all, which is required for setting up an custom domain name.

Procedure of Setting UP Custom Domain on your Own Computer

Here, I'll show you step by step tutorial on setting up custom URL for your web project. Just follow my steps.

  1. First, Go to "C:\Windows\System32\drivers\etc",
  2. Second, Open the file named as "hosts" in notepad,
  3. Third, At the end of file on new line add this "127.0.0.1 myproject.run" (You can modify this as per your requirements) without "#" before it and then save it and close.
  4. Fourth, Go to directory where Apache is installed or Xampp is installed, Something like "C:\Program Files\xampp\apache\conf",
  5. Fifth, Open the file named as "httpd.conf" in notepad,
  6. Go to the end of file and add code shown below.

# Setup Listening Port
NameVirtualHost *:80

# Ensure "localhost" is preserved
<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "C:/Program Files/xampp/htdocs/"
</VirtualHost>

# Setup "myproject" Virtual Host
<VirtualHost *:80>
    ServerName myproject.run
    DocumentRoot "C:/Program Files/xampp/htdocs/online/server/projects/"

    <Directory "C:/Program Files/xampp/htdocs/online/server/projects/">
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

You can change the host definition after this comment "# Setup "myproject" Virtual Host on code shown above as per your requirements and needs.

We are defining three things here i.e.

  1. "ServerName" - which is our domain name / Web address / URL,
  2. "DocumentRoot" - The folder which which accessible by this domain name
  3. "Directory" - Where we are defining other definitions which are required at minimum.

After this, You need to restart your Apache server for changes to take effect. In Xampp, you can do this directly from Xampp control panel. After that, Open your browser and type "myproject.run" in address bar and homepage of your project will appear on browser screen. You can add as many domain names you want and that too for free :LOL:.

I'll soon add more information about how to setup custom domain names on linux, till then, enjoy.

More by this Author


Comments

No comments yet.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working