Last week in Web Development Basics: Part 1, I explained what the kinds of tools required to begin developing websites that can respond to a user action. This week the topic is how to set up a web server on your computer so your computer can execute programs and scripts as though it was a live website.
The software we will use is XAMPP which is Apache, MySQL, PHP and Perl is a nice little bundle for you; it is relatively easy to install. This example will be installing XAMPP on a Windows Machine, but using the link provided you can download the same software for multiple Operating Systems.
Step 1. Download XAMPP and open the file.
The installer will now ask you where you want install the web server; choose a location then click install
Step 2. When the installation completes setup will run automatically
First prompt asks if you want a desktop shortcut – always handy, press y for yes and n for know and hit return to confim.
If you get the following prompt do not panic just press y hit return
The third prompt asks if you want XAMPP to be portable; this is useful for storing it on a flash drive or media you intend to carry around and use on multiple machines. If you will be using only the installation on one machine for web development you can press n and continue .
Then XAMPP will configure itself and all you have to do is hit return:
It will then configure the timezones – it should hopefully get this right (if not I will show you how to correct this after the install is complete).
Finally you will be prompted with a number of options that you can use to start XAMPP
Right now we are only interested in starting the server and to do this we will have to access the XAMPP Control Panel (there should be a shortcut on your desktop by now but we want to feel manly/womanly right now and do things through the command-line), press 1 and then press return. The XAMPP control panel looks like this:
Our first task after starting up XAMPP control panel is to start the Apache and Mysql web services, we do this by clicking the start buttons next to the words Apache & MySql under the word modules. Now XAMPP should look like the screenshot below.
Now the server is running it’s time to get it to execute some code. The web server specifies the folder where the website or application will be served from this is in the htdocs folder of where you installed XAMPP; a shortcut is to click the Explore button in the XAMPP control panel:
Inside the htdocs folder create a new folder and name it “test”
Inside the test folder right click and go to the New option and select Text Document rename the document index.php (make sure you get rid of the .txt extention)
Open this document in Notepad and insert the following (this is simple PHP code to check if the server works)
The echo command puts things on the screen, the server will not print anything on the webpage unless explicitly asked to do so. The 1st example simply places the text hello world on the page the 2nd adds 2 numbers together and prints the total on the webpage for people to see.
This is the complete page the web server has placed the text hello world on the page and added the numbers 1 + 5 to get 6 and then printed 6 on the page, so web servers generate a page based on the commands within the page. This allows us to output a different page depending on what the user does or what the user needs.
Changing the timezone in php
If during setup php guessed the time wrong, you can rectify this by navigating to your xampp installation then to the php folder; open the php.ini file(in notepad or other program). Around line 1015 you should see
Replace the timezone (seen here as Europe/London) with any of the timezones below
NOTE: it is very important that the timezone you choose is in “quotes”.
That concludes Part 2. The next article will be about the PHP programming language and how it works with a web server.