How to upgrade to PHP7


#12

This is how I installed php 7. I made this in order to install a symfony 2 project.

sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update -y

sudo apt-get install php7.0-curl php7.0-dev php7.0-gd php7.0-intl php7.0-mcrypt php7.0-json php7.0-mysql php7.0-opcache php7.0-bcmath php7.0-mbstring php7.0-soap php7.0-xml
apt-get install libapache2-mod-php7.0 -y

sudo apt-get install gcc make autoconf libc-dev pkg-config -y
sudo pecl install apcu -y

sudo bash -c "echo extension=apcu.so > /etc/php/7.0/cli/conf.d/20-apcu.ini"
sudo bash -c "echo extension=apcu.so > /etc/php/7.0/fpm/conf.d/20-apcu.ini"
sudo bash -c "echo extension=apcu.so > /etc/php/7.0/apache2/conf.d/20-apcu.ini"

Hope it works for you guys.


PHPBrew and Apache
#13

This worked for me, thanks @rodolvelasco!

@jamie07051975 have a look at this as this got PHP7 working for me with Apache.

@PhpCoder231 I also got the same error you mentioned but not sure why. These instructions are taken directly from the PHPBrew repository on Github. Try these commands above.


#14

Brill - thanks for that!


#15

When I enter php -v I get PHP 7.0.6 (cli) (built: May 1 2016 08:12:21) ( NTS )

But phpinfo() still displays PHP Version 5.5.9-1ubuntu4.14

Is there something I need to do for the two to sync?


#16

I have the same problem that paulkd, after trying switching to php7 both using phpbrew and ppa repository (sudo add-apt-repository ppa:ondrej/php) - php -v points to new 7.0.7 from homebrew, but not apache.
service apache2 restart does not affect apache version.

I looked at apache2.conf, but couldn’t find any settings related to php interpreter version, not in conf.d

Please help!


#17

I had the same problem. You have to disable the php5 module in apache2 and then enable the php7 module:

$ sudo a2dismod php5
$ sudo a2enmod php7.0

When I did this I got an error ‘could not parse envvars’ but I solved this by temporarily renaming this file in the /etc/apache2 directory. The restart apache and now it worked for me.

If you do not see php7.0 module then do the following:

$ sudo add-apt-repository ppa:ondrej/php -y
$ sudo apt-get update -y

$ sudo apt-get install php7.0-curl php7.0-dev php7.0-gd php7.0-intl php7.0-mcrypt php7.0-json php7.0-mysql php7.0-opcache php7.0-bcmath php7.0-mbstring php7.0-soap php7.0-xml

$ sudo apt-get install libapache2-mod-php7.0 -y

Now you should be able to enable the module.


#18

Thanks I updated the PHP version. Is there any way to update the syntax highlighting?

E.g. for:

// importing a function (PHP 5.6+)
use function My\Full\functionName;

The current highlighting is 5.5


#19

Anyone still struggling I have included a list of commands to upgrade to php7 as part of my post here Laravel 5.3 Installation on Cloud9


#20

It works for me. Thank you very much!


#21

If anyone is trying the solution OP posted, you may encounter a problem when you run
$ phpbrew switch php-7.0.1
You may get an error along the lines of:
bash: Invalid: command not found

This is because the version of PHP installed has changed, so you need to change the version you switch to as well. To find which is the current version, run $ phpbrew list

$ phpbrew list
* (system)
  php-7.0.16     
  php-5.6.30     

Adapt the remaining commands as appropriate i.e.

$ phpbrew switch php-7.0.16
$ phpbrew use php-7.0.16
$ php -v
PHP 7.0.16 (cli) (built: Jun  5 2017 06:03:59) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

#22

Thank you, I upgraded PHP5 to PHP7 with the help of your comment.


#23

This article is not ok, because apache still keeps using the older version of PHP


#24

This is what i get :

 $ phpbrew install 7.0 +default
===> phpbrew will now build 7.0.24
===> Loading and resolving variants...
Downloading http://www.php.net/get/php-7.0.24.tar.bz2/from/this/mirror via curl extension
[==================================================================] 184.00/184.00B 100%
Redirecting to http://php.net/get/php-7.0.24.tar.bz2/from/this/mirror
Redirecting to http://php.net/distributions/php-7.0.24.tar.bz2
[==================================================================] 13.95/13.95MB 100%
===> Extracting /home/ubuntu/.phpbrew/distfiles/php-7.0.24.tar.bz2 to /home/ubuntu/.phpbrew/build/tmp.1508371882/php-7.0.24
===> Moving /home/ubuntu/.phpbrew/build/tmp.1508371882/php-7.0.24 to /home/ubuntu/.phpbrew/build/php-7.0.24
===> Checking patches...
Checking patch for replace apache php module name with custom version name
===> Configuring 7.0.24...


Use tail command to see what's going on:
   $ tail -F /home/ubuntu/.phpbrew/build/php-7.0.24/build.log


Error: Configure failed:
The last 5 lines in the log file:
checking for cURL in multiarch path... not found

./configure: line 410: test: please: integer expression expected

configure: error: reinstall

./configure: line 299: return: please: numeric argument required

./configure: line 309: exit: please: numeric argument required

Please checkout the build log file for more details:
         tail /home/ubuntu/.phpbrew/build/php-7.0.24/build.log

#25

For anyone still needing to upgrade to PHP7. I wrote a bash script to make the process painless. Below is a link to the scripts GitHub page. All you need to do is run 3 commands in the terminal and you’re upgraded.

Cloud9-PHP7-Upgrade


#26

It would be great if you could make it update to PHP 7.2 :slight_smile: But this was awesome. Thank you.


#27

It would be great if you guys updated this for the latest version of PHP as this did not work for me.


#28

No promises, if I get some time I’ll give it a whirl. If you do it, please fork though github and do a pull request with the new code. So others can use it. Glad it helped none the less.

Ian


#29

To anyone who visits this nowadays, there is a script that will automatically do this for you. It is located Here.

It allows a faster way to update, and it requires 1 command.


#30

Thanks! I did find one very minor error that I opened an issue for, but it was easy to work around – after that, it worked like a charm and phpinfo(); confirms I’m on 7.0.28 now.:grinning:


#31

$ phpbrew list

  • (system)
    php-7.0.16
    php-5.6.30
    Adapt the remaining commands as appropriate i.e.

phpbrew switch php-7.0.16 phpbrew use php-7.0.16
$ php -v
PHP 7.0.16 (cli) (built: Jun 5 2017 06:03:59) ( NTS )
Copyright © 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright © 1998-2017