Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpinfo and php -v show different version on lion

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

like image 987
fengd Avatar asked Jul 22 '12 12:07

fengd


3 Answers

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.

like image 124
Windo Avatar answered Oct 06 '22 00:10

Windo


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

like image 42
Gerardo G Avatar answered Oct 05 '22 23:10

Gerardo G


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.

like image 30
Lucas Avatar answered Oct 06 '22 00:10

Lucas