Using XAMPP on Windows

When learning PHP you will want to test PHP files on your computer; this is called running the PHP pages locally. To do this you need to install some software on your computer.

Testing files locally is much faster than trying to create and edit files on a remote server run by a hosting company. This page shows you how to install that software and the sample code for our book.


To view a PHP page that is stored on your PC in your web browser, your PC needs to be running a piece of software called a web server that supports PHP.

The web server's job is to find the page you want, run the PHP code, then send an HTML page to your web browser. We recommend a web server called Apache.

To create database-driven websites on your PC, you also need database software such as MySQL or MariaDB installed on your computer.

Rather than installing and configuring this software yourself, we recommend that Windows users get a program called XAMPP.

  • XAMPP is free.
  • It installs and configures Apache and MySQL for you.
  • And it provides an interface to help you use them.

The XAMPP interface is really helpful because neither Apache nor MySQL have a graphical user interface of their own.

How to Install XAMPP on Windows

To install XAMPP on your PC go to: https://apachefriends.org and click on the XAMPP for Windows link.

Screen shot of home page of XAMPP website

The download will start automatically.

Screen shot of download page of XAMPP website

Once the download has completed, go to your Downloads folder and double-click on the installer to start the installation.

Screen shot of XAMPP installer in Windows Explorer

Follow the instructions to install XAMPP.

Screen shot of the XAMPP setup wizard starting to run

To start XAMPP, type XAMPP into the search bar.

Then select the XAMPP Control Panel to start XAMPP.

Screen shot of the search box in the Windows task bar with XAMPP entered in the text input and the popup showing a link to open the XAMPP Control Panel

The XAMPP Interface

  • Screen shot of the XAMPP control panel
  • The button to start Apache is highlighted
  • The button to start MySQL is highlighted
  • The port numbers for Apache and MySQL are highlighted - these are shown when the servers have started

Where to Save PHP Files

When you are learning to create websites using PHP, you should save all of your PHP pages in a folder called the document root folder. You should also put any other files that the browser might request in this folder (such as images, CSS and JavaScript files).

When using XAMPP the default location of the document root folder is C:\XAMPP\htdocs\.

Running the Sample Code

1. Click here to download the code files for the entire book.

2. Move them to the document root folder (the default location is C:\XAMPP\htdocs\).

3. Enter the following URL into your browser's address bar: http://localhost/phpbook/

Once you have loaded this page, you can click on the links to move between the example files.

NOTE: You cannot open a PHP file in your browser using the browser's File > Open menu option to open a file, or by dragging it onto a browser like you would with an HTML page.

Understanding Local URLs

The URL is made up of the following parts:

  • http://
  • localhost
    host name
  • :
  • 80
  • /
  • phpbook/index.php