Installing JSON extension on PHP 5.1 in Ubuntu

| 1 Comment

Today I needed to get a staging environment setup for an application using an old Ubuntu box. The latest available version of PHP to install with apt-get was PHP 5.1.2. and unfortunately I needed to use the json_encode and json_decode functions which are not included in this version. As opposed to trying to do a manual upgrade of PHP I decided to just install the json library, which actually became a rather fun and challenging experiencing. Here are the steps I took:

apt-get install php5-dev

I needed to install the php developer tools to be able to install the extension, if you already have these tools installed you can skip this step.

pear channel-update

Just confirming I have the most updated protocols from

pear install pecl/json

This is where the real action actually takes place. I encountered a weird error here which I talk about in my previous post. But typically this should install without any issue.

I then updated the php.ini (which for me was located in ‘/etc/php5/apache2/’) to include the following line at the end:

Then I restarted apache and was able to use the json functions I needed.