close
Cart icon
User menu icon
User icon
Lightbulb icon
How it works?
FAQ icon
FAQ
Contact icon
Contact
Terms of service icon
Terms of service
Privacy policy icon
Privacy Policy
Zdjęcie główne artykułu.

How to run PHP files?

To run a PHP application, you will need a server. Usually you will also need a database. What to do if you don't have access to a server?

The easiest way is to use a so-called local server. That is an application that you install on your own local system. This is a well known and proven way to run PHP applications locally.

XAMPP - a proven and simple solution

The XAMPP application contains everything you need:

  • Apache server
  • PHP language support
  • MySQL database

XAMPP is free, tested and available for all popular systems. You won't need anything else at this stage. Go to the main XAMPP website and download the version that suits your system: https://www.apachefriends.org

How to install XAMPP

The installation is a simple process, although you need to be careful about a few things.

  • Pay attention to the directory where you install XAMPP. For Windows, for example, the default directory is C:\xampp.
  • It is possible that your firewall will block XAMPP. Make sure this does not happen to you.
  • Once the installation is complete, the XAMPP control panel should launch. You can always run it manually - it is a standard application like any other.

In the control panel you should start two services: Apache (which is the server) and MySQL (which is the database). Click on the Start button next to those services.

xampp control panel

Now open your browser and type in the address: http://localhost/. If everything went correctly, you should see the homepage of your local server.

Where to put files

We already have everything we need to run our PHP application locally. Now the next question - where to put the files of our application?

Remember the directory where XAMPP was installed? Go to it and find the 'htdoscs' subdirectory. This is where we place our applications.

To keep things organized, it's best to put everything in separate subdirectories. For example:

C:/xampp/htdocs/my_app

If we have such an application then we need to type http://localhost/my_app into the browser in order to run the app.

Database management

Most PHP applications use databases. In XAMPP we have access to the phpMyAdmin control panel. You can find it at http://localhost/phpmyadmin/.

In this panel you can manage databases, create tables, import data, etc.

Database - an example

Let's follow a simple example from the PHP - Practical Project course. In this course, you will be creating a game of battleships that you can run in XAMPP.

Game requires a MySQL database to run. In the game files you will find i.a. ships.sql file.

  • Open this file in any text editor and copy it.
  • Go to the phpMyAdmin panel, select SQL tab, paste copied content and click on Execute button.

After executing SQL, a database should be created with the necessary tables.

CAUTION: the default database login credentials in XAMPP are:

  • user = root
  • password = ‘’ (empty password)

Make sure that your application uses this data in its database connection configuration.

Codenga