How to access website hosted in localhost from internet

Web programming topics
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

How to access website hosted in localhost from internet

Post by Neo » Tue Mar 23, 2010 11:27 am

Following steps will allow you to access a website hosted on your machine (localhost) from internet (no matter you have a ADSL modem that brings you a dynamic WAN IP).
  1. Assign a static IP to your computer (with web server)
    Each computer in a network has its own internal IP address. That IP address may be static, which means that it never changes. Or, as is likely if you share an Internet connection with other computers, the internal IP address may be assigned dynamically and may change from time to time.

    Note: in a network configuration, the internal IP is not the same as the IP assigned by your ISP. The IP assigned by your ISP can be either static or dynamic.

    When you are opening ports to allow incoming connections to your computer, your computer must be assigned a static internal IP address, to ensure that the incoming connections always go to the correct computer.

    There are several steps:
    1. See your current IP address
      Find your current IP address and whether it is static or dynamic:
      1. Open Windows Start menu
      2. Select Run. Type: command and click OK.
      3. At the blinking cursor, type: ipconfig /all and press Enter.
      4. Look for these entries near the end of the list:
        • Dhcp Enabled. No means your IP address is static. Yes means it is dynamic.
        • IP Address. This is your current IP address.
      5. To exit, at the blinking cursor, type: exit and press Enter.
      If your current IP address is:
      • Static, then make note of the IP address. You need the IP address when you open ports in your router or firewall.
      • Dynamic, then assign a static IP address instead.
      ipconfig.gif
      ipconfig.gif (17.34 KiB) Viewed 32564 times
    2. Choose a static IP address
      Choose an IP address, and collect other information needed in order to assign a static IP address to your computer.
      1. In your router administration program, find and remember this information:
        • Router (Gateway) IP address
        • Subnet Mask
        • IP addresses of your DNS servers
      2. In your router administration program, find an IP address that can be assigned as a static IP. The address:
        • Must not be one that might be assigned to someone as a dynamic address.
        • Must not be one that has been assigned to another device (often these are the low numbers).
        • Must be lower than the range of dynamic addresses.

    3. Assign the static IP address
      To set a static IP address:
      1. Open Windows Start menu.
      2. Open Control Panel.
      3. Classic view: Open Network Connections
        Category view: Select Network and Internet Connections, and then Network Connections.
      4. Double-click on your active LAN or Internet connection.
      5. Click Properties.
        This opens the Local Area Connections Properties window.
      6. In the General tab, highlight the Internet Protocol (TCP/IP) item, and click Properties.
        LACproperties.gif
        LACproperties.gif (37.86 KiB) Viewed 32564 times
        This opens the Internet Protocol (TCP/IP) Properties window.
      7. In the General tab, click Use the following IP address, and enter:
        • IP address. The static IP address you want to assign to this computer.
        • Subnet mask. Subnet mask used by your router.
        • Default gateway. IP address of your router's default gateway.
      8. In Use the following DNS server addresses, enter all the IP addressses for the DNS servers your router uses.
      9. Click OK.
        tcp.gif
        tcp.gif (33.11 KiB) Viewed 32564 times
        Then:
      10. Click OK to close each window.
      11. Restart your computer.
      12. Then, check your IP address again, to make sure that the changes were applied.
    For example, let's say you picked the IP address 192.168.1.102. After the above step is completed, you should be able to get to the website on your local machine by going to both http://localhost and http://192.168.1.102, since your computer will now always have that IP address on your network.
  2. Configure Port Forwarding on your router
    We need to forward all packets that are coming to port 80 (web server) to your machine. This is done through port forwarding.
    This is done very easily by following steps.
    1. Login to you router
    2. Enable Port Forwarding (If there is a tick box)
    3. Go to Port Forwarding page and set Port 80 (Web Server) to be forwarded to your machine (Put your PC's IP there).
    There are differences in configuration on each brand/model. Here are some examples.
    DLinkPF.JPG
    DLinkPF.JPG (68.52 KiB) Viewed 32564 times
    LinkSysPF.gif
    LinkSysPF.gif (32.73 KiB) Viewed 32564 times
    NetGearPF.jpg
    NetGearPF.jpg (40.3 KiB) Viewed 32564 times
  3. Find your WAN IP
    If you look up your IP address (such as http://www.ip-adress.com/), the IP you see is actually the IP of your router (WAN IP). When your friend accesses your website, you'll give him this IP. Having done all that, your friend should now be able to access your web page by going to his web browser on his machine and entering http://IP.address.of.your.computer (the same one you see when you go here ).
  4. Assign a domain name to your IP
    Since DSL users usually get a dynamic IP, you have to always give your IP to your friend to access your web page. There is anice solution to come up with this. You can assign a domain name to your IP with a service called DynDns.
    DynDNS.JPG
    DynDNS.JPG (96.1 KiB) Viewed 32564 times
    After going through registration and email verification, finally you can see your domain is activated as below.
    DynDNSlist.JPG
    DynDNSlist.JPG (18.96 KiB) Viewed 32564 times
    Finally, download the DynDNS update client software and install it in your PC. Using an update client with your Dynamic DNS hostname allows you to make sure you can always reach your home network, because it makes sure that your hostname is always up-to-date with the latest IP address. The update client runs in the background, so once you have it properly configured you don't have to worry about it; you only need to remember your hostname to reach your files and services.
  5. Check access to localhost is allowed through internet
    In some cases we need to configure our web server to allow access to web server from internet.
    For example, on Apache server, you may have to do the following steps (If those are not already configured).
    1. Edit file C:\www\vhosts\localhost\.htaccess
      There will be these lines within:

      Code: Select all

      order deny,allow
      deny from all
      allow from 127.0.0.1
      Comment all of them out by placing a # sign at beginning of each line.
    2. Edit file C:\www\Apache22\conf\extra\httpd-vhosts.conf
      Find the first VirtualHost block... Which is the "localhost" block.

      You will see lines:

      Code: Select all

       <VirtualHost *:80>
       DocumentRoot "C:/www/vhosts/localhost/_"
       ServerName localhost
       ServerAlias 127.0.0.1

      Update line 'ServerAlias 127.0.0.1' to 'ServerAlias 127.0.0.1 my.domain.com'

      Note that you can add more domains and IP addresses [such as your LAN system IP] to this line.

      Save file. Restart Apache.
    The reason access is restricted (by default) under "localhost" to the local system is due to security issues. When the Suite is first installed some of the web apps are not fully finished with their installation process and it would be un-wise at that stage to open access to them on the internet.

    The reason you have to make the changes to httpd-vhosts.conf to bind "localhost" to additional IP addresses is a technical one. There is a conflict with a default Virtual Host and the dynamic domains feature of the Suite.
I wanted to provide a complete guide and hope this will help you!
Neofriend
Captain
Captain
Posts: 103
Joined: Wed Dec 23, 2009 3:37 pm
Location: Pakistan

Re: How to access website hosted in localhost from internet

Post by Neofriend » Tue Mar 23, 2010 3:49 pm

the title sounds pretty interesting.... let me read in detail now :)
thegtaguy
Corporal
Corporal
Posts: 9
Joined: Fri Dec 17, 2010 8:48 pm

Re: How to access website hosted in localhost from internet

Post by thegtaguy » Fri Dec 17, 2010 8:55 pm

When Somebody Enters my WAN IP into their BROSWERS ADDRESS BAR they get an error saying :

Code: Select all

This Address may be temporarily down ...
When i enter MY WAN IP in my address bar i get redirected to my ROUTER Admin Panel !!

Please Help ME !!
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: How to access website hosted in localhost from internet

Post by Neo » Fri Dec 17, 2010 9:51 pm

Foe me, it seems that you have not correctly setup port forwarding (Step 2). Can you check on that?
If you do not correctly forward port 80 (Web Server) to your machine, obviously you will expereince the issue you explained earlier.
thegtaguy
Corporal
Corporal
Posts: 9
Joined: Fri Dec 17, 2010 8:48 pm

Re: How to access website hosted in localhost from internet

Post by thegtaguy » Sun Dec 19, 2010 10:15 am

Neo wrote:Foe me, it seems that you have not correctly setup port forwarding (Step 2). Can you check on that?
If you do not correctly forward port 80 (Web Server) to your machine, obviously you will expereince the issue you explained earlier.
Actually , I had a Little Confusion ...
I wanted to Ask U ...
I have a DHCP connection , So my Default Gateway is 192.168.1.1 // This is Shown in MY CMD //
If i Go to IP-ADDRESS.com , I get a Different IP // You Know U Are the ADMIN // :D

If enter Both of them in my Address Bar Both Take me to the Router Authentication Page ...
Which one should i login to and edit ?

I'm Using Window 7 + XAMPP !!
Thanks ...
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: How to access website hosted in localhost from internet

Post by Neo » Mon Dec 20, 2010 3:50 pm

I have a DHCP connection , So my Default Gateway is 192.168.1.1 // This is Shown in MY CMD //
If i Go to IP-ADDRESS.com , I get a Different IP
If you want to forward port 80 to your web server, you will have to off the DHCP server on router and assign a static IP to your PC. Read the first post on that.
If enter Both of them in my Address Bar Both Take me to the Router Authentication Page ...
Which one should i login to and edit ?
Use the LAN IP to login to the admin page since all WAN IPs are then transfered to your PC.

I recommend WAMP since I'm working with that for years now without any issue.
thegtaguy
Corporal
Corporal
Posts: 9
Joined: Fri Dec 17, 2010 8:48 pm

Re: How to access website hosted in localhost from internet

Post by thegtaguy » Sat Dec 25, 2010 10:35 am

Thank You Very much my Website is up and Running on my IP ...
Can u tell me how can i configure my web mail , FTP .. etc.
Thank You !!
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: How to access website hosted in localhost from internet

Post by Neo » Sat Dec 25, 2010 1:59 pm

FTP
Download FileZilla Server and install.
Then forward Port 21 (FTP port) to your PC.

If you need to use FTPS, then you will also have to forward ports 989 and 990.

Code: Select all

989	TCP	UDP	FTPS Protocol (data): FTP over TLS/SSL
990	TCP	UDP	FTPS Protocol (control): FTP over TLS/SSL
web mail
Since webmail is operated through port 80 (Web Server), you don't need to do port forwarding for this.
However, you will have to find a mail server such as MDaemon. See http://www.altn.com/ for their products. They offer a free version for home users. See http://www.altn.com/Products/Free-Windows-Mail-Server/.

Hope that helps !
User avatar
Kevin
Sergeant Major
Sergeant Major
Posts: 40
Joined: Sun Jul 19, 2009 7:49 pm
Location: Sydney

Re: How to access website hosted in localhost from internet

Post by Kevin » Sat Dec 25, 2010 2:09 pm

thegtaguy
Corporal
Corporal
Posts: 9
Joined: Fri Dec 17, 2010 8:48 pm

Re: How to access website hosted in localhost from internet

Post by thegtaguy » Sat Dec 25, 2010 10:07 pm

Neo wrote:
FTP
Download FileZilla Server and install.
Then forward Port 21 (FTP port) to your PC.

If you need to use FTPS, then you will also have to forward ports 989 and 990.

Code: Select all

989	TCP	UDP	FTPS Protocol (data): FTP over TLS/SSL
990	TCP	UDP	FTPS Protocol (control): FTP over TLS/SSL
web mail
Since webmail is operated through port 80 (Web Server), you don't need to do port forwarding for this.
However, you will have to find a mail server such as MDaemon. See http://www.altn.com/ for their products. They offer a free version for home users. See http://www.altn.com/Products/Free-Windows-Mail-Server/.

Hope that helps !
Okay ,
I have downloaded FileZilla Server.
I have to use NAT to port forward.
So i entered a new entry :

Code: Select all

Name "FileZilla"
IP "192.168.1.11"
Input Port "21"
Output "21"
Connection Type "TCP"
Are the Above Settings Correct or do i need to modify something ?
Post Reply

Return to “Web programming”