Multiple domain setup with Wndows and Apache

Sometimes, you might have several projects you want to access on the same server. You might also want to access them via a user friendly address, instead of using the IP address. Accessing it through a server is possible only through 127.0.01. What if we want to access more than just one project on the same server but not use 127.0.0.1  ?

You do not need to start or stop each project via separate servers. You could assign all of them different domain names on the same server. We would refer to each domain in a more readable address.

If you want to map a user friendly address to the all projects on the same server then here is how to do it on Windows with Apache. For this example, I am using XAMPP for the server stack. However using WAMP, would take an almost identical sequence of steps. There is not much difference.

  1. We will have to edit the host file.

  2. Usually, this is found in the directory C:\WINDOWS\system32\drivers\etc

  3. Open the host file, don’t do the mistake of opening it with a word processing application. It would reformat the file, and consequently mess the file up when saving it. Opening the host file with Notepad would be just fine.

  4. Add your fantastic domain name to this file. Of course, this is the local machine. So each line has the IP address of 127.0.0.1

  5. Let us say I am creating domain names for myFantasticSite.Blog and myFantasticSite.Forum.

127.0.0.1 myFantasticSite.blog

127.0.0.1 www. myFantasticSite.blog

127.0.0.1 myFantasticSite.forum

127.0.0.1 http://www.myFantasticSite.forum

  1. Save the changes.

That is it for the first part. Now we are left with the second part. Let us edit the httpd-vhosts.conf file.

  1. Locate the httpd-vhosts.conf file. For XAMPP, this is usually in C:\xampp\apache\conf\extra

  2. Open the file with plain old Notepad editor.

  3. For our fantastic site, we will add virtual hosts for each of them.

  4. Each of the virtual hosts will be of the form.

ServerName myFantasticSite.forum

ServerAlias http://www.myFantasticSite.forum

DocumentRoot “C:/xampp/htdocs/forum”

ServerName myFantasticSite.blog

ServerAlias http://www.myFantasticSite.blog

DocumentRoot “C:/xampp/htdocs/blog”

  1. Save the file, and restart the ApacheServer via the XAMPP control panel for these changes to take effect.

Congrats. That is all you needed to do. Now by just entering entering http://myFantasticSite.blog , your blog site will come up. When you also enter http://myFantasticSite.forum, your forum site should also come up.

Let me know if this was helpful.

Thank you so much for your time.

Leave a comment