exec("php -v”) vs phpinfo() -- different php version

This happens because you've still got the older PHP binary installed (probably in /usr/bin).

When you change your PATH environment variable on the command to include /usr/local/bin - this means that the shell also searches that folder (and in that order) to find the program you want to run. In this case when you run php, it finds the new version in /usr/local/bin and runs that for you.

However that PATH environment variable change is local to that shell session only. It is not saved anywhere, and not used in other contexts.

Thus when you run the phpinfo.php script through the web server, it runs with a standard PATH that doesn't include /usr/local/bin. Thus the older PHP binary is run - showing the old version number.

It really doesn't matter at all - why would you want to run a PHP binary from a PHP script run by the webserver anyways?

In case you really wanted to do that and wanted it "fixed", you could do that by either changing your exec() call to include the full path:

exec("/usr/local/bin/php -v" , $out);

or by changing the PATH environment variable for in your PHP script context.