TechJunkie is a BOX20 Media Company

Home PC Windows How to Run a PHP File in XAMPP

How to Run a PHP File in XAMPP

How to Run a PHP File in XAMPP

If you’re just getting into web development or testing, you’ve most likely been recommended to get XAMPP. It is a free, stable, and regularly updated server solution. In case you’re programming in PHP, you’re in luck, as running PHP files in XAMPP is a piece of cake. Keep reading to find out how to do it.

What Is XAMPP?

XAMPP is a cross-platform and open-source web server package. It is completely free to download and use and is developed and updated by Apache Friends. The main components include the Apache HTTP Server and the MariaDB database. Also included are the interpreters that can read Perl and PHP scripts.

Xampp Logo

XAMPP is compatible with Linux, Windows, and Mac operating systems, making it a super-versatile server solution. It also supports LAMP and WAMP stacks.

XAMPP is an acronym, with the letters standing for the following:

  1. X is for cross-platform
  2. A is for the Apache server
  3. M is for the MariaDB database (it used to stand for MySQL)
  4. P is for PHP
  5. P is for PERL

Open a PHP File in XAMPP

Opening and running PHP files in XAMPP is easy and simple. All you need is a working copy of XAMPP and a PHP file. Let’s see how you can do this.

Step 1

First, let’s get XAMPP. You’ll need to get an appropriate version for your operating system from the Apache Friends’ official site.

Launch your favorite web browser and go to https://www.apachefriends.org/index.html. When the Home page of the site opens, you should click on the latest version of the program for your operating system. At the time of this writing, PHP 7.3.7 is the latest one for all three major OS platforms. Click on the one you need to download it.

In case you want an older version, click on the “Click here for other versions” link within the green Download field.

Step 2

Next, you should install XAMPP on your computer. The most common practice is to install it on the C drive, though some users opt to install it on D or other non-system partitions.

To install XAMPP, double-click on the installer file you downloaded. Click on the Run button to start the installation. Follow the installation wizard to complete the installation. In the Select Components section, you can opt to leave some components out if you’re sure you won’t need them. However, it is recommended to keep everything as is and install the full version.

The default location is C:\xampp. You can change it if you want to, but it is recommended not to.

Xampp Installation

Step 3

In this step, you’ll create the project folder where you’ll save the PHP file you’d like to run in XAMPP. To do that, go to your XAMPP folder. If you haven’t altered installation options, your copy of XAMPP is installed on the C drive.

Once you get to the XAMPP’s main folder, go to the htdocs folder. There, create a new folder and name it after the file you’ll copy into it. Alternatively, you can name it “NewProject,” “Project 1,” or give it any other name.

Step 4

If you already have a file that you want to open with XAMPP, browse for it. Once you’ve located it, copy and paste it into the folder you created in the previous step. You can also cut and paste the file.

If you don’t have the file and you want to create your first PHP file to test XAMPP, here’s what to do. Go to the folder you created in the previous step and create a new text file in it. Name the file and change its extension from txt to php. Before we start, here is a word of warning: don’t enter the full stops at the end of the commands, as they are only there for grammatical purposes.

Open the file with a text editor, both Notepad and Notepad ++ will be good. Start your HTML document with <html>. In the next row, open the header with <head><h1>Title</h1>. Close the header in the next row with </head>.

Next, open the body container with <body> in the next row. Press Enter a few times and press TAB for indent. Type in <?php. Press Enter once or twice and write the following command print “text”. Between the quotations, you should write what you want to see when you open the file with XAMPP.

Press Enter once more and type ?>. This will end the PHP section. In the next row, you should type </body>. In the row below that one, you should type </html>. Press Ctrl and S keys on your keyboard to save the changes to the file. Your file might look like this at the end:

PHP File Example

Step 5

Now, let’s open the file with XAMPP. Here’s how to do it:

  1. Launch XAMPP. You can open it via the status bar icon or search for it in the Start menu if you’re on a Windows computer.
  2. Once the app opens, you will see its Control Panel. Click on the Start button in the Apache row. This will launch the Apache server. The Apache label in the Module column will turn green and you’ll see a message in the log at the bottom of the Control Panel informing you that the server is running.
    Apache Running
  3. Now, open your browser and type “localhost” into the address bar (omit the quotations).
  4. You should see the “localhost – Welcome to XAMPP” option right below the address bar. Click on it.
  5. You will be redirected to localhost/dashboard. Replace the dashboard part with the name of the folder where your PHP file is located. In our case it looks like this: localhost/NewProject.
  6. You will see the list of files in the said directory. Click on your PHP file.

If everything’s OK, you should see your PHP file open in your browser.

XAMPP to the Max

As a free and open-source solution, XAMPP is a common option for web developers and testers running on a tight budget. What’s more, many professionals use it, too. The fact that it’s compatible with Linux, Windows, and Mac makes it even more popular.

Do you use XAMPP? Have you ever had problems running PHP files and how did you solve them? Share your thoughts and experiences with XAMPP in the comments section below.

How to Use Plain Text Mode in TextEdit

Read Next 

3 thoughts on “How to Run a PHP File in XAMPP”

Samrech Phauk says:
Dear Sir/Madam,
When I first installed XAMPP I selected Firefox as my browser. No Firefox doesn’t show any thing from my hello.php. So I use Opera and it output: “This site can’t provide a connection. localhost sent an invalid response. Try running Windows Network Diagnostics.
ERR_SSL_PROTOCOL_ERROR”
Jonelle Corridon says:
Very helpful, thanks!
Ann says:
PHP stopped running for me. I have reloaded xampp 2x’s now. I have tried addressing the issue with StackOverflow twice. They keep closing my request without giving me any places to check. After following all the instructions I could find to correct the issue; including changes to the Apache config file. Running a test file for print (“Hello World”) results in an empty screen. After all the changes, my server indicates it can no longer find the file. I did run php -v in the DOS command. It indicated PHP was running correctly. Please help or I will have to look for an alternative program to do this simple function.

Leave a Reply

Your email address will not be published. Required fields are marked *


Kerry Bayley

Oct 10, 2019

My career as a project manager has given me plenty of time to get familiar with the full Microsoft suite, as well as a host of other tools, all of which I write about online.

1949 Articles Published

More