PHP Tutorial
Control Statement
PHP Programs
PHP Functions
PHP Arrays
PHP Strings
PHP Math
PHP Form
PHP Include
State Management
PHP File

How to run PHP code in XAMPP

To run PHP code in XAMPP, you’ll need to follow these steps:

1. Install XAMPP: If you haven’t already installed XAMPP, download it from the Apache Friends website (https://www.apachefriends.org/index.html) and follow the installation instructions for your operating system.

2. Start Apache and MySQL: After installing XAMPP, start the Apache server and MySQL database from the XAMPP Control Panel. You can do this by launching the XAMPP Control Panel and clicking on the “Start” buttons next to Apache and MySQL.

3. Create a PHP File: First, navigate to the htdocs folder within your XAMPP installation directory (e.g., C:\xampp\htdocs or D:\xampp\htdocs if you installed XAMPP on a different drive). Create a new folder for your project (e.g., demo) and inside this folder, create a new text file named index.php.

4. Write Your PHP Code: Open the index.php file in a text editor and write your PHP code. A simple PHP script might look like this:

				
					<?php
echo "Hello, World!";
?>
				
			

Note: Remember to save the file with a .php extension.

5. Access Your PHP Script: Open your web browser and type localhost/demo/index.php in the address bar (replace demo with the name of your project folder if you named it differently). Press Enter to execute the script. You should see the output of your PHP code displayed in the browser.

By following these steps, you have successfully created and executed a PHP file using XAMPP. This process allows you to develop and test PHP applications locally before deploying them to a live server.

Scroll to Top