phpinfo and php -v show different version on lion-ThrowExceptions

Exception or error:

I try to upgrade my php from 5.3.13 to 5.4.5
I’ve manually download source codes of php 5.4.5 and ./configure then sudo make install it.

after that, I run

php -v

it shows 5.4.5, while I run

<?php phpinfo(); ?>

it shows 5.3.13. what is the problem here and how to fix it. thanks

How to solve:

This is a bit of a guess answer since I don’t have a mac, but based on my Winodws experience this could only happen if you have 2 php executables and your CLI is using one and Apache is using the other.

In your phpinfo() output look for the table row Loaded Configuration File.

I’m on Windows so mine says C:\server\php\5.4.3\php.ini but of course yours will be different.

If this is not the path that you expect it to be using then you will need to make sure you change the path in your Apache’s httpd.conf file.

Once you have found the httpd.conf file find the line: PHPIniDir

When you have found this line make sure it is pointing at the correct directory for the php.ini file and restart Apache.

I would also say to check the LoadModule php5_module line is also pointing at the correct file but the chances are that this will be ok if you were using php 5.3 before.

This answer does assume that you have installed the new php version in a different directory but this is all I can think of with the information you have provided.

Answer:

I think I just came from the same problem. I’m using OSX lion and was installing PHP without brew or port was simply using PHP that came with the machine.

I was in need to install mcrypt module to the current php I’m using ( at that moment I didn’t realize that there were 2 version of PHP on my machine, and forgot how I install it ), so I install homebrew and after that installing mcrypt using brew. After the installation, I open my browser and through phpinfo() I found that the PHP version is different with the one I install mcrypt module, and so cannot make the module to work.

This is what it showed in terminal :

Windo-MBP:~ herwindoartono$ php --version
PHP 5.3.23 (cli) (built: May  4 2013 06:43:49)

and from the browser ( local apache ), by opening a php page contain phpinfo(); showing PHP 5.3.15 version.. I don’t know how I ended with different version on my machine, so I browse and I browse for solutions and found one :

Changing a line in httpd.conf should change which php version I’m using

This is how to change which PHP version to use, base on my experience :

  • Edit your httpd.conf, by typing in terminal : sudo subl /etc/apache2/httpd.conf note: subl is for sublime text 2, else you can use nano.
  • Find line LoadModule php5_module libexec/apache2/libphp5.so, comment it
  • Add below that line : LoadModule php5_module /usr/local/opt/php53/libexec/apache2/libphp5.so, for your case just change the php53 to php54.
  • Restart apache using terminal : sudo apachectl restart
  • Test phpinfo() in browser, and it come out with version I intended to use.

Reference : https://github.com/josegonzalez/homebrew-php/issues/448

I don’t have much experience in PHP, but I hope this can solve your(or everyone else) problem.

Answer:

I was facing the very same problem in Ubuntu 14.04, and I did the following:

  1. from the root directory i looked for php.ini

    find / -name php.ini

I got two different files, which means I have two different versions of php installed, so

  1. I removed all php versions

    sudo apt-get -y purge php*

  2. then reintalled desired php version (in this case 5.6)

    sudo apt-get install php5.6

Answer:

I had a simular situation, it was caused by different installation versions of php over time and the not updated searchpath in linux.

Investigate via echo $PATH.

Output for example: /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

In my case the older version 5.5.9 was in a installation path referenced before the newest version 5.5.22.
5.5.9 was installled at /usr/local/bin/ and 5.5.22 at /usr/bin/.

Adapt it to by moving the correct folder to before the wrong one, or better yet deinstall the old php version.

Answer:

If you are on ubuntu and your web server is NGNIX, and also you use of php-fpm, you should to change your ngnix config:

in /etc/ngnix/sites-available nano per your address and change the fpm version:

  location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;

then restart your ngnix

$ sudo service nginx restart

now check your php version with phpinfo() and php -v on cli.

Leave a Reply

Your email address will not be published. Required fields are marked *