PHP Run First Program -

PHP Run First Program

How to Run PHP Programs on XAMPP

Follow these steps to write and run PHP programs using XAMPP.

Step 1: Write and Save the Program

  1. Write the PHP Program:
  • Use any text editor (like Notepad, Sublime Text, or VS Code) to write your PHP code. For example, create a simple PHP file with the following code: <?php $var = "Hello World!"; echo $var; ?>
  1. Save the File in XAMPP’s htdocs Directory:
  • Save the file inside the htdocs folder of your XAMPP installation directory (e.g., C:/xampp/htdocs).
  • You can create a new directory within htdocs for better organization. For example, create a folder named test and save the file as test.php: Path Example: C:/xampp/htdocs/test/test.php

Step 2: Open XAMPP Control Panel

  1. Open the XAMPP Control Panel:
  • Go to the XAMPP Control Panel and start the Apache server by clicking the “Start” button.
  • If your program needs a database connection, start MySQL as well.

Step 3: Open Your Browser

  1. Open Your Browser:
  • Open any browser (e.g., Chrome, Firefox) and type localhost in the address bar, then press Enter.
  • You can also use the “Admin” button next to Apache or MySQL in the XAMPP Control Panel to open the browser.

Step 4: Locate and Run the PHP File

  1. Navigate to Your File:
  • After typing localhost in the browser, remove the dashboard URL from the address bar and type the path where your PHP file is saved.
  • For example, if your file is saved at C:/xampp/htdocs/test/test.php, type the following URL in your browser: http://localhost/test/test.php
  1. Press Enter:
  • After pressing Enter, you should see the output of your PHP program.

Output

When you run the above example, you will see the following output in your browser:

Hello World!

This confirms that your PHP environment is set up correctly and your script is running on XAMPP!

Leave a Comment