Reputation: 4163
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 :
Upvotes: 7
Views: 5732
Reputation: 3625
If your system is like this:
ubuntu
NGNIX
php-fpm
So 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.
Upvotes: 1
Reputation: 21
You need to change default php version.
sudo update-alternatives --set php /usr/bin/php7.2
Upvotes: 2
Reputation: 8951
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
Upvotes: 0
Reputation: 30167
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.
Upvotes: 4