Posts Tagged ‘ Ubuntu ’

Ubuntu Lucid Lynx 10.4 LTS with PHP5.2 / CakePHP1.1, Ubuntu Lucid Lynx 10.4 LTS, and PHP5.3

Note: If you want to downgrade to PHP5.2 under Ubuntu Lucid 10.4 LTS just scroll down till the bottom of the post.

Hello! Last weekend I decided to upgrade my linux distro to the new ubuntu one, I was using a 2 years old ubuntu distro and after the launching of ubuntu 10.4 LTS with PHP 5.3 packages included, i thought it was a great chance for trying it and keep myself updated. But I forgot a little, but important, detail: I’m currently integrated in a project that consists in developing an huge information system based on CakePHP 1.1, it was the stable version of CakePHP when the development started, in that time CakePHP was in its 1.2RC2 release – it’s not of my buisness, but i find always myself wondering how cool it would be if that person had thought the development and maintenance would take some years, and the 1.2 would become stable.. 1.3.. and so on..
Anyway, let’s talk about what matters, i could not develop with CakePHP 1.1 under PHP 5.3, and i needed to make it work till Monday , i was left with 3 solutions:

  1. Fix the CakePHP 1.1 core for running under PHP 5.3
  2. Downgrade the PHP install for 5.2
  3. Setup a virtual machine as close as the deploying environment.

Well… in my mind the first one one was inconceivable, i dont have enough time to spent with what i’m not paid for in my spare times. About the second one…i didn’t want to downgrade, i wanted to make it only as fallback option. So i went ahead and started with the third solution.

So i downloaded and installed VirtualBox, downloaded a Debian Lenny small ISO image, created a new virtual machine with two virtual network adapters, the first one in the host-only mode, that means that the VM could not reach the outside network, only the hosting machine, that connection creates a loopback interface for the communicatio. The second adapter i setup with NAT mode, it allows you to reach the outside world through the hosting system giving the WM a virtual ip address. Why this network setup? Because we want to have access to the outside world, for software packages downloading, etc.. and we need to have access to our VM HTTP server, and through the loopback device ip address we can do it. During the debian install wizzard it asked me what kind of software did i want to install, i answered with an webserver direct answer! And it setup a system with apache. I installed PHP5 packages and it’s apache2 module more  the database one. I decided to leave the database and the document root filesystem in my physical system, since this app has some extremely heavy components with lots of queries and calculations in the database, so i configured my postgresql for accepting connections in my local virtual ip address, and configured my app for connecting to the virtual host machine ip address. Installed an SSH client in the VM, generated a DSA SSH key with ssh-keygen, and put it in my host machine authorized_keys with no command execution, port forwarding, X11 forwarding, and PTY allocation allowed. Setup an init script for mounting it using SSHFS in the document root, running it as www-data, edited the default apache’s VirtualHost and changed the DocumentRoot directive accordingly. Restarted all services and voilá! Opened my browser, typed it’s ip address and I had my wonderfull CakePHP 1.1 app running under ubuntu 10.4. I had my victory.

After some testing i realized that, as expected, it was a bit slow while handling a big bunchs of data. And I pondered to go through the third solution and removed all PHP5.3 packages from the system, and found this explaining a strategy to install Karmic packages in 10.4 to run PHP as CGI, I prefer PHP5.2 to run as an apache module, so everyting i did was this:


# remove all php packge
sudo aptitude purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`
sudo su
# use karmik for php pakage
echo -e "Package: php5\nPin: release a=karmic\nPin-Priority: 991\n"  >> /etc/apt/preferences.d/php
apt-cache search php5-|grep php5-|awk '{print "Package:", $1,"\nPin: release a=karmic\nPin-Priority: 991\n"}' >> /etc/apt/preferences.d/php
apt-cache search -n libapache2-mod-php5 |awk '{print "Package:", $1,"\nPin: release a=karmic\nPin-Priority: 991\n"}' >> /etc/apt/preferences.d/php
exit
# add karmik to source list
sed s/lucid/karmic/g /etc/apt/sources.list | sudo tee -a /etc/apt/sources.list.d/karmic.list
# update package database (use apt-get if aptitude crash)
sudo apt-get update
# install php
sudo apt-get install -t karmic php5-cli libapache2-mod-php5

But i won’t give up of PHP5.3 anyway ;-)

EDIT: Quoting a comment from Pablo

A fourth solution could be install an older xampp package, which is isolated from “system’s” php packages and libs. xampp-linux-1.7.1 has php 5.2.9