How to Run a PHP File in XAMPP: 5 Easy Steps

Reading time icon 4 min. read


Readers help support Windows Report. We may get a commission if you buy through our links. Tooltip Icon

Read our disclosure page to find out how can you help Windows Report sustain the editorial team. Read more

Run a PHP Files in XAMPP
Try Opera One, a browser with unlimited functionalities already integrated.A remarkable browser like Opera One has maximum capabilities already underneath the hood.Here's what Opera One covers through default:
  • An incredible AI Service accessible directly in the sidebar
  • Ad-blocker mode integrated to load pages quicker
  • Modular browser, multithreaded, and intuitive tab navigation
  • Battery saver mode
  • ⇒ Get Opera One

Running PHP files locally can be a breeze with XAMPP. If you’re new to this, don’t worry, we’ll guide you through the process step-by-step. Let’s dive into how to run a PHP file in XAMPP quickly and easily.

How do I run a PHP file using XAMPP?

1. Installing XAMPP

  1. Visit the official XAMPP website and download the appropriate version for your operating system (Windows, macOS, or Linux).
  2. Open the downloaded installer file. Follow the installation instructions, selecting the required components, including Apache, MySQL, PHP, and phpMyAdmin.
  3. Select the directory where you want to install XAMPP. The default directory is usually C:\xampp.
  4. Click Next and complete the installation process.

Installing XAMPP sets up a local web server environment, allowing you to run and test PHP scripts on your machine without needing an external web server.

2. Starting XAMPP and Apache

  1. Locate and open the XAMPP control panel (on Windows, search for XAMPP Control Panel in the Start menu).
  2. In the control panel, click the Start button next to Apache and MySQL. Ensure that the modules turn green, indicating they are running.

3. Creating and saving a PHP File

  1. Open a text editor such as Notepad, Notepad++, or any Integrated Development Environment (IDE) of your choice.
  2. Write your PHP script. For example, type the following code: <?php echo "Hello, this is PHP."; ?>
  3. Save the file with a .php extension. For instance, save it as index.php.
  4. Copy or move the saved PHP file to the htdocs directory inside the XAMPP installation folder (e.g., C:\xampp\htdocs).

Saving your PHP file in the htdocs directory is important because this directory is the root folder for your local server, enabling the server to locate and run your scripts.

4. Running the PHP file in a browser

  1. Open any web browser such as Opera.
  2. In the address bar, type the following URL: http://localhost/index.php
  3. Replace index.php with your file name if different and press Enter.
  4. If everything is set up correctly, you should see the output of your PHP script in the browser.

Running your PHP file through the browser ensures that the PHP code is executed on the server side and the result is displayed on the client side.

5. Using phpMyAdmin with XAMPP

  1. Ensure MySQL is running in the XAMPP control panel.
  2. Open your web browser and navigate to http://localhost/phpmyadmin/
  3. Use the default credentials (usually username: root, password: blank) to log in.
  4. Click on the Import tab, browse and select your SQL file, then click Go to execute the SQL commands.

Using phpMyAdmin provides a graphical interface for managing your MySQL databases, making it easier to perform database operations without needing to write SQL commands manually.

Additional tips and troubleshooting

  • Always verify that Apache and MySQL are running from the XAMPP control panel.
  • If you encounter issues loading your PHP files, try accessing http://localhost in Incognito mode to avoid browser cache problems.
  • Create separate folders inside htdocs for different projects. Access these folders through http://localhost/your_project_folder/index.php

These additional tips help ensure a smoother development experience and resolve common issues encountered while running PHP files using XAMPP.

By following these steps, you can install, set up, and run PHP files using XAMPP, making local web development easier and more efficient. Always keep your XAMPP updated and regularly back up your projects to prevent data loss.

If you want to handle the files differently, here’s our list of the best software to open PHP files on Windows.

Did you find our guide on how to run a PHP file in XAMPP useful? Let us know in the comments below.

More about the topics: Programming tools and tips, web app, website

User forum

0 messages