Your Ad Here

Tuesday, May 3, 2011

Run First PHP Program

In my first article I show you how install  PHP , mysql, apache.Now we see how write a php program.
First create your working folder.
Create folder for your project in your machine.Ex :- I created project folder in D  Drive naming by test.com.
then you must create a VirtualHost in your machine.open Run from your start menu.
Then write drivers to go to drivers folder in windows system32 file

Then open etc folder ,


Then open hosts file in Notpad.

then create host for local machine in bottom of the page.
Ex :-  127.0.0.1 local.test.com
then save it.
then open your apache configuration document.
Start ->   All Programs -> Apache HTTP Server 2.2 ->Configure Apache Server->Edit the Apache httpd.conf Configuration File




First Change DocumentRoot it is appear like this way
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
you must comment it using # ....change it like this by mapping  your project folder
#DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
Redirect it to
DocumentRoot "D:/Projects/test.com"
Now change Directory tag. It is appear like this way
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
Now you must comment it using # .... and  change it like this by mapping  your project folder
#<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
Redirect it to
<Directory "D:/Projects/test.com">


Then your going to create VirtualHost .In bottom of the page add your working folder and your virtual host that created above.
Ex :-
             <VirtualHost 127.0.0.1:80>
             DocumentRoot D:\Projects\test.com
             ServerName local.test.com
           </VirtualHost>



Then last you must restart apace server .

Now you ready to run your first php web page.

Now first get notpad from your start menu.We are going to preview "This is my first Program" in your first php web page.In top of the notpad put Less Than ( < ) ,question mark and php together

Ex : - <?php 


this is the way we start a php program .
And next line is print line.write echo. this is how we print a string in a php page.
then put " and write our sentence This is my first Program  then again put " and for end the print statement put semicolon ( ; ) .

Ex :- echo "This is my first Program";


and to end the php page put question mark and Greater Than( > ) mark.

Ex : - ?>


then save it in your project folder and run it in you web browser  by giving your host local.test.com and page  name.


OK now you run your first php program. Now try print strings with some HTML tags 


Ex :-  echo "<b>This is my first Program</b><br/>";
         echo "<h1>This is my first Program</h1><br/>";
         echo "<i>This is my first Program</i><br/>";    ......etc .

Enjoy with your PHP programs .

No comments:

Post a Comment