Install PHP Locally
Before you can run PHP, you need a server that understands it. On your own computer that server is usually Apache, and the easiest way to get both is a package called XAMPP. It installs Apache, PHP, and MySQL together and manages them from one control panel. One download, one installer, and you are ready to write PHP.
XAMPP puts your website files in a folder called htdocs. Anything you save there is served at http://localhost. A file called htdocs/hello.php opens at http://localhost/hello.php. The localhost address is the key: it tells your computer to treat the folder as a website, so PHP actually runs instead of being shown as text.
On Windows, XAMPP works out of the box in most cases. On macOS, MAMP is the popular equivalent, and Linux users can install PHP and Apache with their package manager. Whichever you pick, the idea is the same: a web server on your machine that knows how to run PHP.
Once everything is installed, check the version with php -v in a terminal. Then make a test file, open it at localhost, and you have a working PHP environment. From there every lesson in this track runs on the same setup.
Get XAMPP running
Download XAMPP from the official Apache Friends site and run the installer. When it finishes, open the XAMPP Control Panel and press Start next to Apache. The panel shows green when the server is up. MySQL can wait until the database lesson.
# XAMPP Control Panel
# Press "Start" next to Apache
# A green status means the server is listening
Your first localhost file
Open the htdocs folder and create a file named test.php. Put a small PHP script inside. Then open http://localhost/test.php. If you see the greeting, PHP is installed and running.
<?php
echo "PHP is working!";
?>
Syntax
php -v
# PHP 8.3.x (cli) - the version you have installed
php -S localhost:8000 Is Built-in Server
No Apache needed for learning — php -S localhost:8000 serves current folder instantly.
php -S localhost:8000
Good to know
- XAMPP bundles Apache, PHP, and MySQL in one installer.
- Files go in htdocs and open at http://localhost.
- Start Apache from the XAMPP Control Panel before testing.
- php -v in a terminal shows which PHP version you have.