You need PHP on your own computer to run the examples. There are several ways to get it. Pick the one that matches your setup.
Option 1: an all-in-one bundle (easiest for beginners)
These packages install PHP, a web server (Apache) and MySQL together.
- XAMPP works on Windows, macOS and Linux.
- Laragon is a popular, light choice on Windows.
- MAMP is common on macOS.
- AMPPS works on Windows, macOS and Linux.
Install one, start Apache from its control panel, and put your PHP files in its htdocs or www folder.
Option 2: install PHP only
If you just want to run scripts from the terminal, you do not need a full web server.
# macOS (Homebrew)
brew install php
# Ubuntu / Debian
sudo apt install php-cli
On Windows, you can download PHP from windows.php.net and add its folder to your PATH. The official download page is php.net/downloads.
Option 3: Docker
If you already know Docker, the official php image gives you any version without installing anything on your computer.
docker run --rm -v "$PWD":/app -w /app php:8.4-cli php index.php
Check that it works
Open a terminal and run:
php -v
You should see a line that starts with PHP 8. If the terminal says “command not found”, PHP is not on your PATH yet.
Which PHP version?
Choose a version that is still supported. PHP Versions and Modern PHP has the link to the official list.