This will be quite a short post where will be taking the site we have built so far, putting it where Apache can find and serving it. If you have come here looking to install your first Apache server, then have a look at this post first.
What is Local host?
How does Apache find sites? First, will get our browser putting in a request for a site to the Apache server. We did this at the end of the previous tutorial by typing the following in the address bar:
We know that this gets us to the Apache test page, so we know we are in the right place, but what exactly is happening?
The above URL’s both tell the browser the same thing, that the server we are going to get our site from is hosted within the operating system that the browser is running in. This as known as the local host, hence the name. The numerical representation, 127.0.0.1 is, technically, the correct representation of the local host; the text ‘localhost’ is used to be a bit more user friendly. Either can be used, and both are as universally accepted as the each other.
Where do I put the Site?
So now we know how to point the browser to the correct server, how do we fetch the site we want? There are two things we need to do here – first, we need to put the site somewhere the server can find it, and then we need the browser to ask for the site from that location. So lets start with the first thing first.
If you have been following the tutorials, or got the tutorial’s site from github, the site will be contained in a folder. You can call this folder what you want, I’ve called mine ‘my_site’. Make a copy of the folder. We want to put this in our XAMPP directory – you will find this in your computer’s root directory – look for the folder called ‘xampp’, funnily enough. Double click the xampp directory, and you will see a lot of folders and files. We are looking for the ‘htdocs’ folder.
Double click into ‘htdocs’, and you will see a few more folders and files. This is where Apache looks when it has received a request for a page, so this is where we need to put our site folder. Paste your folder here.
Request our Site
The next step is to request our site. So go back to your browser, and type in the following:
If you have called your site something else, then replace ‘my_site’ with your name.
Refresh your browser page and you should now see your ‘brilliant’ site :) And this is how you can serve a number of sites from your server. Any time you want to start a new site, you put a new folder in the ‘htdocs’ folder.
…We will be putting together our first PHP script. I may have said this at the end of the last tutorial too, but I promise I will get to this next time! I’m sure you are raring to get going on scripting, and we will do next time. Until then, code your face off.