Learn

Short lessons with real code you can edit and run on the page.

Installing PHP

Optional PHP 8.5 Runs in your browser
In short

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 -v names the installed version on the first line of its output, as in PHP 8.6.0 (cli).
  • A Windows PATH entry for PHP has to name the folder that holds php.exe, such as C:\php, because an entry naming php.exe itself is ignored.
  • The PHP 8.6.0 zip for Windows comes without a php.ini file, so php --ini reports (none) as the loaded configuration file.
  • Without a php.ini that sets extension_dir, PHP for Windows looks for extensions in C:\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.

  1. Download PHP. On php.net's Windows downloads page, find VS18 x64 Non Thread Safe and click its Zip link. For PHP 8.6.0, that's php-8.6.0-nts-Win32-vs18-x64.zip.
  2. 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.
  3. Unzip it to C:\php. Extract the files so that php.exe ends up at C:\php\php.exe. PHP looks for its extensions, parts of PHP that add features, in C:\php\ext by default, so this folder saves you a setting later.
  4. Create php.ini. In C:\php, copy php.ini-development and rename the copy to php.ini. PHP reads its settings from a php.ini next to php.exe, and the development version shows error messages, which helps while you learn.
  5. Add C:\php to PATH. PATH is the list of folders Windows searches for programs, and adding C:\php to it lets you type php in any folder.
  6. Check it. Open a new terminal and run php -v. It should print a line that starts with PHP 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.

Terminal
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.

  1. Search the Start menu for environment and open Edit the system environment variables.
  2. Choose Environment Variables.
  3. Under System variables, select Path and choose Edit.
  4. 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.

Terminal
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.

Terminal
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.

PHP versions by install method in November 2026, with php.net security support dates
Install methodPHP versionphp.net security fixes until
Windows zip from php.net8.6.0December 31, 2030
winget on Windows8.6.0December 31, 2030
Homebrew on macOS8.6.0December 31, 2030
XAMPP, newest release8.5.13December 31, 2029
Ubuntu 26.04 LTS8.5December 31, 2029
Ubuntu 24.04 LTS8.3December 31, 2027
Ubuntu 22.04 LTS8.1Ended December 31, 2025
Debian 138.4December 31, 2028
Debian 128.2December 31, 2026
Fedora 44 and 458.5December 31, 2029
Fedora 438.4December 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.

Terminal
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.

PHP
<?php
echo "This script runs on PHP ", phpversion(), ".\n";
Output
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.

Command Prompt
'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.

  1. Check the PATH. Run where php in Command Prompt or Get-Command php in PowerShell to search the PATH for php.exe. When it finds nothing, no folder on the PATH holds php.exe.
  2. Add its folder to PATH. Follow the PATH steps for Windows with the folder that holds php.exe, such as C:\php. For XAMPP installed in C:\xampp, that folder is C:\xampp\php.
  3. 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.

Terminal
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.

Output
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.exe is ignored. Enter the folder, C:\php.
  • The PATH entry has a space at the end. Windows skips C:\php typed with a trailing space, even though where php still lists it, and PowerShell also skips an entry wrapped in quotes. A trailing backslash, as in C:\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 of extension_dir = "ext" in php.ini.
  • Fatal error: Uncaught Error: Undefined constant "php". The terminal command php -v ended up in a PHP file, where PHP reads php as 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
<?php
php -v;
Output

Fatal error: Uncaught Error: Undefined constant "php" in /app/main.php:2
Stack trace:
#0 {main}
  thrown in /app/main.php on line 2

Exercise

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.

PHP
<?php
echo phpversion();
Output
Show the solution
<?php
echo PHP_MAJOR_VERSION;

Quiz

This quiz has 5 questions. Pick an answer to see why it is right or wrong.

  1. 1Which command prints the version of PHP installed on your computer?

  2. 2What does this script print when PHP 8.6.0 runs it?

    <?php
    echo PHP_MAJOR_VERSION;
  3. 3You added C:\php to PATH, but a Command Prompt window that was already open still says php is not recognized. What fixes it?

  4. 4Which PHP build for Windows is recommended for running scripts from the command line?

  5. 5Which command shows which php.ini file PHP loaded?

Frequently asked questions

Can I run PHP online without installing it?
Yes, the PHP lessons on this site run PHP 8.5.12 inside each lesson page. You can edit their runnable examples and run them again, while installing PHP lets you run your own .php files on your computer.
Which version of PHP should I install?
Install PHP 8.6, the newest version, released on November 19, 2026. PHP 8.2 to 8.5 still get security fixes, though support for 8.2 ends on December 31, 2026.
What is the difference between Thread Safe and Non Thread Safe PHP?
Thread Safe builds are for running PHP as a module inside a multithreaded web server such as Apache. Non Thread Safe builds are for single-threaded use, such as the command line or FastCGI with IIS, and they're the recommended choice for command-line scripts.
How do I install a PHP extension?
On Windows, remove the semicolon in front of the extension's line in php.ini, such as extension=mbstring. If PHP isn't in C:\php, also remove the one in front of the extension_dir line under On windows. On Ubuntu and Debian, install its package, such as php-curl, and restart the web server if PHP runs as its module.
Does VS Code come with PHP?
No, Visual Studio Code uses the PHP installed on your computer for its PHP checks. Install PHP first, and VS Code runs the php on your PATH or the php.exe that its php.validate.executablePath setting points to.
Can PHP run on Windows?
Yes, php.net publishes official PHP builds for 64-bit and 32-bit Windows. PHP 8.3 and newer need Windows 8 or Windows Server 2012 or later, and there are no official builds made for Windows on ARM.