Loopback 127.0.0.1 and how it pulls up xampp

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Loopback 127.0.0.1 and how it pulls up xampp

Postby waveform » 06. March 2015 09:58

I'm trying to visually understand something.

When I type the Loopback address 127.0.0.1 my browser, the browser points to http://127.0.0.1/xampp/ (as long as XAMPP is running)
I guess what I'm not able to visualize is, how does my browers know that it's suppose to loop itself to the XAMPP Apache server application? I know XAMPP's httpd.conf file contains the instructions responsible for directing the browser to pull up the XAMPP welcome page. But how does the loopback address on a local machine know to follow the commands in the httpd.conf file specifically? For example: What if I was running two servers each with their own config files on the same machine. How would the loopback address know which application server to listen to over the other?
User avatar
waveform
 
Posts: 5
Joined: 18. August 2013 19:54
Operating System: Win XP-win7 Debian 7.8

Re: Loopback 127.0.0.1 and how it pulls up xampp

Postby Altrea » 06. March 2015 15:41

Your Apache listens on a unique specific port. So if you Start two different Apache both need to listen on their own port. Thats how your OS can address a request to The correct process
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Loopback 127.0.0.1 and how it pulls up xampp

Postby Nobbie » 06. March 2015 20:28

waveform wrote:I know XAMPP's httpd.conf file contains the instructions responsible for directing the browser to pull up the XAMPP welcome page.


No. If you enter localhost or 127.0.0.1, a TCPIP request is send to your local machine. Apache is listening and the browser already "cuts" the request into pieces, finally Apache is requested to deliver "/", nothing else. In httpd.conf the "DocumentRoot" tells Apache, what is meant by "/". So Apache delivers that DocumentRoot. At next, there is a file name missing, in that case the configuration of "DirectoryIndex" tells Apache, what to deliver for a folder (because "/" is only a folder, not a file), in this case it this file called "index.php". This file is coded with very simple PHP and in this file there is a redirection to the folder "xampp". This finally leads to the Xampp Welcome Page - but this is not configured in httpd.conf.

waveform wrote:For example: What if I was running two servers each with their own config files on the same machine.


You cannot run two servers on the same server using the same port - if you do not specify a Port in your URL, automatically Port 80 is taken for HTTP. This is one of most common problem here in the Xampp Forum, why does my Apache not run? It is due to the fact, that there is already a software running on localhost listening to Port 80.

But after the explanation above you should understand, how the Xampp Welcome Page is delivered - it is by far not only Apache and not only httpd.conf, which is responsible.
Nobbie
 
Posts: 13179
Joined: 09. March 2008 13:04

Re: Loopback 127.0.0.1 and how it pulls up xampp

Postby waveform » 06. March 2015 23:46

Thanks to the both of you for responding.

@ nobbie.
That was a good break down of the process. I appreciate that.
I knew about the DirectoryIndex paths in the config, I written some very basic PHP and tested a few forms following my books.
I think the ambiguous question I was asking maybe related more to the browser's behavior. I wasn't sure or clear on how I wanted to ask the question. Sorry. But it seems like you knew what I was after. Thanks

To confirm I'm following what you said:
I know the server listens. So would it be safe to say that when I type in the loopback address, the browser goes out and looks for any available server on the local machine? So it's standard behavior for a browser to send the loopback request to (any available) server on the local machine, (on port 80 default) while the server just stands by and waits for something to contact it? So then also, when you link a PHP file to your (x)html document, it's the actual browser that's sending the request to the server. So then the server is not looking for anything, it's just waiting for something to be sent to it? So it's the browser that's doing all the sending at first.

I think what confused me with regard to the question above was, why the XAMPP start page was coming up when I would type localhost in my browser. I thought the 'htdocs' directory was loaded by default, ...and I have my own index files in there. But it's the 'xampp' sub folder contained with-in 'htdocs' that's actually loaded when localhost is typed in the browser.
C:\xampp\htdocs\xampp
To load your own index, you actually have to go up one level to htdocs. The 'xampp' folder must be hard coded into the server. I know the server root is 'apache' but why the server defaults to the xampp sub folder mixed me up. I thought all html and php documents were set to load from 'htdocs'. Anyway.


On a side note. Last night I was trying to find XAMPP's built in xhtml or php start up page files in:
C:\xampp\htdocs\xampp

I could not find them. I wonder if it's coded into the server somewhere.
User avatar
waveform
 
Posts: 5
Joined: 18. August 2013 19:54
Operating System: Win XP-win7 Debian 7.8

Re: Loopback 127.0.0.1 and how it pulls up xampp

Postby Altrea » 07. March 2015 00:59

