How to Run a PHP File Using XAMPP

3 Min | October 09, 2024
Table of Contents

Before transferring your PHP application to a live server, you must develop and test it on a local host. A popular program called XAMPP makes this process simple and effective. 

By following this tutorial, you will be able to set up XAMPP and run your PHP files.

Table of Contents

What is XAMPP?

XAMPP is an open-source web server solution package developed by Apache Friends. On local web servers, it is mainly used for web application testing. XAMPP stands for:

  • X: Cross-platform
  • A: Apache Server
  • M: MariaDB (MySQL)
  • P: PHP
  • P: Perl

Why Use XAMPP?

XAMPP provides all the necessary tools to run PHP programs, including MySQL databases and Apache servers. It provides local application testing for developers before launching to a live server.

How to Install XAMPP on Windows Localhost?

Your PHP development journey on Windows requires a robust and stable local server environment. XAMPP, an open-source solution, that is highly recommended for developers. In this guide, XAMPP, ensure you’re well-equipped to dive into PHP development with ease. Let’s transform your Windows localhost into a powerful development playground!

Step 1: Download XAMPP

run a php file using xampp
  • Visit the ApacheFriend.org website and download XAMPP for your operating system.

Step 2: Run the Installer

run a php file using xampp
  • Open the downloaded file and follow the installation instructions. It is recommended to keep the default installation directory (C:\xampp).

Step 3: Start Apache and MySQL

run a php file using xampp
  • Open the XAMPP Control Panel. Execute the Apache and MySQL services by clicking the “Start” buttons next to them.

Congratulations! You have completed the XAMPP installation process & started Apache and MySQL!

Setting Up a PHP Project in XAMPP

It’s quite easy to get started with your PHP project with XAMPP. After putting your PHP files in a new directory, open your web browser and enter your project. You will be able to code and test your PHP applications locally after completing this process.

Step 1: Create a New Folder in htdocs

  • Navigate to the XAMPP installation directory (C:\xampp\htdocs) and create a new folder for your project. For example, name it demo.

Step 2: Write a PHP Script

run a php file using xampp
  • Inside the demo folder, create a new file named new.php. 

Step 3: Save the File

  • Save the file in the (demo) folder.

Running Your PHP Script

It’s easy to run your PHP script using XAMPP. Once your PHP project is configured in the “htdocs” directory, use the XAMPP control panel to make sure that the Apache server is started and running. Your PHP script will run as a result, and the output will appear in the browser. You may easily test and debug your PHP code locally by following these easy steps.

Step 1: Open Your Web Browser

  • Open your preferred web browser. In my case, I am using Google Chrome.

Step 2: Access the Localhost

run a php file using xampp
  • Type (http://localhost/demo) in the address bar and press Enter.

Step 3: View the Output

  • You should see “Hello, world!” displayed in your browser, indicating that your PHP script is running successfully.

FAQs

PHP has many benefits that make it a top choice for web developers.

  1. Simplicity: PHP is a language that both beginner and expert developers may easily learn, thanks to its simple commands.
  2. Compatibility: PHP is compatible with a wide range of operating systems, such as Linux, macOS, and Windows.
  3. Flexibility: PHP makes it simple for developers to modify already existing projects.
  4. Cost-effective: PHP is free to download and use without any license fees because it is an open-source language.
  5. Performance: PHP is an excellent language for web development since PHP scripts load more quickly than those of many other computer languages.

Library Support: To make their work easier, developers may use PHP’s extensive library of pre-written programs and libraries.

In Summary

One simple step in developing websites is to set up XAMPP and run PHP scripts locally. That has the potential to greatly improve your development workflow.

Before putting your PHP website on a live server, you may build, test, and debug them in a secure local environment by following these steps. Have fun with coding!

The Author

Scroll to Top