To run PHP you need the PHP interpreter installed. You do not need a full web server like Apache for learning: PHP ships with a small built-in server that is perfect for development.
Install PHP
Pick your operating system.
Windows
The simplest option is a local development bundle such as Laragon or XAMPP, which installs PHP, a web server and MySQL together. Alternatively:
- Download the latest VS16 x64 Non Thread Safe zip from the PHP for Windows site.
- Extract it to
C:\php. - Add
C:\phpto yourPATHenvironment variable. - Open a new terminal so the change takes effect.
macOS
Install Homebrew if you do not have it, then run:
brew install php
Linux (Debian or Ubuntu)
sudo apt update
sudo apt install php-cli
Check the installation
Open a terminal and run:
php -v
You should see something like this. The exact numbers will differ:
PHP 8.3.12 (cli) (built: Sep 24 2026 10:12:31) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.12
If you see "command not found" or "'php' is not recognized", PHP is not on your PATH. Close and reopen the terminal first. If that does not help, check the folder you added to PATH.
Run a script from the terminal
Create a folder for this course, for example php-course, and inside it a file called hello.php:
<?php
echo "Hello from PHP!\n";
echo 'PHP version: ' . PHP_VERSION . "\n";
In the terminal, move into the folder and run it:
cd php-course
php hello.php
Output:
Hello from PHP!
PHP version: 8.3.12
\n is a newline character. In the terminal it moves output to the next line.
Run pages in the browser
Start PHP's built-in server from the same folder:
php -S localhost:8000
Now create index.php:
<!DOCTYPE html>
<html lang="en">
<body>
<h1>It works</h1>
<p>The time on the server is <?php echo date('H:i'); ?>.</p>
</body>
</html>
Open http://localhost:8000 in your browser. Refresh the page and the time updates, because PHP runs again on every request. Press Ctrl+C in the terminal to stop the server.
The built-in server is for development only. It handles one request at a time and has no security hardening. Real sites run PHP behind a web server such as Nginx, Apache or LiteSpeed.
Set up your editor
Any editor works. If you use VS Code, install the PHP Intelephense extension. It shows errors as you type and completes function names, which saves a lot of time while learning.
Summary
- Install PHP 8 with a bundle (Windows), Homebrew (macOS) or your package manager (Linux).
php -vshows the installed version.php file.phpruns a script in the terminal.php -S localhost:8000serves a folder athttp://localhost:8000for development.