How to Run PHP Programs in XAMPP Example?

03-Apr-2023

.

Admin

How to Run PHP Programs in XAMPP Example?

Hi Guys,

How to run PHP programs in XAMPP PHP is a popular backend programming language. PHP programs can be written on any editor, such as - Notepad, Notepad++, Dreamweaver, etc. These programs save with .php extension, i.e., filename.php inside the htdocs folder.

Generally, a PHP file contains HTML tags and some PHP scripting code.

It is very easy to create a simple PHP example.

To do so, create a file and write HTML tags + PHP code and save this file with .php extension.

As I'm using window, and my XAMPP server is installed in D drive. So, the path for the htdocs directory will be "D:\xampp\htdocs".

PHP program runs on a web browser such as - Chrome, Internet Explorer, Firefox, etc. Below some steps are given to run the PHP programs.

Let's start example following command.

Step 1 : Create a simple PHP program like hello world.


<?php

echo "Hello World!";

?>

Step 2 : Save the file with hello.php name in the htdocs folder, which resides inside the xampp folder.

Note: PHP program must be saved in the htdocs folder, which resides inside the xampp folder, where you installed the XAMPP. Otherwise it will generate an error - Object not found.

Step 3 : Run the XAMPP server and start the Apache and MySQL.

Step 4 : Now, open the web browser and type localhost http://localhost/hello.php on your browser window.

Step 5 : The output for the above hello.php program will be shown as the screenshot below:

Output :

#PHP