To install PHP, run one command for your system: winget install PHP.PHP.8.3 on Windows, brew install php on macOS, or sudo apt install php-cli on Ubuntu and Debian. Then open a new terminal and run php -v. If it prints a version number, PHP is installed.
php -v
PHP 8.3.19 (cli) (built: Mar 27 2025 11:08:15) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.19, Copyright (c) Zend Technologies
with Zend OPcache v8.3.19, Copyright (c), by Zend Technologies
Your version and build date will differ. Inside a script, the same information comes from PHP_VERSION and phpversion(). Press Run to see what this page's PHP reports:
Install PHP on Windows
The quickest route is winget, which ships with Windows 10 and 11. Open PowerShell or Windows Terminal:
winget install PHP.PHP.8.3
Close the terminal, open a new one, and run php -v. A new window is needed because terminals keep the PATH they started with.
To install by hand instead:
- Download the "VS16 x64 Non Thread Safe" zip from windows.php.net/download.
- Unzip it to a short path such as
C:\php. - Copy
php.ini-developmenttophp.iniin the same folder. - Add
C:\phpto thePathvariable (Start menu, "Edit the system environment variables", Environment Variables). - Open a new terminal and run
php -v.
If you also want Apache and MySQL in one installer, XAMPP and Laragon bundle them with PHP.
Install PHP on macOS
macOS no longer includes PHP. Install it with Homebrew:
brew install php
php -v
brew install php gives you the latest release. To pin a version, install it by name, for example brew install php@8.3. Versioned formulas are not linked by default, so add it to your PATH with the command Homebrew prints at the end of the install. brew upgrade php updates it later.
Install PHP on Linux
Ubuntu 24.04 and Debian 13 ship PHP 8.3 or newer in their own repositories:
sudo apt update
sudo apt install php-cli php-mbstring php-xml php-curl
php -v
On Fedora, RHEL and similar systems:
sudo dnf install php-cli php-mbstring php-xml
php -v
Extensions are separate packages named php-<name>: on Debian and Ubuntu php-mysql adds the MySQL drivers (php-mysqlnd on Fedora) and php-intl the intl extension. For a newer PHP than your distribution offers on Ubuntu, the widely used ppa:ondrej/php repository has every supported version:
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.3-cli
Check the PHP version in code
Libraries often need a minimum version. version_compare compares version strings the way PHP does, and PHP_VERSION_ID gives a plain integer (80300 means 8.3.0) that is easy to compare:
Check which extensions are installed
Many errors after a fresh install are a missing extension. In a terminal, php -m lists every loaded extension. In code, extension_loaded checks one by name:
Add the names your project needs (for example pdo_mysql, intl, gd) and run it on your own machine to see what to install.
Find php.ini
Settings such as display_errors, memory_limit and upload_max_filesize live in php.ini. The terminal command php --ini prints which file is loaded. From code:
The CLI and the web server can use different php.ini files, so a setting changed for one does not always apply to the other. The error reporting page shows the settings worth changing first on a development machine.
Common problem: the terminal still runs the old version
After upgrading, php -v sometimes reports the previous version. Run which php (macOS, Linux) or where php (Windows) to see which binary the terminal finds first. On macOS this is often a Homebrew version that is installed but not linked; on Windows it is usually an older folder earlier in Path, such as the one inside XAMPP. Fix the order, open a new terminal, and check again. Then continue with running PHP files.
Frequently Asked Questions
How do I check which PHP version is installed?
Run php -v in a terminal. The first line shows the version, for example PHP 8.3.19 (cli). Inside a script, echo PHP_VERSION; or echo phpversion(); prints the same number.
Why does Windows say 'php is not recognized as an internal or external command'?
The folder that contains php.exe is not on your PATH. Add it (for example C:\php) under Environment Variables, then open a new terminal window, because terminals that were already open keep the old PATH.
Which PHP version should I install?
The newest release that your project and host support. PHP 8.4 and 8.5 are in active support, 8.2 and 8.3 get security fixes only, and anything older than 8.2 gets no fixes at all. php.net/supported-versions.php lists the exact dates.
Do I need Apache or XAMPP to run PHP?
No. PHP runs scripts from the terminal with php file.php, and php -S localhost:8000 starts a development web server. XAMPP, MAMP and Laragon are bundles that add Apache and MySQL, which is useful when you also need a database.