Another result between php -v and phpinfo ()

I do not understand why:

php -v (or) php -m 

return: PHP 7.0

and phpinfo () says I'm using PHP 5.

Strange, any idea?


I use Ubuntu and Nginx. Below is the print screen:

enter image description here

enter image description here

+7
unix php ubuntu phpinfo
source share
2 answers

This is not strange. php -v runs php-cli , which in turn reads another ini file. phpinfo() is evaluated by your web server, which reads the ini file specific to the web server.

In the case of Ubuntu it is: /etc/phpX/apache2/php.ini and /etc/phpX/cli/php.ini , for nginx in your case php-fpm , whose configuration is in /etc/phpX/fpm/php.ini .


Also, in your case, PHP7 is probably compiled or pulled from another repo. If you want nginx to pick up PHP7, you need to either compile or install php7-fpm or something on these lines. YMMV depending on how you got PHP7 on your system.


To understand how this works, create a file anywhere in the file system inside your web folder, for example, test.php with the following contents:

 <? phpinfo(); ?> 

Then try running:

 # php test.php 

and then access this file from a web browser at http://path.to.your.site.com/path/to/test.php

You will see that cli PHP will report version 7.0, while nginx will continue to report PHP5.

+4
source share

If you have this problem when upgrading from PHP5 to PHP7 on Ubuntu 14.04 with Apache, here is what helped me (credit goes here ):

Disable PHP5 module on Apache:

 sudo a2dismod php5 

Now enable PHP7:

 sudo a2enmod php7.1 

A restart of Apache is required to reflect the changes:

 sudo systemctl restart apache2 
0
source share

All Articles