How to create a local web host domain name for free

9,269

Solution 1

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"

Solution 2

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:
9,269

Related videos on Youtube

Sharpmind
Author by

Sharpmind

I am a Final Year Student of ICBT City Campus in Sri Lanka doing by HND in Computing & Software Development. I hope il get full support on Programming from the users here. Thanks in Advance to All. God Bless All

Updated on September 18, 2022

Comments

  • Sharpmind
    Sharpmind over 1 year

    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).

    • Everett
      Everett over 11 years
      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?
    • Sharpmind
      Sharpmind over 11 years
      I am using Win 7. @Everett bro i just only need for my computer. how can i ?
    • Sharpmind
      Sharpmind over 11 years
      @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 ?
    • user
      user over 11 years
      I pity whoever actually owns mysite.com (it's actually registered since back in 1995).
  • Everett
    Everett over 11 years
    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...
  • Sharpmind
    Sharpmind over 11 years
    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
  • Everett
    Everett over 11 years
    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
    Everett over 11 years
    Good job on this answer Kaplaa. Look forward to seeing more of this quality from you in the future.
  • Sharpmind
    Sharpmind over 11 years
    @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.
  • user
    user over 11 years
    +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.
  • Kaplaa
    Kaplaa over 11 years
    @Sharpmind - If the Apache service is no longer starting then that is the result of a incorrect configuration file. You would need to run the apache config check test against your configuration file. You can do this by running '\path\to\apache -c \path\to\httpd.conf -d \path\to\apache\base\directory -t'. This will then check your httpd.conf for errors and tell you the line numbers of the errors. If you need further help you will need to post your httpd.conf for close inspection.
  • Kaplaa
    Kaplaa over 11 years
    @Michael Kjörling - link This site (which is very old) has an example of mapping two host name alias to one IP address while split over two lines. '144.3.56.200 ARCHIVE.RESEARCH.COM 144.3.56.200 archive.research.com'. The lack of formatting in these comments stops me reproducing this code exactly as it was displayed on the Microsoft site.
  • Sharpmind
    Sharpmind over 11 years
    @Kaplaa after i restartd apache was not working so i re 0 installed to see again same problem and it say "Port 80 in use by "system"!" how to over come this ? Thank you