accessing web server locally by different ways

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mfaisalwarraich
    New Member
    • Oct 2007
    • 194

    #1

    accessing web server locally by different ways

    I have a very basic question about accessing PHP Web Server (apache) locally by different ways. These ways can be:

    localhost
    127.0.0.1
    IP address of the computer
    name of the computer


    Which option is best and why? Why all these are used? and what is the important of each of them?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    localhost is just an alias for 127.0.0.1, which is an IP that targets the computer you are on.

    The IP address of the computer can vary. It can either be:
    • an internal address (usually in the range 192.168.x.x) which is automatically assigned by a DHCP server (usually a router), or manually set on each computer (not recommended!).
    • and external address, assigned by an ISP.


    The name of the computer is also just an alias for an IP address. DNS servers assign domain names to IP addresses (google.com, bytes.com) so that you do not have to enter the entire IP when you want to visit a site. - Routers on internal networks do the same thing. When your computer is assigned an IP on a local network, the name of your computer is registered with the router and assigned to your given IP address. - When somebody on your network types a name in a browser, his/her browser sends a request to the router asking what IP that name represents. If it is a local name (e.g. "john-doe", "me.lan") the router sends back the network IP registered for that name. If it is an external domain (e.g. "google.com ", "bytes.com" ) then the router forwards your request to your ISP's DNS server, which replies with the IP for that domain name.

    As to which is best to use, that depends on what you are doing.
    • If you are just connecting to a local service, like a Apache HTTP server on your own computer, using either "localhost" or "127.0.0.1" is fine. They are pretty much equal, so it doesn't really matter which you use. (The IP *may* be slightly better, since it is the OSs responsibility to assign "localhost" to the IP, and certain OSs *cough*Vista*co ugh* have been known to muck that up.)
    • If you are connecting to a computer on the network, the computer's name may be better than using the network IP, since DHCP servers don't always assign the same IP address to the same device.
    • For external connections, it's generally better to us an IP than a domain name. It removes the need to request the IP from the DNS servers. - The downside to that is that domain names can change locations, and can even be dynamically rotated based on various factors. (For example, when you connect to Facebook, you are not always connecting to the same server. You are often re-routed to a server that is less loaded or geographically closer to you.) - However, if it is a *normal* domain name that statically points to a single IP, fetching the IP once and using that is better than using the domain name itself.


    Hope that helps.

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Great answer, Atli :D

      Comment

      • mfaisalwarraich
        New Member
        • Oct 2007
        • 194

        #4
        very very helpful and excellent reply Atli. thanx alot

        Comment

        Working...