Install PHP 5.2 on Ubuntu 12.04 LTS

Remark: you should already have switched to PHP5.3 and heck, even 5.4…. but some old projects aren’t worth the dev time to update the code to PHP 5.3 or 5.4.

Having issues with your PHP 5.2 legacy websites after migrating them to new hardware and OS releases, which normally run on PHP5.3 or 5.4?

The best way to install PHP5.2 is by adding Karmic repositories to your apt sources. This way, you can simply install PHP 5.2 from package.

An easy way to add the sources is by running a small shell script that:

1) Creates a list of all your currently installed PHP packages.

2) Create the karmic.list files sources.list.d, holding the correct repo’s

3) Create a prefences file in /etc/apt/preferences.d, that pins your PHP version to the PHP5.2 version.

This script is copy pasted from Khalid:

There are of course other ways of installing PHP5.2 on Ubuntu 12.04 LTS, but this one works for me… and I have had no issues so far on my servers and sites..

Credits to: Randy Fay and Khalid

 UPDATE: 

Due to the fact that karmic is no longer in the Archive repo’s, the script needs a little change (replace archive by old-releases)

 

 

UPDATE2:

Today we had a crashed server that needed to be reinstalled. We had some problem with the PIN priority, packages installed still were 5.3.10… Bugger.

But looking a little further, you can use apt-mark hold to ‘pin’ package version to the installed packages.

So we had to install the PHP5.2 packages and ‘hold’ them to that version using:

 

 

 

 

Install Zend Optimizer for php 5.2 and earlier

Zend Optimizer has been updated and renamed to Zend Guard since PHP 5.3.

However, you might still have some older projects running PHP 5.2, where Zend Optimizer is still needed.

Here’s a small how to install for Ubuntu 12.04 LTS with PHP 5.2.

First of all, download Zend Optimizer 3.3.3 through this link: Zend

Unpack it on your server with this command:

Navigate into the data directory, and correct php version, eg:

copy the so file to the php path:

Enable zend optimizer throught /etc/php5/conf.d by typing:

Enable Zend optimizer by reloading apache

Check if Zend Optimizer is enabled by:

 

Installing and configuring Quota on Ubuntu

Writing this article because I had some weird stuff installing en enabling quota on my Ubuntu virtual server:

When using a shared webserver, it is always nice to know which site is using what amount of disk space. This is of course, when each site runs under its own user. Of course you can use df or other tools to find out, but using quota on Ubuntu is the way to go.

First we start by installing quota itself:

After installing this, you need to enable quota (usrquota and grpquota) on the disk which contains the websites.

and change the / partition by adding usrquota,grpquota to the mount option

In my case, on my Xen virtual machine:

Prepare quota to be enabled by creating the quota files:

You will also need to load the quota kernel module, and cause that to be loaded at boot time. You can do that by running:

Then run the quotacheck command:

 the quotacheck parameters above explained:
-a: checks all filesystems
-v: verbose check
-u: Only user quotas listed in /etc/mtab or on the filesystems specified are to be checked.  This is the default action.
-g:  Only group quotas listed in /etc/mtab or on the filesystems specified are to be checked
-m: same as –no-remount and thus forces quotacheck to run while the filesystem is mounted read/write, this way you don’t have to stop any services in order to perform the quotacheck.
-F vfsv0: to specify the quotaformat

This might take a while to complete… So grab a coffee.When the quotacheck has finished, enable quota itself by:

When I did this, I got the following errors: 

Fix this by:

Now, when you check the quota.user and quota.group file sizes, this might seem odd:

Wow, huge files! Now, don’t worry about this, as df show up as:

Also as explained on: HP SystemAdmin Forums

This is not a problem. The quota files are sparse files, i.e., they have “holes” of empty space that don’t actually take up any disk space. If you do an ls -ls on the file, the first field is the ACTUAL disk space used in KB. You’ll see that the file really occupies much less disk space than the length field would suggest. This is because the quota files are indexed based on the UID (for quota.user) or GID (for quota.group). If you have very large UIDs or GIDs (or negative ones, which translate to very very large unsigned integers) it will make the files appear very large.

You can’t change this, short of removing the large UIDs/GIDs and changing ownership of any files belonging to them, and you can’t remove the quota files. But it’s really not a problem. The Tru64 backup utilities, and most third-party ones as well, handle the quota files properly. They either don’t back them up at all, or back up them up as sparse files.

Show all userquota’s with this command:

 

If you want to enable Hard and Soft Quota’s limits for your users and websites, you can implement this with quotatool. For now this is out of the scope of this article, as I’m not (yet) interested in this. 🙂