PHP ยท Chapter 2 of 44

PHP Install & XAMPP Setup

To run PHP, you need a web server with PHP installed, plus usually a database like MySQL. The easiest way to get started on your own computer is to install an all-in-one package such as XAMPP, which bundles Apache, MySQL/MariaDB, and PHP together.

XAMPP is free, available for Windows, macOS and Linux, and lets you test PHP scripts locally before deploying them to a real web host. Alternatively, many web hosting providers already have PHP installed and ready to use.

Syntax
http://localhost/yourfile.php

Installing XAMPP

Download XAMPP from the Apache Friends website, run the installer, and start the Apache and MySQL modules from the XAMPP Control Panel. Place your .php files inside the htdocs folder.

Running your first script

After starting Apache, open a browser and go to http://localhost/yourfile.php to see your script's output. Any syntax errors will typically be shown directly in the browser.

Example 1 (bash)
php -v
Output
PHP 8.3.0 (cli)

Running php -v in a terminal confirms PHP is installed and shows its version.

Example 2 (php)
<?php
  echo "XAMPP is working!";
?>
Output
XAMPP is working!

Saving this as test.php in htdocs and visiting localhost/test.php shows this message.

Key points

  • XAMPP bundles Apache, MySQL and PHP for local development.
  • PHP files are placed in the htdocs folder when using XAMPP.
  • php -v checks the installed PHP version from the command line.
  • Many hosting providers already have PHP preinstalled.
๐Ÿ’ก Note: Always start both Apache and MySQL in the XAMPP Control Panel before testing database-driven PHP scripts.

๐Ÿ“ Quick Quiz

1. What does XAMPP bundle together?

2. Which folder holds your PHP files in XAMPP?

3. Which command shows the installed PHP version?