When The Browser and Terminal Show Different Versions of PHP If you're seeing the browser and the terminal show different versions of PHP then something is wrong.

If you happen to see two different versions of PHP whenever you run:

  • php -v in the console and visit
  • phpinfo() in the browser

Then this usually means the version of PHP that your web server is using is different than the version of PHP your command-line is using.

Specifically, this means you likely have more than one installation, and the web server is using one version, and the terminal is using a different version (in addition to using a CLI version of the interpreter).

Of course, if you’re seeing the browser and the terminal show different versions of PHP then something is wrong. You want them to be the same, but depending on how your system is configured, then  you may need to update your environmental variables.

I was recently having issues with this with various installations of PHP installed via Homebrew and with my local installation of Valet.

This is what I did to fix it.

The Browser and Terminal Show Different Versions of PHP

I use Z-Shell and Oh My Zsh so you may need to adapt the following steps to match your shell (like if you use Bash). But the gist of everything is as follows.

First, you need to know where Homebrew has installed PHP. This can be accomplished by running in which php the terminal. It should return something like this:

And the corresponding version information, when running php -v should look like this:

Next, you need to make sure that your zshrc file includes a reference to the binary that’s output above (and it should be in this order):

Next, you’ll need to update your shell session to reload the environmental variables.

After you do that, then you should see the same version in the terminal as you see in a sample PHP file when running phpinfo().