Checking the active PHP version before a deployment, extension change, or upgrade prevents one of the easiest runtime mismatches to miss. A shell session can report one interpreter while the application is actually served by a different build with older syntax support, different deprecation behavior, or a separate extension set.
Version checks in PHP are runtime-specific. The CLI binary reports the interpreter resolved in the current shell, while the web-facing runtime reports the SAPI behind the site such as apache2handler or fpm-fcgi, and each runtime can load its own configuration files and extensions.
The safest workflow is to confirm the CLI version first, then query the web-served runtime only when the site might not use the same interpreter. Hosts that mix distro packages, Homebrew, control panels, or custom builds often keep multiple binaries on one machine, so compare the reported version with the executable path and active configuration files before assuming every request is using the same PHP branch.
Related: How to show loaded PHP extensions
$ php -v
PHP 8.5.4 (cli) (built: Mar 10 2026 23:15:23) (NTS)
Copyright (c) The PHP Group
Built by Homebrew
Zend Engine v4.5.4, Copyright (c) Zend Technologies
with Zend OPcache v8.5.4, Copyright (c), by Zend Technologies
The first line is the decisive answer: the dotted PHP release and the cli SAPI. Build strings and loaded extension lines vary by package source.
$ php -r 'printf("Version: %s\nVersion ID: %d\nSAPI: %s\n", PHP_VERSION, PHP_VERSION_ID, PHP_SAPI);'
Version: 8.5.4
Version ID: 80504
SAPI: cli
PHP_VERSION_ID is the integer form used for version comparisons, and PHP_SAPI identifies which runtime answered the command.
$ command -v php /opt/homebrew/bin/php
A mismatch often means another PHP binary appears earlier in PATH than the runtime that was expected.
$ php --ini Configuration File (php.ini) Path: "/opt/homebrew/etc/php/8.5" Loaded Configuration File: "/opt/homebrew/etc/php/8.5/php.ini" Scan for additional .ini files in: "/opt/homebrew/etc/php/8.5/conf.d" Additional .ini files parsed: (none)
These paths belong only to the CLI runtime that answered the command.
Related: How to find PHP configuration files
<?php header('Content-Type: text/plain'); printf("Version: %s\n", PHP_VERSION); printf("Version ID: %d\n", PHP_VERSION_ID); printf("SAPI: %s\n", PHP_SAPI); ?>
A narrow text probe keeps the check focused on version and runtime identity. phpinfo() also shows the version, but it exposes much more configuration and environment data than this job needs.
Keep the probe temporary and place it in the same site, virtual host, or pool that serves the application. Leaving it reachable still exposes runtime details.
$ curl -s https://portal.example.net/php-version-check.php Version: 8.3.6 Version ID: 80306 SAPI: apache2handler
apache2handler means the site is using the Apache module. PHP-FPM deployments commonly report fpm-fcgi instead, and either value can differ from the CLI runtime.
$ rm /var/www/portal.example.net/public/php-version-check.php
Leaving the probe reachable after the check exposes version and runtime details with no operational benefit.