Install and Configure PHP 7.1 on Cloud 9 Workspaces

Joe • July 6, 2017

community general linux php projects speaking ubuntu

July 8th I'm giving a general PHP training day at the Fedex Institute of Technology and because I'm targeting absolute beginners I wanted to use Cloud 9. Cloud 9 is an online editor that gives you a full linux workspace to build your project in. The first thing I noticed was the container Cloud 9 provides is running PHP 5.5.

I've created a simple bash script to update PHP to 7.1 and update apache:

`install.sh`:

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

sudo apt-get install php7.1-curl php7.1-cli php7.1-dev php7.1-gd php7.1-intl php7.1-mcrypt php7.1-json php7.1-mysql php7.1-opcache php7.1-bcmath php7.1-mbstring php7.1-soap php7.1-xml php7.1-zip -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.1 -y
sudo cp /etc/apache2/envvars.bak /etc/apache2/envvars

sudo a2dismod php5
sudo a2enmod php7.1

sudo service apache2

I've also added it to a Github Repo so you can clone that repo into a new workspace and you'll start the workspace with the script ready to run:

Create Cloud 9 Workspace

Create Cloud 9 Workspace

Once your workspace is ready, open the bash tab and run `sh install.sh`. When the command is complete, run your project and navigate to your project's URL and click on the info.php file. You should see similar output:

PHP 7.1 on Cloud 9

PHP 7.1
on Cloud 9

Hope this helped someone out or saved you some time. Thanks for reading.