Installing PHP
Download and install PHP directly, verify the installation from a terminal, and run your first PHP file with the built-in development server.
Introduction
Before you can write and run PHP code, PHP itself needs to be installed on your machine. There are a few ways to do this, ranging from a fully manual setup using the official installers to all-in-one bundles that install PHP alongside a web server and database (which the next lesson covers in detail).
This lesson focuses on the manual route: downloading PHP directly from the official source, confirming it installed correctly, and understanding why PHP normally needs a web server — plus a shortcut that lets you skip that requirement while learning.
- How to download PHP directly from php.net for advanced or manual setups.
- How to verify a PHP installation using the terminal.
- Why PHP typically needs a web server like Apache or Nginx to serve pages.
- How to use PHP's built-in development server for quick testing without a full server setup.
Downloading PHP from php.net
The official source for PHP is php.net. On Windows, the "Windows downloads" section provides pre-built zip packages (choose the "Thread Safe" version if you plan to use it with Apache as a module). On macOS and Linux, PHP is more commonly installed through a package manager — Homebrew on macOS, or apt/yum on Linux — which pulls from the same underlying PHP source releases.
This manual route is considered "advanced" because you are responsible for configuring PHP yourself: setting up your system PATH, choosing a php.ini configuration file, and — as you will see shortly — pairing PHP with a web server. Beginners are usually better served by an all-in-one stack, which the next lesson covers.
Windows
Download a zip build from windows.php.net, extract it, and add the folder to your system PATH.
macOS
Most developers install PHP via Homebrew with a single command: brew install php.
Linux
Use your distribution's package manager, e.g. sudo apt install php on Debian/Ubuntu-based systems.
# macOS (Homebrew)
brew install php
# Debian/Ubuntu
sudo apt update
sudo apt install phpVerifying Your Installation
Once PHP is installed, the fastest way to confirm it worked is to open a terminal (Command Prompt, PowerShell, or a Unix shell) and check its version.
php --versionPHP 8.3.10 (cli) (built: Jul 15 2026 10:22:41) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.3.10, Copyright (c) Zend Technologies
with Zend OPcache v8.3.10, Copyright (c), by Zend TechnologiesA "command not found" or "'php' is not recognized" error almost always means PHP is not on your system PATH yet. Re-check the installation steps for your operating system, or restart your terminal after installing.
Why PHP Needs a Web Server
Having PHP installed lets you run PHP scripts from the command line, but real websites are accessed through a browser via a URL like http://localhost/page.php. Turning a raw PHP file into something a browser can request over HTTP is the job of a web server — most commonly Apache or Nginx.
The web server listens for incoming HTTP requests, and when it sees a request for a .php file, it hands that file off to the PHP interpreter (often through something called PHP-FPM, or as an Apache module) to execute. The server then sends the resulting HTML back to the browser.
Setting up Apache or Nginx by hand can be fiddly, which is exactly the problem all-in-one stacks like XAMPP solve — that is the focus of the next lesson.
The Built-in Development Server
For quick testing and learning, PHP ships with its own lightweight development server built in — no Apache or Nginx required. It is not meant for production use, but it is perfect for trying out scripts locally.
cd my-project
php -S localhost:8000[Sun Jul 26 10:00:00 2026] PHP 8.3.10 Development Server (http://localhost:8000) startedWith that running, visiting http://localhost:8000/hello.php in your browser will execute hello.php and show its output — no separate web server installation needed.
Example: Running a File Directly
You can also run a PHP file directly from the command line without any server at all, which is useful for quick scripts and testing logic.
<?php
echo "Hello from the PHP CLI!\n";
echo "PHP version: " . phpversion();php greet.phpHello from the PHP CLI!
PHP version: 8.3.10Common Mistakes
- Forgetting to add PHP to your system PATH after a manual Windows install.
- Trying to open a .php file directly by double-clicking it in a file browser — it needs to go through PHP, not just open as a text file.
- Using the built-in development server (php -S) for a real production site — it is single-threaded and meant for local testing only.
- Installing multiple PHP versions and not realizing which one "php --version" is actually pointing to.
Best Practices
- Always confirm your installation with php --version before writing any code.
- Use the built-in development server for small scripts and quick experiments.
- Prefer an all-in-one stack (covered next) if you want Apache/Nginx and MySQL without manual configuration.
- Keep track of which PHP version you installed, since some features (enums, readonly properties) require PHP 8.1 or later.
Frequently Asked Questions
Do I need to install a web server separately from PHP?
Not necessarily for learning — PHP's built-in development server (php -S) lets you test pages in a browser without installing Apache or Nginx. For production, you will want a real web server.
How do I know my PHP installation worked?
Run php --version in a terminal. If it prints a version number and build details instead of an error, the installation succeeded.
Can I just double-click a .php file to run it?
No. A .php file needs to be processed by the PHP interpreter, either through a web server request or the php command in a terminal — double-clicking will usually just open it as plain text.
Is the built-in development server safe for a live website?
No. It is explicitly documented as being for development and testing only, since it is not built to handle real production traffic or security concerns.
What is the difference between the CLI version of PHP and the version a web server uses?
They are usually the same PHP engine, just invoked differently — one runs scripts from the terminal, the other runs scripts in response to HTTP requests through a web server or the built-in server.
Key Takeaways
- PHP can be downloaded directly from php.net for manual, advanced installations.
- php --version confirms whether PHP installed correctly and which version you have.
- PHP normally needs a web server like Apache or Nginx to serve pages over HTTP to a browser.
- The built-in development server (php -S localhost:8000) is a fast way to test PHP files without installing a full web server.
Summary
Getting PHP installed and verified is the first concrete step toward writing real PHP code. Whether you install it manually from php.net or rely on the built-in development server for quick tests, the goal is the same: confirm PHP runs on your machine before building anything bigger.
In this lesson, you downloaded and verified PHP, and learned why a web server is normally part of the picture. Next, you will set up a complete, beginner-friendly stack — XAMPP, WAMP, or LAMP — that bundles PHP with Apache and MySQL.
- You know how to download PHP directly from php.net.
- You can verify a PHP installation using php --version.
- You understand why PHP typically needs a web server.
- You can start PHP's built-in development server for quick local testing.