Writing your first PHP script
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.

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.

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.
1 2 3 4 5 6 7 8 9 10 | <html>
<head>
<title>My First PHP Page</title>
</head>
</body>
<?php
print ('Hello. How do you find PHP so far?');
?>
</body>
</html> |
After this, execute the page by going to http://localhost/hello.php in your browser. You should get something like this.

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.
1 2 3 | <?php /* put your PHP script between these delimiters */ ?> |
Line 7 is where the PHP code is.
1 2 3 | <?php print ('Hello. How do you find PHP so far?'); ?> |
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.
In: PHP Tutorials · Tagged with: PHP, sample codes, source code

Permalink
A Good One.
Permalink
Thanks, this was useful.
Permalink
wew ! this is good for newbie…
webmaster, do you want put my link in this blog ?
bramzzz.blogspot.com
and i will put your link in my blog.
tq
Permalink
was very useful to start with php coding.
thanks
Permalink
thanks for giving this informatin it very usefull.
Permalink
Yes a very good tutorial….thanks a ton…
Permalink
Good intro to PHP. Thanks!
Permalink
Nice Information..
Thanks Alot…
Permalink
thanks! i didn’t know how to run php with xampp lite and this tutorial really worked here.
Permalink
thanx,,,,,,
it help me to run php
Permalink
Hello there
Can I ask ..
How to use only <?
instead of <?php.
Best Regard,
Luckman R thank you
Permalink
@Luckman
By default, your PHP install should support the short tag. If it does not, you can enable it in by changing the short_open_tag value in php.ini.
For more information, see the description for ’short_open_tag’ at this page http://php.net/manual/en/ini.core.php
Permalink
thanx man,for past 2 days i m searching for how i run my php pogram and you just solve my problem.
Permalink
How can I make the documentation of an WEBSITE running in PHP?
Permalink
Thanks man, very helpful. By the way, line five of the code has a typo in it!
Permalink
thanks…… a lot…
Permalink
thnx… keep it up…
Permalink
i would like to change my script placing path such like…
lets say i create a scripting name it as start.php and this script is inside a folder name “project” can i put my directory in “C:\xampp\project”, if can, then did i need to setup a httpd.conf?
Permalink
thax a lot to askaboutphp…..very useful
Permalink
Thanx for dis…it really helped me out!!!!!
Permalink
hello
the date function doesn’t works in my php. it doesn’t return any value please help me. i have tried all the syntax.
Permalink
please tell me how to load the list of items from mysql table to php combobox?