Loading...
 

Edit Section: Ubuntu 16.04 LTS for Human Beans


x
 
!!!# Install new php versions and switch between them
Ubuntu 16.04 comes with php 7.0, and some php applications might still fail with php 7.0 .Therefore, in some cases, it might be sensible to have both php 7.0 and php 5.x, so that you can choose which version to use for your needs at any time. Or even better, 7.1. You need to add a new repository to have other versions of php available, and you will require the equivalent branch for a patched apache2 that will work with the other php version repository.
You can do so with:
{CODE(colors="shell")}
xavi@computer# sudo su
sudo add-apt-repository -y ppa:ondrej/php
sudo add-apt-repository -y ppa:ondrej/apache2
sudo apt-get update
sudo apt-get install php5.6 php5.6-mysql php-gettext php5.6-mbstring php-xdebug libapache2-mod-php5.6  php5.6-curl php5.6-gd php5.6-mcrypt php5.6-xml php5.6-xmlrpc libphp5.6-embed  php-memcache php5.6-intl php5.6-zip  php5.6-sqlite3  
sudo install php7.1 php7.1-mysql php-gettext php7.1-mbstring php-xdebug libapache2-mod-php7.1  php7.1-curl php7.1-gd php7.1-mcrypt php7.1-xml php-xml-parser php7.1-xmlrpc libphp7.1-embed  php-memcache php7.1-intl php7.1-zip  php7.1-sqlite3
{CODE}
Installing both php5.6 & php7.1 resulted in a lot of complaining from apt and lots of conflicts. The first suggested resolution was to remove all the stock php5 packages so that PHP 5.6 could be installed - so I just accepted the first suggestion.
The config files are all in /etc/php/5.6 and /etc/php/7.1 respectively - inside here is where you can configure which extensions are loaded, set the ini settings, and everything else for each version in isolation.
So to switch from php 5.6 to php 7.1 you need to do two things:
{CODE(colors="shell")}
sudo a2dismod php5.6; sudo a2enmod php7.1; sudo service apache2 restart # For php in web apps
sudo ln -sfn /usr/bin/php7.1 /etc/alternatives/php # For php-cli in the command line
php -v
# PHP 7.0.6-1+donate.sury.org~xenial+1 (cli) ( NTS )
# Copyright (c) 1997-2016 The PHP Group
# Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
#    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
#    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
{CODE}
or from php7.1 to php5.6:
{CODE(colors="shell")}
sudo a2dismod php7.1 ; sudo a2enmod php5.6 ; sudo service apache2 restart # For php in web apps
sudo ln -sfn /usr/bin/php5.6 /etc/alternatives/php # For php-cli in the command line
php -v
# PHP 5.6.21-1+donate.sury.org~xenial+2 (cli) 
# Copyright (c) 1997-2016 The PHP Group
# Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
#    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
{CODE}
From the commandline, I have both php5.6 and php7.1 available as commands. I also still have a php command - look in /etc/alternatives to see that it symlinks to a particular version of PHP cli*. You can also quickly check which yours is using by running php -v.
Remember that php.ini and other files with settings are not in /etc/php5 anymore but in /etc/php/__version__/
Change HighlighterToggle Highlighter
  • Sitemap
To translate, do not change the language and the content. Instead, create a new translation in the new language.
The namespace for a page is guessed automatically from the page name. However, some exceptions may arise. This option allows to override the namespace.

Search and select what you are looking for from the options that appear.

No matching results.

days
Image Seed: noun \ˈsēd\ : the beginning of something which continues to develop or grow

Knowledge seeds

Switch Language