PHP Lesson 4 – What is XAMPP and how to use it?

Last updated on January 17th, 2024

What software is needed to run a PHP script?

It has already been mentioned that two things are needed for a PHP script to work – a web server and a PHP interpreter.

The PHP interpreter is free software and is usually used together with the Apache server, which is also free. (Other servers can also be used, for example Nginx.).

However, to fully work with PHP, one more element is needed – database management software. Databases are necessary to store information in them. A database management system called MySQL is usually used (other databases can also be used). A software called phpMyAdmin is usually used together with MySQL – this is a program for working with MySQL databases. MySQL and phpMyAdmin are also free programs.

So, to fully work with the PHP language, you will need the following programs:

– Apache web server (official website https://www.apache.org)
– PHP interpreter (official page https://www.php.net/downloads.php)
– MySQL databases (official website https://www.mysql.com)
– phpMyAdmin software for working with MySQL (official website https://www.phpmyadmin.net)

All this seems complicated, but there is a simple way to install all the listed programs at once with just a few clicks. To do this, you need to download the XAMPP software package, which contains everything you need to work with the PHP language and can be installed in seconds. XAMPP is an abbreviation for Cross-Platform, Apache, MySQL, PHP and Perl.

Where can I download XAMPP and how to use it?

Open the official XAMPP page and download the package to your computer:

https://www.apachefriends.org/

After downloading XAMPP click on the .exe file and start the installation by following the instructions given at each step. XAMPP will prompt you to install several additional programs, such as Filezilla, Perl, and others. Install only Apache, PHP, MySQL and phpMyAdmin.

Note: If you have difficulty downloading and installing XAMPP, please read the additional tutorial How to download and install XAMPP?

After installation, you will see the XAMPP Control panel icon in your start menu or desktop. This is what the XAMPP icon looks like:

XAMPP icon

Double-click on it, then click on the “Start” button next to Apache – now your server is started. To stop the server, click the “Stop” button.

XAMPP control panel

After you download and install the software on your computer it will be located in the xampp folder and the path to it on your computer will be:

C:\xampp

(or C:\Program Files\xampp\ – if xampp is located in the Program Files folder on the C: drive).

In the xampp folder you will see an htdocs folder – this is your main directory where you should place your files and folders. Once a file, for example test.php, is created and stored in the htdocs folder, you will be able to access and view it in the browser via a localhost address, i.e. its browser address will be:

http://localhost/test.php

and the path to it (to the source file) on the machine will be:

C:\xampp\htdocs\test.php

(or C:\Program Files\xampp\htdocs\test.php – if XAMPP is installed in the Program Files folder).

Remember that the Apache server must be started from the XAMPP control panel for your PHP scripts to run.

If in the htdocs folder you make, for example, a dir folder and put the test.php file in it, then the address to access the file in the browser will be:

http://localhost/dir/test.php

and the path to the source file will be:

C:\xampp\htdocs\dir\test.php

(or C:\Program Files\xampp\htdocs\dir\test.php – if XAMPP is installed in the Program Files folder)

An example of working with the XAMPP package

Open the text editor Notepad and put the following code in it:

<!DOCTYPE html>
<html>
<head>
<title>PHP Test</title>
</head>
<body>

<?php echo "Hello World"; ?>

</body>
</html>

Save the file as test.php and place it in C:\xampp\htdocs\ folder (or C:\Program Files\xampp\htdocs\). Start the Apache server. Open your browser and type in the address http://localhost/test.php – on the screen you will see a page with the greeting “Hello World”.

Note: You may not install XAMPP on your computer if you wish. Buy a domain and hosting and upload your PHP scripts to the Internet for viewing. Upload your script to your hosting via file manager or FTP (HTML/CSS Lesson 2 – How to upload the HTML pages to the Internet?). Then, if your domain is www.example.com and your script is test.php, you’ll be able to see the script at www.example.com/test.php