There is rarely one PHP version on a machine. The command line has one, the web server may load another, and a hosting control panel can set a third per site. Checking the version means checking the one that matters for what you are doing. Here are the commands and pages for each, and what to do when they disagree.
The command line#
php -v
# PHP 8.4.6 (cli) (built: ...)
php --ini # which php.ini the CLI loads
which php # macOS/Linux: where the php binary is
where.exe php # Windows
This is the PHP that runs scripts you type, Composer, Artisan and cron jobs. It is not necessarily what serves web pages. Note the word (cli) in the output: it is a separate build with its own configuration file.
The web server#
The only reliable way to know what version serves your pages is to ask a page:
<?php echo phpversion(); // just the number
<?php phpinfo(); // everything: version, php.ini path, loaded extensions
Save either as version.php in the web root, open it in a browser, then delete it. The phpinfo page also shows Server API — Apache module, FPM/FastCGI, CGI — and Loaded Configuration File, both of which explain why the web server behaves differently from the CLI.
WordPress#
WordPress shows the PHP version its web server is using without any file uploads: Tools, Site Health, Info tab, Server section. It lists the version, the server API, memory limits and more. Every “PHP version” plugin reads the same value with phpversion(); you do not need one.
For WP-CLI users, wp --info prints the CLI PHP version, which again can differ from the site’s.
Why they differ#
- Two installations. A distribution package and a manual or Homebrew install, each with its own binary. The PATH decides which the CLI gets; the web server’s configuration decides which it loads.
- PHP-FPM pools. With FPM, each site’s pool can point at a different PHP version. The CLI knows nothing about pools.
- Hosting panels. cPanel, Plesk and similar let you set the PHP version per site or per directory, sometimes through a
.htaccesshandler line. The SSH shell may have a generic default. - Docker. The container has its own PHP entirely;
php -von the host tells you about the host.
Specific setups#
# Docker: ask inside the container
docker exec my-app php -v
docker compose exec app php -v
# Homebrew on macOS: which versions are installed and linked
brew list | grep php
brew info php
# Debian/Ubuntu with several versions
update-alternatives --display php
ls /etc/php/ # one folder per installed version
# Windows XAMPP: the bundled PHP
C:\xampp\php\php.exe -v
On shared hosting, the control panel’s PHP selector is authoritative for the web; the SSH shell usually offers versioned binaries such as php84 alongside a default php.
Checking from inside the application#
echo PHP_VERSION; // "8.4.6"
echo PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION;
if (version_compare(PHP_VERSION, '8.2.0', '<')) {
die('PHP 8.2 or newer is required.');
}
version_compare is the right way to gate on a version; string comparison gets 8.10 versus 8.9 wrong.
Making them agree#
For development, one PHP for both is simplest:
- Debian/Ubuntu:
sudo update-alternatives --set php /usr/bin/php8.4for the CLI, anda2enmod php8.4(Apache module) or switching the FPM pool for the web. - Homebrew:
brew unlink [email protected] && brew link [email protected], then restart the web server or FPM service. - Windows: put the intended PHP folder first on the PATH, and point Apache’s
LoadModuleor the FPM configuration at the same folder.
Then confirm both: php -v and the version page. In production, decide the version per site in the server or panel configuration and treat the CLI as separate; run maintenance scripts with an explicit versioned binary where it matters.
Questions people ask#
Which PHP version should I be on?
A supported one: 8.3 or 8.4 for the widest library support in 2026, 8.5 if your dependencies allow. Anything below 8.1 no longer receives security fixes.
Can two sites on one server run different PHP versions?
Yes, with PHP-FPM: one pool per version, each site’s virtual host pointing at its pool. Hosting panels do this for you.
Why does php -v show a version I did not install?
The operating system or a tool such as XAMPP or MAMP bundled it, and it is earlier on the PATH. which php or where.exe php shows the path.
Does Composer use the CLI version?
Yes. If the web server runs a newer PHP than the CLI, Composer may refuse packages the site could actually run. Set platform.php in composer.json or align the versions.
Where to go next#
- PHP 7 vs PHP 8 — if the number is lower than you hoped.
- PHP not working with Apache after an upgrade — when the web version changed underneath you.
- What’s new in PHP 8.5 — the current release.