v and phpinfo()

I don't understand at all why :

php -v
(or) php -m

return : PHP 7.0

and phpinfo() says I am using PHP 5.

it's strange, any idea?


I'm using Ubuntu and Nginx. Below is a printscreen :

在这里输入图像描述


It's not strange. php -v runs php-cli , which in turn reads a different ini file. phpinfo() is evaluated by your webserver, which reads a webserver-specific ini file.

In case of Ubuntu, those are: /etc/phpX/apache2/php.ini and /etc/phpX/cli/php.ini , for nginx in your case it uses php-fpm , whose config is located in /etc/phpX/fpm/php.ini .


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


To get a feeling of how this works - create a file anywhere on the filesystem inside your web folder, say, called test.php with the following content:

<?

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'll see that cli PHP will report version 7.0, whereas nginx will keep reporting PHP5.


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

Disable PHP5 module on Apache:

sudo a2dismod php5

Now enable PHP7:

sudo a2enmod php7.1

To reflect changes Apache restart is required:

sudo systemctl restart apache2
链接地址: http://www.djcxy.com/p/88206.html

上一篇: 在iOS中集成Google和Facebook登录

下一篇: v和phpinfo()