Setting up a Local Server for PHP using XAMPP

  • Tutorials
  • Local Server
  • PHP
  • XAMPP

XAMPP is a very popular tool for setting up and building PHP applications and websites without the use of a live server. XAMPP gives you the opportunity to use Apache, PHP and MySQL from the comfort and safety of your local machine. This tutorial will help you get started by setting up a local environment that is capable of running PHP.

Download XAMPP:

Let’s begin this tutorial by downloading our software. To do this, simply go to http://www.apachefriends.org/en/xampp.html and download the version of XAMPP for your operating system.

This should take you to a new area with new download links. Here we will specify the current build that includes PHP 5.5. Click on the “Installer” button to begin the install. Open the installer file and go through the installer until you reach the final step.

Starting a Project:

Once your install has completed, the XAMPP Control Panel should appear. You should see a number of Modules that we can choose to enable in this control panel. To use PHP, we will only need to start the Apache module. Start Apache and minimize your control panel (if you close the program, it will still run in the background).

You will know when the Apache server is running because it should turn green in the Module column. When this has happened, you can begin creating your project files in the XAMPP Directory.

The area that all your project files should be saved is at the following directory:

C:/xampp/htdocs/

Create a new folder in ‘htdocs’ called ‘testSite’ and navigate to this to create your new PHP files. Create a file called ‘index.php’ and open this file in your preferred text editor. In this file type the following code:

<?php
echo 'This is my first PHP project, created on ' . date('l the jS F');
?>

Testing the Code

Save this code and open up the file in your native web browser. To do this, you must always start the URL with ‘localhost’. This will tell the browser that the webpage it needs to serve is stored locally. We must then follow ‘localhost’ with the project name that we specified in ‘htdocs’ which was ‘testSite’. Therefore, to open your this we project, we simply need to use the following URL:

http://localhost/testSite

When you enter this into your browser and hit enter, you should see your index.php file. If you can see the message ‘This is my first PHP project, created on {TODAY’S DATE}, Your project has been set up correctly. You can now expand this page and start building a much more complex application without the need to use a live server.

Using a local server is a much better way to develop your PHP projects as they are completely private to your computer and faster. With XAMPP you can also expand your web projects by using the other modules available such as MySQL.

Note: If you want to upload WordPress files to your local area, you must start the Apache module and the MySQL module.

Summary

You must add all project folders to the following directory: C:/xampp/htdocs/your-project if you are using Windows. Your project files may exist in another directory in other operating systems.

To access your project in the browser, navigate to the following url: http://localhost/your-project-folder

Contact Me

If you would like to work with me on a project, I would be more than happy to help! Get in touch by using one of the following channels below: