Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have installed XAMPP, and my projects are saved in htdocs folder. When I view it in browser the URL identifies as http://localhost/example/index.php

How can I access it using a domain name of my choice, such as www.mysite.com?

My computer runs Windows 7, and I plan to access this website from my computer only (not across the web).

share|improve this question
    
What operating system are you doing this in? Are you trying to make this publicly accessible (to the internet), or just accessible from your computer/network? –  Everett Nov 17 '12 at 14:29
    
I am using Win 7. @Everett bro i just only need for my computer. how can i ? –  Sharpmind Nov 17 '12 at 14:38
    
I'd answer, but Kaplaa is right. Might as well accept that as the answer. –  Everett Nov 17 '12 at 16:56
    
@Everett i am clear with that idea but inside htdocs my index.php is in another folder. how can i add that and host in the way Kaplaa said ? –  Sharpmind Nov 17 '12 at 17:03
    
I pity whoever actually owns mysite.com (it's actually registered since back in 1995). –  Michael Kjörling Nov 17 '12 at 19:12
add comment

4 Answers

up vote 4 down vote accepted

You need to add a host to your hosts file.

Open a command shell and type the following command.

echo "127.0.0.1 www.mysite.com" >> %SYSTEMROOT%\System32\drivers\etc\hosts

You can test that this command has worked by cracking open a command shell and entering the following command:

ping www.mysite.com

This will confirm that you the host entry for www.mysite.com is located at 127.0.0.1. If you see an IP address that isn't 127.0.0.1 then the previous step did not complete correctly.

You will also need to edit your httpd.conf file and modify the the Virtual host section to include the following line:

ServerAlias www.mysite.com

Once your have made this change restart Apache. You will then be able to browse to "http://www.mysite.com"

share|improve this answer
    
this makes some what clear to me. but i have a doubt. inside htdocs folder my site is within another folder then how will it work if i give 127.0.0.1 ? Please explain –  Sharpmind Nov 17 '12 at 16:59
    
Good job on this answer Kaplaa. Look forward to seeing more of this quality from you in the future. –  Everett Nov 17 '12 at 17:08
    
Sharpmind - 127.0.0.1 is a loopback address. Almost anything that runs a TCP/IP stack (like Windows 7) recognizes this as its own address (loop back to me). You don't have to worry, this is a standard that is recognized by networking in general. As far as the folder goes, that's not a problem either. Here's a video that will help you in understanding what Kaplaa is telling you youtube.com/watch?v=XMqUG4E2M0M –  Everett Nov 17 '12 at 17:12
    
@Everett i tried the way. the echo in hosts and the httpd.conf ServerAlias and restrted apache. its not running the service now.. and if can show me the method for this host clearly please. –  Sharpmind Nov 17 '12 at 18:23
    
+1, but it's usually better to open the hosts file in an editor instead and add an alias to whatever 127.0.0.1 line is already there. I'm betting there was, and I'm not sure how Windows' resolver handles the presence of multiple lines with the same IP. Usually the syntax is ip-address alias-1 alias-2 alias-3 ... alias-N all on one line; e.g., 127.0.0.1 localhost www.mysite.example.com. –  Michael Kjörling Nov 17 '12 at 19:11
show 3 more comments

LifeHacker has got a few articles related to this.

See this : http://lifehacker.com/124804/geek-to-live--how-to-assign-a-domain-name-to-your-home-web-server

Step 1. Set up your DynDNS.com account.

Register for a free account at DynDNS. Agree to the site's terms, and use a legitimate email address to complete registration. Once in awhile, DynDNS will email you at that address asking you to confirm that it continue your service.

Log into your new account. Go to the "My Services" area on the left side. Under "Host Level Services" click "Add Host Services." There, click "Add Dynamic DNS Host." DynDNS will autofill your IP address (if you're doing this from your home computer). Choose a domain and type in a custom subdomain, which can be anything from lifehacker.kicks-ass.org or john.is-a-geek.com or gtrapani.dyndns.org, like below:

Step 2. Set up your computer to update DynDNS.

Now that your computer is registered with DynDNS, each time your computer's IP address changes, it has to let DynDNS know. This can be done either with free updater client software or through your router.

If your computer is connected directly to the Internet, download the DynDNS updater client for Mac or Windows here. Install and enter your DynDNS information so that your computer can update DynDNS's database regularly.

If you are behind a router, you're in luck. Most modern routers support dynamic DNS services. Here's a screenshot from my router's interface (yours will look different) for with DynDNS settings:

Step 3. You're done. Give your new domain a spin!

Type your new domain name by entering it in your web browser's address bar. It should resolve to your home server. From here you can publicize or bookmark your server's new domain name no matter how often your IP address changes.

Notes: DynDNS has a few advanced options to consider.

"Enable wildcard" lets you set up sub-subdomains. For example, blog.johnsmith.mine.nu can resolve to a weblog, where jukebox.johnsmith.mine.nu can resolve to a music directory. Virtual hosts must be configured for your Apache web server to display the right site when addressed by different subdomains. Set up an MX record to handle email handling to your home server. Upgrade your account assign a custom domain name or your choosing to your home server as well, for about 25 bucks a year. See more info on Custom DNS.

share|improve this answer
    
Vijay, I used to answer questions with a URL as well. Superuser frowns on this because places like LifeHacker may change the format of their URL's, or remove old stories entirely. Then when someone else comes along, they can't see the answer anymore (because the link doesn't work). Best practice is to include a cut and paste from the linked article that explains the answer. You can summarize it if you like, or use the quotes. This way the answer is permanently available. I'll edit your answer to show you what I mean. –  Everett Nov 17 '12 at 17:05
add comment

As I understand you want use a domain name on your local work. In that case you can edit your hosts file.

127.0.0.1 www.mysite.com

If you really want host your own site, you can use a dyndns subdomain and a cname forward from your domain control panel (if you haven't got a static IP address).

share|improve this answer
add comment

What you want to do is make your computer a NameServer ? Or you just want to forward a domain to the ip of your computer ?

You can forward the domain you purchased to the ip of your computer, make sure you have static ip (verify with internet service provider)

For practice, i would start playing with dynamic dns to figure how it works before pointing a REAL domain to your computer.

Link: http://howto.wired.com/wiki/Set_Up_Dynamic_DNS

share|improve this answer
    
Just to help you out for the future, questions about a question are typically asked in comments. What you've provided is interesting, even useful, but isn't really an answer for the clarified question... –  Everett Nov 17 '12 at 16:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.