Using Example.com domain on XAMPP (Windows)

A few minutes ago, I read a short tutorial about this subject at abcphp.com and no matter how I tried, I couldn’t get it to work. I’m not sure if I’m stupid or if the tutorial is written wrong. Either way, I’ve decided to Google a bit and see if I can find out, how to do this.

What I was trying to achieve is:
Make example.com available as a domain on my local Windows PC using XAMPP. Why example.com you ask?
The answer is given in the above mentioned tutorial:

Example.com [or example.org, example.net] is a special domain as defined in RFC 2606 used for, you guessed it, examples. These domains will never be available to the public, so there’s no need to worry about not being able to access the actual site in the future.

So it’s perfect for our purposes.

Foolish assumptions

  • I am assuming that you installed XAMPP on your Windows PC and that you installed it in c:\xampp
  • I am assuming that your local IP address is 192.168.2.102 – it most certainly isn’t, but mine is. Please change the code I will give you accordingly. If you don’t know how, what your local IP is, here’s how to find it: Press and hold the Windows key and press R. You will see a new little promt thing. Type: cmd
    Then you will see a black DOS command promt. Enter: ipconfig
    This will give you a list of network connections. Chances are, there’s only one. Look for the line starting: IPv4-Addres. The number that comes after this is your local static IP address. If you have more than one Ethernet Adapter showing up there, try each one.

What we need to point example.com to our XAMPP is, we need to set up a so called Virtual Host. Now, it’s REALLY important for you to understand exactly, what a Virtual Host is and how it works! Nah, just yanking your chain.
It’s beyond the scope of this little article, but if you want to find out what a Virtual Host is exactly, click here.

Step 1

Open the file httpd.conf in your favorite text editor. If you installed XAMPP in c:\xampp then it’s located at: C:\xampp\apache\conf

Scroll aaaaaaaaaaaaaaaaaall the way down.

Now, copy and paste this code at the end of the file:

<VirtualHost 192.168.2.102:80>
ServerName example.com
UseCanonicalName Off
DocumentRoot C:/xampp/htdocs
</VirtualHost>

Now remember: change 192.168.2.102 to YOUR local IP address. The :80 after the IP address must remain there. And if you didn’t install XAMPP in c:\xampp, then change C:/xampp/htdocs to the correct setting!

Now save the file and close it.

Step 2

If you are using Windows XP, open up the Notepad program. If you are using Vista or Windows 7, you need to open it with Administrator privileges. If you don’t know how to do that, here’s how:

Open Notepad with Administrative privileges by clicking Start, All Programs, Accessories, and then right-click Notepad and select to open as Administrator.

In Notepad, click File, then Open. Or hit Ctrl+O

Go to this folder:

C:\Windows\System32\drivers\etc

Can’t see anything? Not to worry. Notepad only displays text files by default, so we need to tell stupid Notepad to show ALL the files. At the bottom right corner, you’ll see a little dropdown menu that has “Text files (*.txt)” in it. Click that and set it to “All files”. And voilá!

Now open the file called hosts.

Scroll down to the bottom and enter this code:

192.168.2.102            example.com
192.168.2.102            www.example.com

Obviously, again, you must change 192.168.2.102 to your own local IP.

Then save the file and close Notepad.

Now, restart Apache, then enter www.example.com in your browser and watch the magic happen. :)

If you don’t know how to restart Apache, just restart your PC.

Post to Twitter

You can leave a response, or trackback from your own site.

View Comments to “Using Example.com domain on XAMPP (Windows)”

  1. jap says:

    I have deployed my system on a LAN. They can access my system through my IP address. Will it also be possible for them to access it on a dot-com?

Leave a Reply

blog comments powered by Disqus