waveform wrote:So would it be safe to say that when I type in the loopback address, the browser goes out and looks for any available server on the local machine? So it's standard behavior for a browser to send the loopback request to (any available) server on the local machine, (on port 80 default)

Not really. The browser just fires a request. For the browser it is not important if the request is send to an loopback address or for example an internet server.
All the magic routing is done in the operating system itself (network interface, DNS (if the name needs to get resolved)).

waveform wrote:I thought the 'htdocs' directory was loaded by default

Which is correct

waveform wrote:But it's the 'xampp' sub folder contained with-in 'htdocs' that's actually loaded when localhost is typed in the browser.
C:\xampp\htdocs\xampp

Nobbie already told you why this is happening.

waveform wrote:To load your own index, you actually have to go up one level to htdocs.

No.

waveform wrote:The 'xampp' folder must be hard coded into the server.

No.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Loopback 127.0.0.1 and how it pulls up xampp

Postby waveform » 07. March 2015 06:02

Firstly, Sorry to be a pain in the tail. I'm just trying to make sure i"m clear on these basic fundamental principals.
I appreciate you two taking the time to explain what you have. I think I've got it!

Altrea wrote:.... The browser just fires a request.
...All the magic routing is done in the operating system itself (network interface, DNS (if the name needs to get resolved).


You said: "All the magic routing is done in the operating system itself." This is the root of my question.

So is it safe to say that the TCP/IP protocol in windows/Linux is responsible for taking the loopback 127.0.0.1 address and pointing it to port 80 which I'm assuming Apache server is set to listen to? This is I think what you both are trying to explain to me.

Nobbie wrote:....in this case it this file called "index.php". This file is coded with very simple PHP and in this file there is a redirection to the folder "xampp". This finally leads to the Xampp Welcome Page - but this is not configured in httpd.conf.


This I understand. I didn't realize there was a php file with redirection code .But even so, I looked in htdocs/xampp for both html, and php files with the welcome text and didn't find the one with the "Congratulations, XAMPP is working" text. And the root xampp folder at C/xampp only has .bat, and ini files, so it would have to be located in htdocs/xampp.
User avatar
waveform
 
Posts: 5
Joined: 18. August 2013 19:54
Operating System: Win XP-win7 Debian 7.8

Re: Loopback 127.0.0.1 and how it pulls up xampp

Postby Nobbie » 07. March 2015 13:29

waveform wrote:This I understand. I didn't realize there was a php file with redirection code .But even so, I looked in htdocs/xampp for both html, and php files with the welcome text and didn't find the one with the "Congratulations, XAMPP is working" text. And the root xampp folder at C/xampp only has .bat, and ini files, so it would have to be located in htdocs/xampp.


Its a bit complicated, i am honest, i did no research on how Xampp devlivers the Congratulation text, but think about the fact that it might be a PHP Script (i.e. c:/xampp/htdocs/xampp/index.php - formerly it has been c:/xampp/xampp/index.php - without htdocs between and realized via ALIAS configuration) and this script does not(!) necessarily contain all strings, which are echoed. There may be a configuration file (lets say strings.php) which is somewhere beyond the Xampp folder and is included on runtime by PHP. In some sophisticated environments (like WordPress or Joomla) you even wont find any file containing messages and strings - these are stored in a MySQL Database and put together on runtime by PHP.

All you have to know is the fact that: if you enter localhost or 127.0.0.1 in your browser, a TCPIP request is issued to that domain or IP, and 127.0.0.1 yields to your local PC (the browser does not know about that, he is stupid, he simply sends a request and waits for an answer), the Apache (Xampp) receives that request, "DocumentRoot" and "DirectoryIndex" tells him, which file to deliver (c:/xampp/htdocs is DocumentRoot and DirectoryIndex yields to index.php), so Apache *should* deliver index.php, BUT a file with extension PHP receives special treatement by Apache, it is NOT delivered directly back to the browser, instead it is send (like a stream, or a pipe as it is called on linux systems) to the PHP Interpreter, PHP parses and executes the code and finally the output of this script is passed back to the browser.

So Apache does not know that there is a xampp subfolder in htdocs, this is coded in the PHP Script, which tells the browser to send another request to the same server (again your Apache) in order to request 127.0.0.1/xampp/index.php and last not least then the output of this script ends the whole transaction and the user sees the welcome page.

P.S.: On some systems there is an index.html in the htdocs folder which contains "It works" (not "Xampp is working"); maybe you are mixing up these things? If there is no index.php or if DirectoryIndex is configured differently or if index.html is explicitely given in the URL, you will receive this message. It is the standard Welcome message if you install Apache NOT from Xampp, but manually from apache.com
Nobbie
 
Posts: 13179
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 259 guests

cron