Installing PHP
To install PHP, download the Windows zip from php.net, run brew install php on a Mac, or use apt or dnf on Linux. Then open a new terminal and run php -v, which prints the version you installed. The PHP lessons themselves run without installing anything.
Key facts
- PHP 8.6.0, released on November 19, 2026, is the newest version of PHP.
php -vnames the installed version on the first line of its output, as inPHP 8.6.0 (cli).- A Windows PATH entry for PHP has to name the folder that holds
php.exe, such asC:\php, because an entry namingphp.exeitself is ignored. - The PHP 8.6.0 zip for Windows comes without a php.ini file, so
php --inireports(none)as the loaded configuration file. - Without a php.ini that sets
extension_dir, PHP for Windows looks for extensions inC:\php\ext.
How do I install PHP on Windows?
Download the PHP for Windows zip from php.net and unzip it to C:\php. The official download is a zip file rather than a setup program, so you set it up with a few steps by hand.
- Download PHP. On php.net's Windows downloads page, find
VS18 x64 Non Thread Safeand click its Zip link. For PHP 8.6.0, that'sphp-8.6.0-nts-Win32-vs18-x64.zip. - Install the Visual C++ runtime. PHP 8.6 builds need the Visual C++ v14 Redistributable, and the downloads page links the x64 installer. If it's already on your computer, the installer says so and changes nothing.
- Unzip it to C:\php. Extract the files so that
php.exeends up atC:\php\php.exe. PHP looks for its extensions, parts of PHP that add features, inC:\php\extby default, so this folder saves you a setting later. - Create php.ini. In
C:\php, copyphp.ini-developmentand rename the copy tophp.ini. PHP reads its settings from a php.ini next tophp.exe, and the development version shows error messages, which helps while you learn. - Add C:\php to PATH. PATH is the list of folders Windows searches for programs, and adding C:\php to it lets you type
phpin any folder. - Check it. Open a new terminal and run
php -v. It should print a line that starts withPHP 8.6.0.
The Non Thread Safe (NTS) build is the recommended one for command-line scripts. Thread Safe (TS) builds are for PHP loaded as a module by the Apache web server, and x64 builds suit almost every Windows computer today.
php.net's downloads page also lists a one-line install with winget, a command-line tool that installs Windows programs.
winget install PHP.PHP.8.6
That command installs the Thread Safe build along with the Visual C++ runtime, but it doesn't create a php.ini. The manual steps keep everything in C:\php, which the rest of this guide assumes.
How do I add PHP to the PATH on Windows?
Add C:\php to the Path variable in the Environment Variables window.
- Search the Start menu for environment and open Edit the system environment variables.
- Choose Environment Variables.
- Under System variables, select Path and choose Edit.
- Choose New, type
C:\php, then choose OK in each window.
Path under User variables works too, for your account only, and Edit environment variables for your account in the Start menu opens that list directly. Either way, add to the list and never replace it, because other programs need their entries.
A terminal keeps the PATH it had when it opened. Close any terminal that was already open and start a new one before you run php -v.
How do I install PHP on a Mac?
Install Homebrew, then run brew install php in the Terminal app.
brew install php
macOS stopped including PHP with macOS 12 Monterey, so a Mac on macOS 12 or later has no php command until you install one. Homebrew installs command-line programs with one command each, and php.net's macOS downloads page shows how to install Homebrew itself.
That page writes the PHP step as brew install php@8.6, another name Homebrew gives the same package, followed by a brew link command. In November 2026, Homebrew's php package is PHP 8.6.0, and php -v confirms the version you got.
Homebrew keeps php.ini in etc/php/8.6 under the folder it installs into, and php --ini prints the full path.
How do I install PHP on Linux?
Install PHP from your distribution's packages, with apt on Ubuntu and Debian or dnf on Fedora. The php-cli package gives you the command-line PHP, which includes PHP's built-in web server.
sudo apt update
sudo apt install php-cli
On Fedora, the command is sudo dnf install php-cli.
The command on php.net's downloads page for Linux installs the package called php instead. On Ubuntu 26.04, that package also needs a way to run PHP behind a web server, such as Apache's PHP module, so it installs more than php-cli does.
Which PHP version does each install method give you?
The PHP version you get depends on where you install it from. Of the methods in the table below, only the php.net zip, winget and Homebrew install PHP 8.6.0, the latest version of PHP.
| Install method | PHP version | php.net security fixes until |
|---|---|---|
| Windows zip from php.net | 8.6.0 | December 31, 2030 |
| winget on Windows | 8.6.0 | December 31, 2030 |
| Homebrew on macOS | 8.6.0 | December 31, 2030 |
| XAMPP, newest release | 8.5.13 | December 31, 2029 |
| Ubuntu 26.04 LTS | 8.5 | December 31, 2029 |
| Ubuntu 24.04 LTS | 8.3 | December 31, 2027 |
| Ubuntu 22.04 LTS | 8.1 | Ended December 31, 2025 |
| Debian 13 | 8.4 | December 31, 2028 |
| Debian 12 | 8.2 | December 31, 2026 |
| Fedora 44 and 45 | 8.5 | December 31, 2029 |
| Fedora 43 | 8.4 | December 31, 2028 |
The PHP project releases ready-made builds only for Windows, and on Linux your PHP comes from the packages your distribution builds. Each release of a distribution has its own PHP version, so Ubuntu 22.04 still installs PHP 8.1, a branch whose support from php.net has ended.
For PHP 8.6 on Ubuntu, Debian or Fedora, php.net's downloads page shows how to add a third-party package repository. Those builds are unofficial, and like your distribution's own packages, they carry patches the PHP project doesn't control.
The Debian and Ubuntu repository also adds telemetry to its Apache and PHP-FPM modules.
How do I check which version of PHP is installed?
Run php -v in a terminal to see the installed version of PHP.
php -v
The first line of the output names the version. For the PHP 8.6.0 zip on Windows, it's PHP 8.6.0 (cli) (built: Nov 18 2026 01:00:44) (NTS Visual C++ 2026 x64).
Here cli means the command-line PHP, and NTS confirms the Non Thread Safe build. php --version prints the same lines, but php version without the dashes looks for a file named version to run.
Inside a script, calling phpversion() gives you the version of the PHP that runs it. That helps on a web host, where you may not have a terminal at all.
echo "This script runs on PHP ", phpversion(), ".\n";This script runs on PHP 8.5.12.
The runner on the lesson pages uses PHP 8.5.12, which is the version this example prints. Under PHP 8.6.0, the same script prints This script runs on PHP 8.6.0. instead.
How do I fix 'php' is not recognized as an internal or external command?
Add PHP's folder to your PATH, then open a new terminal.
Command Prompt prints this error when it can't find a program named php. That happens when PHP isn't installed or when the folder holding php.exe is missing from the PATH.
'php' is not recognized as an internal or external command,
operable program or batch file.
PowerShell's message includes The term 'php' is not recognized, followed by more details.
- Check the PATH. Run
where phpin Command Prompt orGet-Command phpin PowerShell to search the PATH forphp.exe. When it finds nothing, no folder on the PATH holdsphp.exe. - Add its folder to PATH. Follow the PATH steps for Windows with the folder that holds
php.exe, such asC:\php. For XAMPP installed inC:\xampp, that folder isC:\xampp\php. - Open a new terminal. Close the old windows first. Restart VS Code and other code editors too, because they don't see the new PATH until then.
On macOS and Linux, the wording depends on the shell, the program that reads your commands. Bash says command not found, and on a standard Ubuntu install, a helper prints Command 'php' not found plus an apt command that installs it.
Either way, the fix is to install PHP or put its folder on the PATH.
How do I find the php.ini file PHP uses?
Run php --ini to see which php.ini file PHP loaded.
php --ini
php.ini holds PHP's settings, and the command-line PHP reads it every time it starts. With no php.ini in C:\php yet, PHP 8.6.0 prints this.
Configuration File (php.ini) Path: ""
Loaded Configuration File: (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
The (none) on the second line means PHP is using its built-in defaults. Once C:\php\php.ini exists, that line shows its path in quotes.
On Ubuntu and Debian, apt's packages keep a separate php.ini for each way of running PHP. The command-line one is /etc/php/8.x/cli/php.ini, where 8.x is the PHP version, while Fedora uses /etc/php.ini.
A PHP page that runs phpinfo() lists the loaded php.ini near the top, along with every setting, and php -i prints the same kind of report for the command-line PHP. Delete such a page from a public server when you're done, because anyone who opens it sees your paths and settings.
How do I turn on a PHP extension on Windows?
Delete the semicolon at the start of the extension's line in php.ini, such as ;extension=mbstring.
In php.ini, a line that starts with a semicolon is a comment, and php.ini-development lists common extensions such as curl and mbstring that way. Run php -m afterward, which lists the extensions PHP loaded.
If PHP isn't in C:\php, also remove the semicolon from ;extension_dir = "ext". Without it, PHP keeps looking in C:\php\ext, prints an Unable to load dynamic library warning when it starts and runs without the extension.
When PHP runs as a module of a web server, it reads php.ini only when the server starts, so restart the server after you change a setting.
Should I use XAMPP or PHP's built-in web server?
Start with PHP's built-in server, and switch to XAMPP when a project needs Apache and a database.
The built-in server comes with PHP itself and starts with one command, php -S localhost:8000, which the Hello World lesson walks through. It runs a single process and isn't meant to be a full web server, so keep it on your own computer.
XAMPP bundles Apache, the MariaDB database, phpMyAdmin and its own copy of PHP. As of November 2026, XAMPP for Windows, Linux and macOS comes in three versions, with PHP 8.3.37, 8.4.28 or 8.5.13, and none of them includes PHP 8.6 yet.
XAMPP's PHP is separate from the one in C:\php, with its own php.ini in C:\xampp\php. With both on your PATH, a terminal runs whichever php.exe comes first in the list, so check php -v.
For a first project on XAMPP, the secure login system tutorial builds a login page with PHP and MySQL.
Common mistakes when installing PHP
Windows finds php through the folders on the PATH, so most of the mistakes below start there.
- The PATH entry points at php.exe. Windows searches folders on the PATH, not files, so an entry of
C:\php\php.exeis ignored. Enter the folder,C:\php. - The PATH entry has a space at the end. Windows skips
C:\phptyped with a trailing space, even thoughwhere phpstill lists it, and PowerShell also skips an entry wrapped in quotes. A trailing backslash, as inC:\php\, is fine. - The terminal opened before PATH changed. It keeps the old list until you close it, so open a new window.
- Warning: PHP Startup: Unable to load dynamic library. PHP looked for an extension in
C:\php\ext, but PHP is in another folder. Remove the semicolon in front ofextension_dir = "ext"in php.ini. - Fatal error: Uncaught Error: Undefined constant "php". The terminal command
php -vended up in a PHP file, where PHP readsphpas the name of a constant. Run commands like it in a terminal instead.
The runner reports the same error when a terminal command is saved as PHP code.
php -v;
Fatal error: Uncaught Error: Undefined constant "php" in /app/main.php:2
Stack trace:
#0 {main}
thrown in /app/main.php on line 2Exercise
This program prints the full version of the PHP that runs it, such as 8.5.12. Change it so it prints only the major version, the number before the first dot, which the constant PHP_MAJOR_VERSION holds. On any PHP 8 release, that number is 8.
echo phpversion();
8
Show the solution
echo PHP_MAJOR_VERSION;
Quiz
This quiz has 5 questions. Pick an answer to see why it is right or wrong.
-
1Which command prints the version of PHP installed on your computer?
The -v option makes PHP print its version and build, then exit. Without the dash, php version treats version as the name of a file to run, and php -m lists the loaded extensions instead.
-
2What does this script print when PHP 8.6.0 runs it?
echo PHP_MAJOR_VERSION;PHP_MAJOR_VERSION is the major version alone, an integer, so PHP 8.6.0 prints 8, as does every other PHP 8 release. The full 8.6.0 comes from phpversion() or PHP_VERSION.
-
3You added C:\php to PATH, but a Command Prompt window that was already open still says php is not recognized. What fixes it?
A terminal keeps the PATH it had when it opened, so only a window opened after the change sees C:\php. A trailing backslash makes no difference, and a PATH entry that names php.exe itself doesn't work at all.
-
4Which PHP build for Windows is recommended for running scripts from the command line?
Non Thread Safe builds are made for single-threaded use such as the command line, and x64 suits almost every Windows computer. Thread Safe builds are for PHP running as a module inside a multithreaded web server like Apache.
-
5Which command shows which php.ini file PHP loaded?
The --ini option lists the configuration files PHP read, or (none) when there isn't one. php -v prints the version, and php -S localhost:8000 starts the built-in web server.























