PHP Install
To run PHP on your own computer you need the PHP interpreter. For web pages you also need a web server that hands .php files to PHP — but PHP ships with a small built-in server that is perfect for learning and local development.
Note: You don't need to install anything to follow this course. Every playground runs PHP 8.4 in your browser. Install PHP locally when you want to build real projects.
Ways to get PHP
| Option | Good for | Notes |
|---|---|---|
| Official package (Linux) | Servers, developers on Linux | apt install php-cli (Debian/Ubuntu), dnf install php-cli (Fedora) |
| Homebrew (macOS) | Mac developers | brew install php |
| windows.php.net zip | Windows developers | Unzip and add the folder to your PATH |
| XAMPP / Laragon / MAMP | Beginners | Bundles Apache, PHP and MySQL with a control panel |
| Docker | Reproducible setups | docker run --rm php:8.4-cli php -v |
| Web hosting | Publishing a site | Most shared hosts already run PHP |
Whichever option you choose, try to use PHP 8.3 or newer. Older versions no longer receive security fixes.
Check your installation
Open a terminal and ask PHP for its version:
php -vPHP 8.4.25 (cli) (built: Sep 25 2025 10:12:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.25, Copyright (c) Zend Technologies
with Zend OPcache v8.4.25, Copyright (c), by Zend Technologies
The exact version number and build date on your machine will differ. cli means this is the command-line version of PHP.
Two other useful commands:
| Command | What it shows |
|---|---|
php -v |
The installed version |
php -m |
The list of loaded extensions (e.g. pdo_sqlite, mbstring) |
php --ini |
Which php.ini configuration file is used |
php -r 'echo 2 + 3;' |
Runs a single line of code |
php file.php |
Runs a script file |
Running a script from the terminal
Create a file named hello.php:
<?php
echo "Hello from the command line!\n";Then run it:
php hello.phpHello from the command line!
The built-in web server
PHP includes a development web server. Inside your project folder, start it with -S and an address:
php -S localhost:8000[Thu Oct 16 10:00:00 2025] PHP 8.4.25 Development Server (http://localhost:8000) started
[Thu Oct 16 10:00:04 2025] [::1]:51512 Accepted
[Thu Oct 16 10:00:04 2025] [::1]:51512 [200]: GET /
[Thu Oct 16 10:00:04 2025] [::1]:51512 Closing
Now open http://localhost:8000 in your browser. A request for / serves index.php (or index.html) from the current folder, and a request for /about.php runs about.php. Press Ctrl+C to stop the server.
Tip: The built-in server handles one request at a time and is meant for development only. Real websites use Apache, nginx or Caddy together with PHP-FPM.
A minimal web page
A typical first page mixes HTML with small pieces of PHP:
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<p>2 + 2 = <?php echo 2 + 2; ?></p>
</body>
</html>When the browser requests this file, PHP replaces the <?php ... ?> part with 4, so the visitor receives plain HTML.
Try it here
The playground below is real PHP. It prints the major version number using the built-in constant PHP_MAJOR_VERSION, which works the same on every PHP 8 installation:
<?php
echo "Running on PHP " . PHP_MAJOR_VERSION . "\n";
echo "Is it at least PHP 8? " . (PHP_MAJOR_VERSION >= 8 ? "yes" : "no") . "\n";Running on PHP 8
Is it at least PHP 8? yes
Editors
Any text editor works, but a code editor with PHP support makes life easier: VS Code with the PHP Intelephense extension, or PhpStorm. They give you autocompletion, error highlighting and quick documentation lookups.
Test yourself
Which command prints the installed PHP version?
php --version-infophp -vphp -sphp info
What does php -S localhost:8000 do?
- Runs the syntax checker
- Starts PHP's built-in development web server
- Installs PHP version 8
- Opens an interactive shell
Is PHP's built-in server suitable for a busy production website?
- Yes, it is the recommended production server
- No, it is meant for development and testing
- Only on Windows
- Only with HTTPS