Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to add a custom domain name on your localhost using XAMPP. Codes are based on Windows, but Step 2 onwards are pretty much applicable on other operating system.
Step 1:
Go to: C:\Windows\System32\Drivers\etc\hosts
And add this to the bottom of the file:
=============
127.0.0.1 your.domain.com
=============
Step 2:
Go to [your XAMPP directory]/apache/conf/httpd-xampp.conf
Step 3:
Go to the bottom of the file and copy & paste this code:
=============
<VirtualHost *:80>
DocumentRoot "[PATH TO YOUR CUSTOM FOLDER]"
ServerName your.domain.com
<Directory "[PATH TO YOUR CUSTOM FOLDER]">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
=============
* Replace [PATH TO YOUR CUSTOM FOLDER] to the folder where your files are located.
Ex: C:/my/www/folder/
* your.domain.com must be the same on Step 1 & Step 3
Step 4:
Stop Apache on XAMPP, wait for 5 seconds, then click "Start" to start again your Apache.
If all things go well, you can go to your browser, type your.domain.com
and it will now happily point to your custom local folder.
@shahhussain305
Copy link

shahhussain305 commented Nov 13, 2015

Wonderful work, i really appreciated it.
It will also be appreciable if you please share the same process for Ubuntu Server.
Thanks

@IA21
Copy link

IA21 commented Feb 1, 2017

Thanks a lot man!

@Thientran2910
Copy link

Thientran2910 commented May 17, 2017

Thank you very much

@effiemakri
Copy link

effiemakri commented Nov 20, 2017

Hello, thanks for these instructions.
I followed them for a Mac (v 10.12.6), and when I went to "localhost" (which is what my domain.com is set up to be), I get the message: Forbidden: You don't have permission to access / on this server.
Any ideas?
Thanks

@Rajeshkr198
Copy link

Rajeshkr198 commented Mar 14, 2018

It doesn't work in my case... Google respond this site can't be reached

@MuslimHS
Copy link

MuslimHS commented Mar 27, 2018

Hi, thanks for this simple explanation. It really saved my time.
One thing though, I think there's a slight mistake on Step 2: Go to [your XAMPP directory]/apache/conf/httpd-xampp.conf , shouldn't it be httpd-vhosts.conf?

@acxgray
Copy link

acxgray commented Oct 30, 2018

Thanks a lot men, It's working on my XAMPP

@ne3nay
Copy link

ne3nay commented Nov 5, 2018

Дякую

@noneuf
Copy link

noneuf commented Nov 13, 2018

On mac, I get this message after following the instructions, any ideas?
Forbidden
You don't have permission to access / on this server.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

@definitelyme
Copy link

definitelyme commented Nov 18, 2018

Excellent. Great job man

@huraji
Copy link

huraji commented Apr 9, 2019

Nice but I have a question. I'm trying to access this subdomain from a mobile device connected to the same wifi. So I type the IP address of my machine and I get redirected to the subdomain but I get "Could not connect to the server".
I'm running an SSL self signed, XAMPP, Windows 10. Do you have suggestion?

@mateegojra
Copy link

mateegojra commented Oct 3, 2019

great effort.... short and easy to understand (Y)

@fpascual-sollutia
Copy link

fpascual-sollutia commented Jan 15, 2020

It works. As easy as it seems. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment