简体   繁体   中英

getting 2 version of php while checking php version in ubuntu 16

Why I am getting 2 different versions of php ?

When I am checking via a php file:

<?php
 echo 'Current PHP version: ' . phpversion();

output: Current PHP version: 7.0.18-1+deb.sury.org~xenial+1

When I am checking via a terminal command:

root@dev-Inspiron-N5110:~# php -v

 PHP 7.1.4-1+deb.sury.org~xenial+1 (cli) (built: Apr 11 2017 22:12:32) 
 ( NTS )
 Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.4-1+deb.sury.org~xenial+1, Copyright (c) 1999-
 2017, by Zend Technologies

php -v giving me PHP 7.1.4-1+deb.sury.org~xenial+1 and phpversion() giving me 7.0.18-1+deb.sury.org~xenial+1 .

That is because you have two different versions installed for PHP. The PHP cli is picking up the latest one whereas Apache has been set up with php 7.0.

What you can do is remove both the PHP version from your system and then do a fresh install again:

sudo apt-get install ppa-purge
sudo ppa-purge ppa:ondrej/php-7.0
sudo apt-get purge php7.*

and then install latest PHP 7 from the official Ubuntu Repository like so:

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

as you are using Ubuntu 16 the new PHP version will be >=7

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM