Installation & Setup
Before you can run a single line of PHP, you need an interpreter on your machine. How you get one depends entirely on your operating system, and the path you choose has real consequences later — a bare interpreter is enough to run scripts from the command line, but web development also needs a web server and, usually, a database, which is why bundled stacks exist. This page covers installing PHP itself on Windows, macOS, and Linux, confirming the install worked, finding the configuration file that controls PHP's behavior, and managing more than one PHP version on the same machine.
Windows
Windows has no PHP interpreter built in, so you have two realistic options. The first is installing PHP directly from the official binaries at windows.php.net: download the "Non Thread Safe" zip if you will run PHP only through PHP-FPM or the CLI, or the "Thread Safe" build if you plan to use it as an Apache module. Unzip it somewhere permanent (for example C:\php) and add that folder to your PATH environment variable so php is available from any terminal.
Adding PHP to PATH on Windows (PowerShell, current user)
[Environment]::SetEnvironmentVariable(
"Path",
$env:Path + ";C:\php",
"User"
)
# Open a new terminal window afterwards for the change to take effect.The second option — and the one most beginners should reach for first — is installing a bundled stack such as XAMPP, which ships Apache, PHP, and MySQL/MariaDB preconfigured and wired together with a control panel. It trades some control over exact versions for a much faster path to "it works." A dedicated XAMPP setup tutorial covers that installer in detail; use the manual zip approach above when you specifically need a particular PHP version or want to pair PHP with a web server you already have installed.
macOS
macOS ships with an Apple-provided PHP binary on some older versions, but it is frequently missing, outdated, or removed entirely on recent releases — do not rely on it. The standard approach is Homebrew, the package manager most Mac developers already use for command-line tools.
Installing PHP with Homebrew
brew install php # Homebrew installs the latest stable PHP and links it onto your PATH # automatically, printing the version once it finishes.
Linux (Debian/Ubuntu family)
On Debian-based distributions, PHP is available directly from the default package repositories through apt. Refreshing the package index first ensures you get a current version rather than a stale cached listing.
Installing PHP on Debian/Ubuntu
sudo apt update sudo apt install php # For web development you will usually also want the CLI, FPM, and a # handful of extensions used by most frameworks and libraries: sudo apt install php-fpm php-mysql php-mbstring php-xml php-curl
Other distributions follow the same idea with their own package manager — dnf install php on Fedora, pacman -S php on Arch — the package name is consistently just php.
Verifying the install
Regardless of platform, two commands confirm PHP is installed and tell you what it can do. php -v prints the interpreter's version and build information; php -m lists every extension (module) currently compiled in or loaded, which matters because a lot of "this library doesn't work" issues turn out to be a missing extension like mbstring, curl, or pdo_mysql.
Sanity-checking a fresh install
php -v php -m
PHP 8.3.6 (cli) (built: Apr 10 2024 12:03:22) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.6, Copyright (c) Zend Technologies [PHP Modules] Core curl json mbstring openssl pdo pdo_mysql Reflection ...
If php is "not recognized" or "command not found," the interpreter either failed to install or was not added to your shell's PATH — on Windows this is almost always the missing PATH entry from the step above; on macOS/Linux it usually means the shell session was opened before the install finished and needs to be restarted.
php.ini: where PHP's configuration lives
PHP reads its settings from a file called php.ini at startup — error reporting level, upload size limits, timezone, which extensions load, and dozens of other behaviors all live there. The exact file location varies by OS and by whether you are running the CLI or a web server SAPI (a machine can have a separate php.ini for each). php --ini tells you exactly which file is in use and where PHP looked for others.
Finding the active php.ini
php --ini # Configuration File (php.ini) Path: /etc/php/8.3/cli # Loaded Configuration File: /etc/php/8.3/cli/php.ini # Scan for additional .ini files in: /etc/php/8.3/cli/conf.d # Additional .ini files parsed: /etc/php/8.3/cli/conf.d/10-mysqlnd.ini, # /etc/php/8.3/cli/conf.d/20-curl.ini, ...
Managing multiple PHP versions
Sooner or later you will work on two projects that require different PHP versions — one legacy codebase pinned to PHP 7.4, another built against PHP 8.3 features. Overwriting a single system-wide PHP every time you switch projects does not scale, so version managers exist to keep several installs side by side and let you pick which one is active.
phpbrew(Linux/macOS): builds and installs multiple PHP versions from source into isolated directories, and switches your shell between them with a single command.phpenv: a lighter, shim-based version manager modeled onrbenv/pyenv, which intercepts calls tophpand forwards them to the version configured for the current directory.Homebrew(macOS): install a specific major version directly by name, e.g.brew install php@8.2, then usebrew link --force php@8.2(or an explicit path) to make it the active one without a separate version-manager tool.
Pinning an older PHP version with Homebrew
brew install php@8.2 brew link --overwrite --force php@8.2 php -v # PHP 8.2.x (cli) ...