Tags

It is desired to be able to switch between PHP versions. This can be accomplished with PHPBrew.

System configuration

whereis php
php: /usr/bin/php /usr/bin/X11/php /usr/share/php /usr/share/man/man1/php.1.gz
vagrant@vagrant-ubuntu-trusty-64:~$
PHP Version => 5.5.9-1ubuntu4.20

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.1 LTS
Release: 14.04
Codename: trusty

Requirements
As root
apt-get build-dep php5

Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/s/systemd/libpam-systemd_204-5ubuntu20.19_amd64.deb 404 Not Found [IP: 91.189.88.149 80]

Solve with
apt-get update

apt-get install -y php5 php5-dev php-pear autoconf automake curl libcurl3-openssl-dev build-essential libxslt1-dev re2c libxml2 libxml2-dev php5-cli bison libbz2-dev libreadline-dev
apt-get install -y libfreetype6 libfreetype6-dev libpng12-0 libpng12-dev libjpeg-dev libjpeg8-dev libjpeg8 libgd-dev libgd3 libxpm4 libltdl7 libltdl-dev
apt-get install -y libssl-dev openssl
apt-get install -y gettext libgettextpo-dev libgettextpo0
apt-get install -y libicu-dev
apt-get install -y libmhash-dev libmhash2
apt-get install -y libmcrypt-dev libmcrypt4
apt-get install mysql-server mysql-client libmysqlclient-dev libmysqld-dev

Installation
As user Vagrant
curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 130 100 130 0 0 231 0 –:–:– –:–:– –:–:– 232
100 1793k 100 1793k 0 0 1381k 0 0:00:01 0:00:01 –:–:– 5132k

chmod +x phpbrew

sudo mv phpbrew /usr/bin/phpbrew

phpbrew init
Using root: /home/vagrant/.phpbrew
Initialization successfully finished!

Phpbrew environment is initialized, required directories are created under

/home/vagrant/.phpbrew

echo "[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc " > .bashrc
echo “source /home/vagrant/.phpbrew/bashrc” > .bashrc

Or:
source ~/.bashrc

phpbrew known
===> Fetching release list…
Downloading https://secure.php.net/releases/index.php?json&version=7&max=100 via curl extension
Downloading https://secure.php.net/releases/index.php?json&version=5&max=100 via curl extension
7.1: 7.1.0 …
7.0: 7.0.14, 7.0.13, 7.0.12, 7.0.11, 7.0.10, 7.0.9, 7.0.8, 7.0.7 …
5.6: 5.6.29, 5.6.28, 5.6.27, 5.6.26, 5.6.25, 5.6.24, 5.6.23, 5.6.22 …
5.5: 5.5.38, 5.5.37, 5.5.36, 5.5.35, 5.5.34, 5.5.33, 5.5.32, 5.5.31 …
5.4: 5.4.45, 5.4.44, 5.4.43, 5.4.42, 5.4.41, 5.4.40, 5.4.39, 5.4.38 …

New PHP version
Installing a new PHP version:
sudo phpbrew --debug install php-5.6.29 +default+mysql+pdo+debug +apxs2 -- --with-mysql-sock=/var/run/mysqld/mysqld.sock

The +apxs2 option will make sure that the desired PHP version will also be loaded for Apache and not just the command-line. The +default option makes sure PHP is compiled with such things as json and mbstring

This may take a while!

Build finished: 30.3 minutes.
Installing...
---> Creating php-fpm.conf
---> Creating php.ini
---> Copying /home/vagrant/.phpbrew/build/php-5.6.29/php.ini-development
---> Found date.timezone is not set, patching...
Congratulations! Now you have PHP with 5.6.29 as php-5.6.29

phpbrew switch 5.6.29

phpbrew list
* php-5.6.29

The command-line PHP version is now:
php -i |more
phpinfo()
PHP Version => 5.6.29

For the PHP version loaded with Apache see:
cat /etc/apache2/mods-available/php5.load
LoadModule php5_module /usr/lib/apache2/modules/libphp5.6.29.so

Reload Apache
sudo service apache2 restart

and check PHP version in the browser via phpinfo():

Configuration File (php.ini) Path /home/vagrant/.phpbrew/php/php-5.6.29/etc
Loaded Configuration File /home/vagrant/.phpbrew/php/php-5.6.29/etc/php.ini

Advertisements