2

I have installed PHP 7 on Ubuntu:

php -v
PHP 7.0.5-2+deb.sury.org~trusty+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

It appears that right version is loaded:

php -i | grep "Loaded Configuration File"
Loaded Configuration File => /etc/php/7.0/cli/php.ini

However phpinfo() still reports old version:

PHP Version 5.5.9-1ubuntu4.14

How do I change it? Thanks!

This is OS version:

 lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:        14.04
Codename:       trusty

I am trying to run latest Magento 2 from Git

leon
  • 1,412
  • 2
  • 17
  • 26
  • I assume you restarted the web server. Whatever the case, `phpinfo.php` reports the PHP installation that the web server uses. Try `which php` and see which installation that is. Then see if this [digitalocean tutorial](https://www.digitalocean.com/community/tutorials/how-to-upgrade-to-php-7-on-ubuntu-14-04) helps. It shows how to upgrade the web server. – Steve Johnson Apr 11 '16 at 19:01
  • yes, restarted many times. Yes, followed all different tutorials (including Digitalocean).$ which php /usr/bin/php. So looks like even which is not pointing to the correct php – leon Apr 11 '16 at 20:01

5 Answers5

3

for enabling php5 to php 7 after install

sudo a2dismod php5.6 

sudo a2enmod php7.0 

sudo service apache2 restart

for enabling php7 to php 5 after install

sudo a2dismod php7.0 

sudo a2enmod php5.6 

sudo service apache2 restart
Dhivin
  • 646
  • 6
  • 20
2

I was wondering the same thing while working on different versions of Silverstripe...

Dhivin's answer was very close, but was missing out a couple of extra changes for PHP CLI. The lines that worked for me were:

From PHP 7.0 to 5.6

sudo update-alternatives --set php /usr/bin/php5.6

From PHP 5.6 to 7.0

sudo update-alternatives --set php /usr/bin/php7.0

Add the above lines to Dhivin's answer, and it should work for you :).

Rob
  • 1,272
  • 6
  • 24
  • 35
0

To install PHP 7 on Ubuntu 14, enter the following commands in the order shown:

sudo apt-get -y update
sudo add-apt-repository ppa:ondrej/php
sudo apt-get -y update
sudo apt-get install -y php7.0 libapache2-mod-php7.0 php7.0 php7.0-common php7.0-gd php7.0-mysql php7.0-mcrypt php7.0-curl php7.0-intl php7.0-xsl php7.0-mbstring php7.0-zip php7.0-bcmath php7.0-iconv

Enter the following command to verify PHP 7 installed properly:

php -v
VIPIN A ROY
  • 1,761
  • 5
  • 28
  • 41
0

From PHP 5.6 To PHP 7.1

$ sudo a2dismod php5.6
$ sudo a2enmod php7.1
$ sudo service apache2 restart
$ update-alternatives --set php /usr/bin/php7.1

From PHP 7.1 to PHP 5.6

$ sudo a2dismod php7.1
$ sudo a2enmod php5.6
$ sudo service apache2 restart
$ sudo update-alternatives --set php /usr/bin/php5.6
-1

You can purge all php and install new

sudo aptitude purge dpkg -l | grep php| awk '{print $2}' |tr "\n" " "

or just disable unnecessary php module and enable php7

see there https://stackoverflow.com/a/38230807/1893211

Community
  • 1
  • 1
Sasa Jovanovic
  • 324
  • 2
  • 14