How to switch between PHP 5.6 / 7.2 on Cloud9?

I am using AWS Cloud9 Amazon Web Services aka Cloud9 IDE. I am trying to achieve an installation where I can easily switch the PHP version of the interface (not the CLI) with PHPBrew between 5.6 and 7 each time. At the moment, Ive only achieved that bash has 5.6.31, the phpinfo() interface says PHP Version 5.5.9-1ubuntu4.17, which is obviously what I don't want to see. Ive already managed to do this on another workspace that says PHP version 5.6.31, but I'm afraid to touch this workspace to risk switching to PHP 7. I have no idea how I got to make the PHPBrew version a system level PHP. ..

I read related topics and questions, but they do not help me. Here's how I set it up:

 curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew chmod +x phpbrew sudo mv phpbrew /usr/local/bin/phpbrew phpbrew -v phpbrew init echo '[[ -e /home/ubuntu/.phpbrew/bashrc ]] && source /home/ubuntu/.phpbrew/bashrc' >> ~/.bashrc sudo apt-get update sudo apt-get install apache2-dev sudo apt-get install libcurl4-gnutls-dev sudo apt-get install libmcrypt-dev libreadline-dev sudo phpbrew install php-5.6.31 +default +dbs +mb +iconv +apxs2=/usr/bin/apxs2 

Please note: I do not know what I'm doing, I have never used Linux. I just collected these lines from such streams and they looked promising, but I have to miss something.

Additional information (requested in comments):

 $ cat /etc/apache2/mods-available/php5.load LoadModule php5_module /usr/lib/apache2/modules/libphp5.6.31.so $ phpbrew list * php-5.6.31 

I would ideally switch with phpbrew switch after I have both 5.6.31 and 7 installed. For now, I would be happy if I could just get it working with 5.6.31

Currently, I decided to switch the “runner” (not sure what it is) from PHP (embedded web server) to Apache httpd (PHP, HTML) here: https://i.snag.gy/Y6eNHy.jpg Then phpinfo() actually showed the phpbrew version. Then I also installed PHP 7.2.1 , but then everything stopped working. I get a lot of errors in c9 console: https://i.snag.gy/pt5oHN.jpg Beautiful, isn't it? :)

 Started apache2 /mnt/shared/bin/run-apache2: line 70: 4813 Segmentation fault apache2 
+7
php ubuntu cloud9-ide cloud9 phpbrew
source share
4 answers

I completely dropped phpbrew as it is not intended to switch Apache PHP, just a CLI (by design). This should never have worked, see this is still a function request .

Starts with a clean Cloud9 PHP / Apache cloud desktop. I followed this article How to install PHP 5.6, PHP 7.1 on Ubuntu 16.04, 14.04 using PPA and based on this it happened:

 sudo apt-get install python-software-properties sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt-get install -y php5.6 sudo apt-get install -y php7.2 

Then check:

 php5.6 -v php7.2 -v 

After installing php7.2, I came across:

 $ php7.2 -v php7.2: symbol lookup error: php7.2: undefined symbol: pcre_jit_exec 

I fixed this by following the advice "Update the libpcre3 library to the version from the repository."

It turns out that it was "hidden", so I had to do this :

 apt-get install libpcre3 libpcre3-dev 

PHP 7.2 started working! Surprisingly, the original PHP Cloud9 remains untouched, which lives under php5 and can be used at any time. So now I can drag 3 different versions. Yes, phpinfo() shows the version I want every time! Repeated execution of Cloud9 desktop is not even required.

mbstring will be missing for 5.6 (ran into a problem when running phpmyadmin ):

 sudo apt-get install php5.6-mbstring 

The php.ini files are located at:

 sudo find . -name 'php.ini' ./php/7.2/apache2/php.ini ./php/7.2/cli/php.ini ./php/5.6/apache2/php.ini ./php/5.6/cli/php.ini ./php5/fpm/php.ini ./php5/apache2/php.ini ./php5/cli/php.ini 

Switching from any to 7.2 PHP

 sudo a2dismod php5 sudo a2dismod php5.6 sudo a2enmod php7.2 sudo service apache2 restart 

With 1 line:

 sudo a2dismod php5 && sudo a2dismod php5.6 && sudo a2enmod php7.2 && sudo service apache2 restart 

Switching from anything to 5.6 PHP

 sudo a2dismod php5 sudo a2dismod php7.2 sudo a2enmod php5.6 sudo service apache2 restart 

With 1 line:

 sudo a2dismod php5 && sudo a2dismod php7.2 && sudo a2enmod php5.6 && sudo service apache2 restart 

Switching from anything to source PHP from Cloud9

 sudo a2dismod php7.2 sudo a2dismod php5.6 sudo a2enmod php5 sudo service apache2 restart 

With 1 line:

 sudo a2dismod php7.2 && sudo a2dismod php5.6 && sudo a2enmod php5 && sudo service apache2 restart 

Now I am very happy.

+6
source share

// Update PHP version (from 5.6 to 7.2)

 sudo add-apt-repository ppa:ondrej/php -y sudo apt-get update -y sudo apt-get install php7.2 php-pear php7.2-curl php7.2-dev php7.2-gd php7.2-mbstring php7.2-zip php7.2-mysql php7.2-xml -y sudo mv /etc/apache2/envvars /etc/apache2/envvars.bak sudo apt-get remove libapache2-mod-php5 -y sudo apt-get install libapache2-mod-php7.2 -y sudo cp /etc/apache2/envvars.bak /etc/apache2/envvars sudo a2dismod php5 sudo a2enmod php7.2 sudo service apache2 sudo service apache2 restart 
+2
source share

You can do this through the .htaccess file by adding the following lines:

To upgrade to PHP 4.4:

 AddHandler application/x-httpd-php4 .php 

To switch to PHP 5.0:

 AddHandler application/x-httpd-php5 .php 

To switch to PHP 5.1:

 AddHandler application/x-httpd-php51 .php 

To upgrade to PHP 5.2:

 AddHandler application/x-httpd-php52 .php 

To upgrade to PHP 5.3:

 AddHandler application/x-httpd-php53 .php 

To switch to PHP 5.4:

 AddHandler application/x-httpd-php54 .php 

To switch to PHP 5.5:

 AddHandler application/x-httpd-php55 .php 

To switch to PHP 5.6:

 AddHandler application/x-httpd-php56 .php 

To switch to PHP 7:

 AddHandler application/x-httpd-php7 .php 

To switch to PHP 7.1:

 AddHandler application/x-httpd-php71 .php 
+1
source share

The following will be upgraded to PHP 7.2 on CLoud9:

 sudo add-apt-repository ppa:ondrej/php -y sudo apt-get update -y sudo apt-get install php7.2 php-pear php7.2-curl php7.2-dev php7.2-gd php7.2-mbstring php7.2-zip php7.2-mysql php7.2-xml sudo apt-get install libapache2-mod-php7.2 -y sudo a2dismod php5 sudo a2enmod php7.2 sudo service apache2 restart 

Source: How to upgrade PHP to 7.2 on Ubuntu?

0
source share

All Articles