Wednesday, July 31, 2013

Create your first PHP file and run it in your computer using Xampp




Before starting PHP you have to install XAMPP Software in your computer. Otherwise the .php files won't run/open in your computer. You should also learn HTML and CSS properly to create PHP pages.
 Step 01  Install Xampp except C Drive
Install Xampp properly. But remember, installing xampp except C drive is the best way to keep your work safe. You may be bound to format your C drive in many cases, then your created files will be ruined.

 Step 02  Run Apache and MySQL to RUN a PHP File
After installing xampp, now run it and click on the Start Button of Apache as shown in the image below. Similarly run the MySQL by pressing the Start Button and minimize the control panel.

 Step 03  Now test the localhost service
As there is Xampp installed in your Computer System, so you computer is now a localhost and ready to test your PHP files. However, open a browser software like chrome or Firefox, type http://localhost/xampp into the address bar and press the Enter Key.

The home page of xampp will open. That means your PC is ready to work as a localhost.

 Step 04  Now create your first index page
Now go to the directory C:>xampp>htdocs and create a new folder. Name the folder as you like, for example: idhali. Go to the folder idhali, right click and open a new text document. Rename it with with the extension .php and the name should be index.php. Now open the file in a text editor like notepad, notepad++ or Sublime Text. Type This is my first PHP file and save that.

 Step 05  Check your index page
Type http://localhost/idhali into the address bar of a browser and hit the Enter Key. You will get the text you have typed before. So this is your first php document called index.php

 Step 06  First step of PHP coding
Now open your index.php page again with a text editor and type the following codes given below...

<html>
<head>
<title>iDhali</title>
</head>
<body>
<?php
$txt="visit www.iDhali.com";
echo $txt;
?>
</body>
</html>

Save the document and browse it again using the link http://localhost/iDhali. You will get the text Visit www.iDhali.com in your browser.

Finally, open the index.php page with a text editor again and make your index page using html, css etc.