Originally published on zero2php.dev — part of the Zero to PHP course. View this lesson on the original site.
Check whether PHP is already installed
Open a terminal (on Windows, PowerShell or cmd). Run:
php -v
If you see a line like PHP 8.3.x (cli) …, you are ready—PHP 8.2 or newer is fine for this course. Skip ahead to Your first script.
If you see command not found, php is not recognized, or a version older than 8.2, install or upgrade PHP using one of the paths below.
Install PHP (pick your environment)
Official overview: Installation on php.net. Use the page that matches your system:
| Platform | Where to read next |
|---|---|
| macOS | Installation on macOS — a common route is Homebrew (brew install php) after you install Homebrew. |
| Linux (Debian/Ubuntu-style) | Installation on Unix systems — often sudo apt install php-cli or a versioned package like php8.3-cli depending on your distro. |
| Fedora / RHEL-style | Same Unix page; often sudo dnf install php-cli. |
| Windows | Installation on Windows — official builds, PATH, and notes on bundled stacks. |
Stacks (optional): tools like XAMPP, Laragon, or Laravel Herd bundle PHP—fine if you run php -v in their terminal or add their PHP folder to your PATH. See also Command line usage for how the php binary behaves.
Containers: if you develop in Docker, you will run php inside the container—see the official PHP image when the course moves to containerized workflows.
After any install or PATH change, close and reopen the terminal, then run php -v again.
Your first script
Create a file named hello.php in a folder of your choice:
<?php
declare(strict_types=1);
echo "Hello from PHP\n";
From that folder, run:
php hello.php
You should see Hello from PHP on its own line.
If php is not found
- Confirm you installed CLI PHP (not only a web stack that hides the binary).
- On Windows, ensure the directory that contains
php.exeis on your PATH (user or system). - On macOS/Linux, use
which phporwhere phpto see which binary runs—adjust PATH or your version manager if you have several PHP installs.
Habit: lint before you trust a run
php -l hello.php
That syntax-checks the file without executing it—useful right after edits.
From Zero to PHP — PHP foundations: environment, syntax, and values