Linux : How to add JSON support to CentOS 5 PHP 5.1.6

By | July 2, 2012

JSON support come natively with PHP 5.2 and later. If you are running CentOS Linux 5, this is PHP version 5.1.6 that is included by default. Fortunately, since version 5.6, CentOS packaged version 5.3.3 of PHP that can be installed through YUM (not included in the ISO set).

If you still run applications that can’t run on recent version of PHP, there is a workaround to get JSON support to PHP 5.1.

1. Make sure your system/PHP is up2date first :

yum update

If you only want PHP update, do :

yum update “*php*”

NOTE : The next step require GCC compiler, if you do not have it installed on your server, just do :

yum install gcc

2. Install JSON module through Pecl :

pecl install json

3. Create the extension file to make it effective :

/etc/php.d/json.ini

With the following content :

extension=json.so

4. Now, you need to restart Apache to load the extension :

service httpd reload

NOTE : You can now remove GCC if you do not require it for more security :

yum remove gcc