How to Set Up Custom Domains/URL's or Web Addresses on localhost/local computer
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.
Basic Requirements to SetUP custom URLs on localhost
- Windows XP, Vista, 7,
- 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.
- First, Go to "C:\Windows\System32\drivers\etc",
- Second, Open the file named as "hosts" in notepad,
- 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.
- Fourth, Go to directory where Apache is installed or Xampp is installed, Something like "C:\Program Files\xampp\apache\conf",
- Fifth, Open the file named as "httpd.conf" in notepad,
- 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.
- "ServerName" - which is our domain name / Web address / URL,
- "DocumentRoot" - The folder which which accessible by this domain name
- "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
How to Develop c++ programm that will try connecting to internet and will fetch data from it using Wininet Library (Devc++ IDE).
In this PHP tutorial, I'm Publishing some details about urlencode and rawurlencode functions of PHP which Includes syntax, examples, Character conversion table and much more...
Basic Knowledge and things that one should have before purchasing any laptop computer. Screen, Memory, Storage, Processor, Interface, Display, Graphics and Much More...
No comments yet.