Now that you know how to use XAMPP Lite, it’s time to write your first PHP script.

This tutorial will guide you on writing your first PHP script, show you how the PHP syntax is used, and where to put and run your PHP pages in XAMPP.

Note: this tutorial assumes you are using XAMPP Lite environment for your PHP scripts. If you want to setup your own XAMPP Lite environment, follow this tutorial about installing XAMPP Lite on a portable device.

Finding your Web Directory

Before you start writing, you need to locate your web directory. This is a special directory within your web server (in our case XAMPP Lite) where all the webpages are located.

When you type a URL into your browser, you are requesting for a file. This file has to be located within the web directory for the web server to deliver it to you. As such, if you have a PHP script, you need to put it into this web directory in order for it to be available to be browsed by your browser.

In our installation of XAMPP Lite, go to the your XAMPP Lite install directory. In that directory, you should see a folder called ‘htdocs’. This is your web directory.

XAMPP Web Directory

Open this directory, and you should see something like this, with some images files, a couple of folders, some image files, one HTML file and one PHP file. For the moment, just ignore them.

XAMPP htdocs directory

Create your PHP file

The next thing you need to do is to create a file within this web directory. So go ahead an do that, and name the file ‘hello.php’, and put the following source codes into the page.



My First PHP Page




After this, execute the page by going to http://localhost/hello.php in your browser. You should get something like this.

Browser Hello ouput

Well, congratulations, you’ve successfully run your first PHP page.

A Closer Look

So, what exactly happened? If you refer back to the source code, Lines 1-5 and 9, 10 are just your usual HTML tags.

Line 6, 7, 8 is where the PHP stuff is happening. Line 6 and 8 is the start and end delimiter that tells XAMPP web server where the PHP scripts starts and where it ends. This is refered to as a PHP processing block.

Line 7 is where the PHP code is.

In this case, it’s telling XAMPP to output the text ‘Hello. How do you find PHP so far?’.

So when you run the page at http://localhost/hello.php, that’s exactly what XAMPP does – print out the text.