How do i run a php script?

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 do i run a php script?

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

  

Hello GFG

  

    echo "Hello geeksforgeeks";

  ?>

How do i run a php script?

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 


//write your code here  
?>  

demo.php

PHP

  

Hello GFG

  

    echo "Inside gfgdemo FOLDER Hello geeksforgeeks";

   ?>

How do i run a php script?

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 do i run a php script?

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

       

          

  

  echo "Hello world using echo
"
;             

  ECHO "Hello world using ECHO
"
;           

  EcHo "Hello world using EcHo
"
;        

  ?>     

   

   

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

Output:

How do i run a php script?

How to run PHP programs?

Example 2: color.php

PHP

     

          

  

  $color = "black";            

   echo "My car is ". $ColoR ."
"
;           

   echo "My dog is ". $color ."
"
;             

   echo "My Phone is ". $COLOR ."
"
;        

   ?>    

   

   

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

Can I run PHP script from command line?

A PHP script can be executed from the command line even without having any web server software installed. To run the PHP script from the command line you should just have a PHP CLI (PHP Command Line Interface) installed on your system.

What do you need to run PHP code?

To run PHP code, you need the following three software on your local machine: Web Server (e.g., Apache) PHP (Interpreter) MySQL Databases (optional)

How do I run PHP on my browser?

Click the button Open In Browser on StatusBar..
In the editor, right click on the file and click in context menu Open PHP/HTML/JS In Browser..
Use keybindings Shift + F6 to open more faster (can be changed in menu File -> Preferences -> Keyboard Shortcuts ).

How do I run a PHP file on Windows 10?

How to Install PHP.
Step 1: Download the PHP files. You'll need the PHP Windows installer. ... .
Step 2: Extract the files. ... .
Step 3: Configure php. ... .
Step 4: Add C:\php to the path environment variable. ... .
Step 5: Configure PHP as an Apache module. ... .
Step 6: Test a PHP file..