Open In App

How to run PHP programs ?

Last Updated : 06 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

XAMPP is a Web development tool, created by Apache, that makes it easy to run PHP (Personal Home Pages) scripts on your computer locally. Installation of XAMPP Server on windows is easy as compared to manual installation of a web server and PHP required a lot of in-depth configuration knowledge. XAMPP package installs MySQL, FileZilla, Mercury, Perl, and Tomcat along with Web Server and PHP, with these applications you can test the full website on your desktop. You don’t need to upload it every time on an online Web server.

Step 1: First of all, open the Apache Friends website and download XAMPP for Windows, and install it.

Step 2: Start the XAMPP Program Control Panel. Click on the “Start”  button next to the “Apache” to start your Apache Web Server. Also, start “MySQL” if your PHP programs depend on a MySQL database to run.

How to run PHP programs ?

How to run PHP programs ?

Step 3: Place your PHP files in the “htdocs” folder located under the “XAMPP” folder on your drive (i.e. C/D/E etc). The initial path is “your_drive_letter:\xampp\htdocs” for your Web server. Make sure that your PHP files are saved as a “.php” file extension.

Example: The “demo.php” file is saved in the htdocs folder.

PHP




<!DOCTYPE html>
 
<html>
<body>
  <h1>Hello GFG </h1>
 
  <?php
    echo "Hello geeksforgeeks";
  ?>
</body>
</html>


How to run PHP programs ?

How to run PHP programs ?

Step 4: Open up any web browser and enter “localhost/filename”. This will open the list of all the files and folders stored under the “htdocs” folder on your computer. Click on the link to a PHP file and open it to run a program.

Example: The file “demo.php” file is placed inside the “htdocs” folder. If you want to run it, open any web browser and enter “localhost/demo.php” and press enter. Your program will run.

Syntax: php have special Syntax to write a code, as shown in below 

<?php   
//write your code here  
?>  

demo.php

PHP




<!DOCTYPE html>
<html>
 
<body>
 
  <h1>Hello GFG </h1>
 
  <?php
    echo "Inside gfgdemo FOLDER Hello geeksforgeeks";
   ?>
 
</body>
</html>


How to run PHP programs ?

How to run PHP programs ?

Step 5: You can create any folder to test PHP files under the “htdocs” folder. If you create a specific folder then you need to use the address as “localhost/foldername” to open them in your browser.

Example: The “demo.php” file is placed inside the “gfgdemo” folder. Enter “localhost/gfgdemo/demo.php” in your browser and press enter, your program will be run.

How to run PHP programs ?

How to run PHP programs ?

PHP case sensitivity

PHP is case sensitive language, in that variables and functions, tags are case sensitive but classes are not case sensitive. Below the example of case sensitivity of php. 

Example 1: echo.php

PHP




<!DOCTYPE>
  <html>     
  <body>        
   
  <?php            
  echo "Hello world using echo </br>";             
  ECHO "Hello world using ECHO </br>";           
  EcHo "Hello world using EcHo </br>";        
  ?>     
  </body> 
  </html> 


In above code we write three different types of echo methods, see the output in the image. 

Output:

How to run PHP programs?

Example 2: color.php

PHP




<html>     
  <body>        
  <?php             
  $color = "black";            
   echo "My car is ". $ColoR ."</br>";           
   echo "My dog is ". $color ."</br>";             
   echo "My Phone is ". $COLOR ."</br>";        
   ?>    
  </body> 
  </html> 


In the above example, the variable name is case sensitive, so it gives error.

Output:

My car is 
My dog is black
My Phone is 

PHP Notice:  Undefined variable: ColoR in HelloWorld.php on line 3
PHP Notice:  Undefined variable: COLOR in HelloWorld.php on line 5


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads