Thursday, August 31, 2017

phpbrew (Install Php 5.3 in Ubuntu 16.04)

While working on multiple projects and if we needed multiple PHP versions then basic solution is install  multiple versions of PHP.

But this option not works if you needed lower  PHP versions in current Linux distributions(In my case it is Ubuntu).Like installing php5.3 version on Ubuntu 16.04.

To solve this one way is compile the code.But it takes time and porting it to unsupported environment is time taking.In attempt of finding the solution come across a tool/utility i.e. phpbrew (https://github.com/phpbrew/phpbrew)

It is quite handy and helpful for managing php versions on the fly.

Steps for installating and using phpbrew

Step 1(Download and configure phpbrew)

# curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew
# chmod +x phpbrew
# sudo mv phpbrew /usr/bin/phpbrew
Step 2(Entry into configuration file)
Configuring this in root account so in /root/.bashrc file needed to make following entry

[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc

Step 3
Initialize phpbrew

#phpbrew init

Step 4
List all known versions of php

#phpbrew known

Step 5
If in step 4 it not shows your required version then 

#phpbrew update --old

Now perform step 4 it will list older version as well.

Step 6
After this we have to install php-5.3(I tried 5.3.29 and other versisons but these are not working here only 5.3.24 installed)

#phpbrew install 5.3.24 +bz2 +calendar +cli +gd +ctype +dom +iconv +fileinfo +filter +ipc +json +mbregex +mbstring +mhash +mcrypt +pcntl +pcre +pdo +phar +posix +readline +sockets +tokenizer +xml +curl +zip +mysql +debug +apxs2

If you face any error then install respective library using apt-get

Step 7
List all installed version in phpbrew

#phpbrew list

Step 8
Before enabling versions from phpbrew needed to do following configuration in

#vim /etc/apache2/mods-enabled/php5.load
LoadModule php5_module /usr/lib/apache2/modules/libphp5.3.24.so 
AddType application/x-httpd-php .php


If it is any varient of php-5.6 or php7 then we have to either create php5.6.so/php7.so file in mods-enabled

Step 9
Before restarting apache2 disabled all other varient using a2dismod

Step 10
Choose Version using phpbrew

#phpbrew use php-5.3.24

Step 11
Check php version using

#php -v
 
And in apache2.Check phpinfo() output

Step 12
After choosing version using phpbrew as done on step 10.You can install any available extension using
#phpbrew ext install redis
#phpbrew ext install mongo

After installing this in php cli changes will be reflect but for apache it is needed to restart the apache for reflecting changes.

References
http://enzolutions.com/articles/2014/10/17/manage-php-versions-with-phpbrew/
https://bitbucket.org/snippets/sergiy_opentag/4LLrMR


No comments: