How to upgrade to PHP7


#1

You can use phpbrew on Cloud9. I found that the standard installation process works fine, just run the commands below.

We first install the libmcrypt-dev package to avoid running into dependency issues during build:

$ sudo apt-get update
$ sudo apt-get install libmcrypt-dev

Next, we download phpbrew and move it to /usr/local/bin:

$ curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew
$ chmod +x phpbrew
$ sudo mv phpbrew /usr/local/bin/
$ phpbrew init

# add this to your ~/.bashrc:
$ [[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc

$ phpbrew lookup-prefix ubuntu

Once set up, we install and load PHP 7:

$ phpbrew install 7.0 +default
$ phpbrew switch php-7.0.1
$ phpbrew use php-7.0.1
$ php -v
PHP 7.0.1 (cli) (built: Dec 29 2015 22:04:43) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies

Use PHP7 in workspaces by default
Upgrade workstation to PHP 7
Upgrade workspace to PHP latest versions
Explanation of the preinstalled apache:: Where is httpd.conf?
Terminal asks for password for ubuntu user on sudo
#2

When executing phpbrew init, Im getting:

username:~/workspace $ phpbrew init
/usr/bin/env: php: No such file or directory

Then when Im executing phpbrew lookup-prefix ubuntu, Im getting:

username:~/workspace $ phpbrew lookup-prefix ubuntu
/usr/bin/env: php: No such file or directory

#3

Hi,

Your workspace currently doesn’t have PHP installed. We’re working to add PHP back in to all workspaces as default, but till then, there are a few work arounds for this:

  1. Install PHP
    Running sudo apt-get install php5 should install PHP5 (which you can then use to update to php7)

  2. Create a PHP workspace
    You can select the PHP workspace type on https://c9.io/new which has PHP automatically installed

I hope this helps.

Regards,
​Mutahhir


#4

Im getting this error after executing your commands from a workspace with preinstalled php configuration.

This is what I got after phpbrew install 7.0 +default

username:~/workspace $ phpbrew install 7.0 +default
    [==================================================================] 3.37/3.37KB 100%
    ===> phpbrew will now build 7.0.4
    ===> Loading and resolving variants...
    ===> Downloading from http://www.php.net/get/php-7.0.4.tar.bz2/from/this/mirror
    [==================================================================] 184.00/184.00B 100%
    Redirecting to http://php.net/get/php-7.0.4.tar.bz2/from/this/mirror
    Redirecting to http://php.net/distributions/php-7.0.4.tar.bz2
    [==================================================================] 13.38/13.38MB 100%
    ===> /home/ubuntu/.phpbrew/distfiles/php-7.0.4.tar.bz2 downloaded.
    ===> Extracting /home/ubuntu/.phpbrew/distfiles/php-7.0.4.tar.bz2 to /home/ubuntu/.phpbrew/tmp/php-7.0.4
    ===> Moving /home/ubuntu/.phpbrew/tmp/php-7.0.4 to /home/ubuntu/.phpbrew/build/php-7.0.4
    ===> Configuring 7.0.4...


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


    ===> Building...

    ^C
    rodolvelasco:~/workspace $ tail -F /home/ubuntu/.phpbrew/build/php-7.0.4/build.log
    /bin/bash /home/ubuntu/.phpbrew/build/php-7.0.4/libtool --silent --preserve-dup-deps --mode=compile cc  -Iext/sysvshm/ -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/sysvshm/ -DPHP_ATOM_INC -I/home/ubuntu/.phpbrew/build/php-7.0.4/include -I/home/ubuntu/.phpbrew/build/php-7.0.4/main -I/home/ubuntu/.phpbrew/build/php-7.0.4 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/date/lib -I/usr/include/libxml2 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/oniguruma -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl/mbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/zip/lib -I/home/ubuntu/.phpbrew/build/php-7.0.4/TSRM -I/home/ubuntu/.phpbrew/build/php-7.0.4/Zend    -g -O2 -fvisibility=hidden   -c /home/ubuntu/.phpbrew/build/php-7.0.4/ext/sysvshm/sysvshm.c -o ext/sysvshm/sysvshm.lo 
    /bin/bash /home/ubuntu/.phpbrew/build/php-7.0.4/libtool --silent --preserve-dup-deps --mode=compile cc  -Iext/tokenizer/ -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/tokenizer/ -DPHP_ATOM_INC -I/home/ubuntu/.phpbrew/build/php-7.0.4/include -I/home/ubuntu/.phpbrew/build/php-7.0.4/main -I/home/ubuntu/.phpbrew/build/php-7.0.4 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/date/lib -I/usr/include/libxml2 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/oniguruma -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl/mbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/zip/lib -I/home/ubuntu/.phpbrew/build/php-7.0.4/TSRM -I/home/ubuntu/.phpbrew/build/php-7.0.4/Zend    -g -O2 -fvisibility=hidden   -c /home/ubuntu/.phpbrew/build/php-7.0.4/ext/tokenizer/tokenizer.c -o ext/tokenizer/tokenizer.lo 
    /bin/bash /home/ubuntu/.phpbrew/build/php-7.0.4/libtool --silent --preserve-dup-deps --mode=compile cc  -Iext/tokenizer/ -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/tokenizer/ -DPHP_ATOM_INC -I/home/ubuntu/.phpbrew/build/php-7.0.4/include -I/home/ubuntu/.phpbrew/build/php-7.0.4/main -I/home/ubuntu/.phpbrew/build/php-7.0.4 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/date/lib -I/usr/include/libxml2 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/oniguruma -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl/mbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/zip/lib -I/home/ubuntu/.phpbrew/build/php-7.0.4/TSRM -I/home/ubuntu/.phpbrew/build/php-7.0.4/Zend    -g -O2 -fvisibility=hidden   -c /home/ubuntu/.phpbrew/build/php-7.0.4/ext/tokenizer/tokenizer_data.c -o ext/tokenizer/tokenizer_data.lo 
    /bin/bash /home/ubuntu/.phpbrew/build/php-7.0.4/libtool --silent --preserve-dup-deps --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/xml/ -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/xml/ -DPHP_ATOM_INC -I/home/ubuntu/.phpbrew/build/php-7.0.4/include -I/home/ubuntu/.phpbrew/build/php-7.0.4/main -I/home/ubuntu/.phpbrew/build/php-7.0.4 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/date/lib -I/usr/include/libxml2 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/oniguruma -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl/mbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/zip/lib -I/home/ubuntu/.phpbrew/build/php-7.0.4/TSRM -I/home/ubuntu/.phpbrew/build/php-7.0.4/Zend    -g -O2 -fvisibility=hidden   -c /home/ubuntu/.phpbrew/build/php-7.0.4/ext/xml/xml.c -o ext/xml/xml.lo 
    /bin/bash /home/ubuntu/.phpbrew/build/php-7.0.4/libtool --silent --preserve-dup-deps --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/xml/ -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/xml/ -DPHP_ATOM_INC -I/home/ubuntu/.phpbrew/build/php-7.0.4/include -I/home/ubuntu/.phpbrew/build/php-7.0.4/main -I/home/ubuntu/.phpbrew/build/php-7.0.4 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/date/lib -I/usr/include/libxml2 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/oniguruma -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl/mbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/zip/lib -I/home/ubuntu/.phpbrew/build/php-7.0.4/TSRM -I/home/ubuntu/.phpbrew/build/php-7.0.4/Zend    -g -O2 -fvisibility=hidden   -c /home/ubuntu/.phpbrew/build/php-7.0.4/ext/xml/compat.c -o ext/xml/compat.lo 
    /bin/bash /home/ubuntu/.phpbrew/build/php-7.0.4/libtool --silent --preserve-dup-deps --mode=compile cc  -Iext/xmlreader/ -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/xmlreader/ -DPHP_ATOM_INC -I/home/ubuntu/.phpbrew/build/php-7.0.4/include -I/home/ubuntu/.phpbrew/build/php-7.0.4/main -I/home/ubuntu/.phpbrew/build/php-7.0.4 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/date/lib -I/usr/include/libxml2 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/oniguruma -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl/mbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/zip/lib -I/home/ubuntu/.phpbrew/build/php-7.0.4/TSRM -I/home/ubuntu/.phpbrew/build/php-7.0.4/Zend    -g -O2 -fvisibility=hidden   -c /home/ubuntu/.phpbrew/build/php-7.0.4/ext/xmlreader/php_xmlreader.c -o ext/xmlreader/php_xmlreader.lo 
    /bin/bash /home/ubuntu/.phpbrew/build/php-7.0.4/libtool --silent --preserve-dup-deps --mode=compile cc  -Iext/xmlwriter/ -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/xmlwriter/ -DPHP_ATOM_INC -I/home/ubuntu/.phpbrew/build/php-7.0.4/include -I/home/ubuntu/.phpbrew/build/php-7.0.4/main -I/home/ubuntu/.phpbrew/build/php-7.0.4 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/date/lib -I/usr/include/libxml2 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/oniguruma -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl/mbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/zip/lib -I/home/ubuntu/.phpbrew/build/php-7.0.4/TSRM -I/home/ubuntu/.phpbrew/build/php-7.0.4/Zend    -g -O2 -fvisibility=hidden   -c /home/ubuntu/.phpbrew/build/php-7.0.4/ext/xmlwriter/php_xmlwriter.c -o ext/xmlwriter/php_xmlwriter.lo 
    /bin/bash /home/ubuntu/.phpbrew/build/php-7.0.4/libtool --silent --preserve-dup-deps --mode=compile cc  -Iext/xsl/ -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/xsl/ -DPHP_ATOM_INC -I/home/ubuntu/.phpbrew/build/php-7.0.4/include -I/home/ubuntu/.phpbrew/build/php-7.0.4/main -I/home/ubuntu/.phpbrew/build/php-7.0.4 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/date/lib -I/usr/include/libxml2 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/oniguruma -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl/mbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/zip/lib -I/home/ubuntu/.phpbrew/build/php-7.0.4/TSRM -I/home/ubuntu/.phpbrew/build/php-7.0.4/Zend    -g -O2 -fvisibility=hidden   -c /home/ubuntu/.phpbrew/build/php-7.0.4/ext/xsl/php_xsl.c -o ext/xsl/php_xsl.lo 
    /bin/bash /home/ubuntu/.phpbrew/build/php-7.0.4/libtool --silent --preserve-dup-deps --mode=compile cc  -Iext/xsl/ -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/xsl/ -DPHP_ATOM_INC -I/home/ubuntu/.phpbrew/build/php-7.0.4/include -I/home/ubuntu/.phpbrew/build/php-7.0.4/main -I/home/ubuntu/.phpbrew/build/php-7.0.4 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/date/lib -I/usr/include/libxml2 -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/oniguruma -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/mbstring/libmbfl/mbfl -I/home/ubuntu/.phpbrew/build/php-7.0.4/ext/zip/lib -I/home/ubuntu/.phpbrew/build/php-7.0.4/TSRM -I/home/ubuntu/.phpbrew/build/php-7.0.4/Zend    -g -O2 -fvisibility=hidden   -c /home/ubuntu/.phpbrew/build/php-7.0.4/ext/xsl/xsltprocessor.c -o ext/xsl/xsltprocessor.lo 
    make: *** [ext/xsl/xsltprocessor.lo] Error 1

Hope I’m not creating noise into your topic with my replies.

Hope you guys can give me a hand configuring this ws.

Thanks in advanced.


#5

You accidently pressed Ctrl C :

As you can see that ^C Represents Ctrl C… And ctrl c goes out of the script your running…


#6

But when i am on this line: $ phpbrew use php-7.0.1

It gives me the error:

bash: Invalid: command not found

#7

How long does it take your command to build the files after executing phpbrew install 7.0 +default?


#8

A verry verrrry long time(15 minutes :smiley: )


#9

Right now Im having your same problem.

bash: Invalid: command not found

#10

When I run $ phpbrew switch php-7.0.4 , I got the message below ;

:~/workspace $ phpbrew switch php-7.0.1 Invalid argument php-7.0.1


OK I got the solution

source $HOME/.phpbrew/bashrc


#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