Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch between PHP 5.6 / 7.2 on Cloud9?

I use AWS Cloud9 Amazon Web Services a.k.a. Cloud9 IDE. I’m trying to achieve a setup where I can easily switch the frontend (not CLI) PHP version with PHPBrew between 5.6 and 7 whenever. For now, I’ve only achieved that the bash has the 5.6.31, the frontend phpinfo() says PHP Version 5.5.9-1ubuntu4.17 which is obviously something I don’t want to see. I’ve already managed to do this on another workspace where it says PHP Version 5.6.31, but I’m afraid to touch that workspace to venture into trying to switch to PHP 7. I have no idea how I achieved to make the PHPBrew version the system level PHP…

I’ve read the related topics and questions but they aren’t helping me. This is how I set it up for now:

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 that I have no earthly idea what I’m doing, I never used Linux. I just collected these lines from threads like this and they looked promising, but I must be missing something.

Additional info (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'd ideally switch with phpbrew switch after I have both 5.6.31 and 7 installed. For now, I'd be satisfied if I could just get it to work with 5.6.31

For now, what I did was to switch the "runner" (not sure what that is) from PHP (built-in web server) to Apache httpd (PHP, HTML) here: https://i.snag.gy/Y6eNHy.jpg Then the phpinfo() was actually showing the phpbrew version. Then I also installed PHP 7.2.1 but then everything stopped working. I get lots of errors in the console of c9: https://i.snag.gy/pt5oHN.jpg Beautiful, isn't it? :)

Started apache2
/mnt/shared/bin/run-apache2: line 70:  4813 Segmentation fault      apache2
like image 689
Firsh - justifiedgrid.com Avatar asked Jan 23 '18 13:01

Firsh - justifiedgrid.com


People also ask

How do I run multiple PHP versions in Ubuntu?

Add a PHP Repository By default, Ubuntu 20.04 ships with the PHP version 7.4. So you'll need to add the PHP repository in your system to install the multiple PHP versions. Once the repository is up-to-date, you can proceed to install multiple PHP versions.


3 Answers

I've completely ditched phpbrew as it's not really for switching Apache's PHP, just CLI (by design). It was never supposed to work, see: this is still a feature request.

Started with a clean Cloud9 PHP/Apache workspace. I followed this article How to Install PHP 5.6, PHP 7.1 on Ubuntu 16.04, 14.04 using PPA and based on that, this is how it turned out:

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 verify:

php5.6 -v
php7.2 -v

I ran into an error after installing php7.2:

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

That I fixed following the advice "Upgrade your libpcre3 library to version from the repository."

Turns out that was "kept back" so I had to do this:

apt-get install libpcre3 libpcre3-dev

PHP 7.2 started to work! Surprisingly, Cloud9's original PHP is left intact, that lives on under php5 and can be used anytime. So I can now juggle 3 different versions. Yes, phpinfo() shows the version I want every time! Re-running the Cloud9 worker is not even necessary.

The mbstring will be missing for 5.6 (ran into the 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

Switch from anything 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

Switch 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

Switch from anything to original 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'm very happy.

like image 101
Firsh - justifiedgrid.com Avatar answered Oct 21 '22 11:10

Firsh - justifiedgrid.com


// PHP version upgrade (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
like image 32
Julius Simanavičius Avatar answered Oct 21 '22 10:10

Julius Simanavičius


The following will upgrade 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?

like image 2
Fifi Avatar answered Oct 21 '22 11:10

Fifi