Use php -v to check the PHP version available in the command line, but use phpinfo() to confirm what your website actually runs. Hosting compatibility problems often come from a mismatch between these two environments. A site can run PHP 8.1 in the browser while SSH reports PHP 8.3, which is exactly the kind of tiny detail that wastes an afternoon.
TLDR: php -v shows the PHP version used by the terminal, cron jobs, Composer, and command line scripts. phpinfo() shows the PHP version used by the web server, such as Apache, Nginx with PHP FPM, or LiteSpeed. For example, a WordPress store may show PHP 8.2 in cPanel, but php -v may return 8.0 over SSH, causing Composer installs to fail. In one common hosting support pattern, roughly 30% of “PHP version” tickets are really CLI versus web PHP mismatches.
Why two PHP version checks exist
PHP can run in more than one place. It can run from the terminal. It can also run through a web server when someone loads a page. These two paths do not always use the same PHP binary, configuration file, extensions, or memory limits.
This is where php -v and phpinfo() differ. They answer similar questions, but not the same one.
php -vanswers: “What PHP version runs when I type PHP commands in the terminal?”phpinfo()answers: “What PHP version runs when my website is loaded in a browser?”
The catch is that many hosting panels let you set the website PHP version without changing the SSH PHP version. So the hosting dashboard says one thing, the command line says another, and your application behaves like it has a personal grudge.

How to check PHP with php -v
If you have SSH access, checking the CLI version is quick. Open your terminal, connect to the server, and run:
php -vYou may see output like this:
PHP 8.2.18 (cli) (built: Apr 10 2024 12:34:56)
Copyright (c) The PHP Group
Zend Engine v4.2.18The key word is cli. That means “command line interface.” This version is used by tools such as:
- Composer, when installing packages
- WP CLI, when managing WordPress from SSH
- Cron jobs, when scheduled tasks run
- Laravel Artisan, when running migrations or queues
- Custom scripts, when called from the shell
If Composer says your PHP version is too old, php -v is usually the first thing to check. A package may require PHP 8.1 or higher, while your CLI still points to PHP 7.4. The website might work fine, but the install fails anyway.
Useful command line checks beyond php -v
php -v gives the version, but it does not show the whole story. These commands help expose the exact binary and config being used:
which phpshows the PHP executable path.php --inishows the loadedphp.inifiles.php -mlists enabled PHP extensions.php -iprints detailed PHP configuration in the terminal.
For example:
which php
/usr/bin/php
php --ini
Loaded Configuration File: /etc/php/8.2/cli/php.iniThat cli folder matters. It tells you this configuration belongs to terminal PHP, not necessarily the PHP used by your site.
How to check PHP with phpinfo()
To check the PHP version used by the website, create a small PHP file in the public web folder. Name it something temporary, such as phpinfo-check.php.
<?php
phpinfo();
Upload it to your site, then open it in the browser:
https://example.com/phpinfo-check.phpAt the top of the page, you should see something like:
PHP Version 8.1.27This is the version being used by web requests. It is the version your visitors, CMS, plugins, themes, and public PHP files use.
Delete the file after checking. Seriously. phpinfo() exposes server paths, loaded modules, environment details, and configuration values. It is useful for debugging, but it should not sit on a live site for weeks. It drives me crazy how often forgotten phpinfo files show up in basic security scans.

When php -v and phpinfo() disagree
A mismatch is common on shared hosting, managed WordPress hosting, VPS setups, and servers with multiple PHP versions installed. You might see:
php -v: PHP 8.3 CLIphpinfo(): PHP 8.1 FPM
Or the reverse:
php -v: PHP 7.4 CLIphpinfo(): PHP 8.2 Apache module
Neither result is automatically wrong. They are just reporting different layers of the hosting setup. The problem starts when your tools assume both layers match.
Hosting compatibility problems this can reveal
Checking both versions helps diagnose issues that look mysterious at first. Common examples include:
- Composer errors: Dependencies refuse to install because CLI PHP is too old.
- Plugin crashes: A plugin requires PHP 8.1, but the website is still on 7.4.
- Cron failures: Scheduled jobs run under an older PHP version than the web app.
- Missing extensions: The website has
mysqli, but CLI PHP does not. - Different memory limits: Browser requests get 256 MB, while CLI scripts get 128 MB.
Expect to waste time on these if you only check one side. A Laravel queue can fail under CLI PHP while the homepage loads perfectly. A WordPress migration script can crash from SSH even though the admin dashboard says the server meets all requirements.
Which one should you trust?
Trust the check that matches the problem.
- If the website is broken, trust
phpinfo(). - If Composer is failing, trust
php -v. - If a cron job fails, check CLI PHP and the cron command path.
- If a plugin compatibility warning appears in the browser, check web PHP.
- If WP CLI behaves differently from WordPress admin, compare both.
For the best diagnosis, compare version, loaded config file, and extensions. Version alone is useful, but it is not the full picture.
A quick checklist for hosting support
Before opening a support ticket, collect these details. It saves back and forth messages and makes the issue easier to prove.
- Output of
php -v - Output of
which php - Screenshot or copied version line from
phpinfo() - The app requirement, such as “requires PHP 8.1+”
- The exact error message from Composer, WordPress, Laravel, or another tool

Best practice: align CLI and web PHP when possible
The cleanest setup uses the same PHP version for both CLI and web requests. This reduces surprises. It also makes deployments, package installs, cron jobs, and local debugging easier to reason about.
Some hosts let you change CLI PHP in the control panel. Others require a specific command path, such as:
/usr/bin/php82 script.php
/usr/local/bin/php83 composer.phar installFor cron jobs, avoid assuming php points to the right version. Use the full path when your host provides it. That one small change can prevent a scheduled task from silently running under the wrong PHP version.
The practical rule is simple: use php -v for terminal problems, use phpinfo() for website problems, and compare both when hosting compatibility looks strange. PHP version checks are easy. Knowing which version you are checking is the part that saves real time.
