In this chapter we will write our first PHP Hello world program. Go ahead and type the following code ( you can also copy paste) in your favorite text editor ( we suggest notepad++ that supports sytax highlighting.)

echo "Hello World";
Name the file index.php. A PHP file ends with a .php extension.

Save the file in the diretory C:\www\ in your windows machine. Now open the browser and browse to C:\\localhost\index.php. You should get a display that says "Hello World".

Congratulations - you have just run your first php programe.

If you have taken a commercial server, transfer this files using ftp server in a directory of your server for example in the subdirectory whereyousavedfile of your server at If you open you sould see "Hello Word" on your browser.

This program does not do anything dramatic. In fact, you could have achieved that same result by writing simple HTML code. There was no need to write the PHP code here.

However, PHP can be programmed at the server side. We will develop some more code in the next few pages before you will be able to realize the benefits of PHP.

A thing about php syntax in this program. The PHP codes start with <?php and ends with ?>In between these two tags we write some codes. These codes are not seen by a browser. These codes do not run on user machine. This code run on server machine. When the user opens index.php the html codes are visible to the user and its machine. When the php code starts the server takes control and gives to the user machine what it wants. In this case the echo statement sends out something to display on the client machine.

echo is a PHP language construct that output one or more strings. It will be used extensively in our tutorial in the next few pages. Also you can see that a .PHP file has html and php code mixed up. Anything that is not between the <?php and ?> tags are treated as if they are part of the HTML.

Simple exercize

1. Try displaying a message different from "Hello World". For example write - "I started learning PHP from".

2. Instead of saving the file and index.php save the file as tutorial1.php. Check by browsing to the location localhost/tutorial1.php

3. Introduce an error by writing something like
echos "Hello World";  

in place of

echos "Hello World";  
And see what happens. Fix the error and recheck.

In the next few chapters we will develop some common programming constructs for PHP. We will start with something very simple - Introducing comments in PHP.