ItecSoftware Logo

Install JSON PHP Extension on CentOs or RedHat

Written by Peter Gilg on - like this:
install json extension linux

JSON (JavaScript Object Notation) is the serialization format that is much lighter than it’s older sibling XML. In addition, JSON is native to JavaScript and it’s object oriented paradigm, hence makes it them perfect partners.

Instead of serializing your code manually, that is writing your own classes and functions, there is a PHP extension that takes on most of the work for you. You just have to install it.

Since I had numerous requests for info and questions relating to JSON extension in CentOS. To enable these functions in RedHat and CentOs 5, the process is really simple and fast.

NOTE: As of PHP 5.2, json extension is now standard. If you’re running PHP 5.2 or later, or like to upgrade instead, you can skip this!

Steps to install json php extension

Ensure you have the necessary dependecies (php, php-pear, php-devel, gcc, make)

$ sudo yum install gcc make
$ sudo yum install php php-pear php-devel

Use PECL (PHP Extension Community Library) to download the json package

$ sudo pecl download json

Use PEAR (PHP Extension and Application Repository) to extract and install the extension

$ sudo pear install json-1.2.1.tgz

Create a file in /etc/php.d called “json.ini”, and add the following lines

; php-json extension
extension=json.so

Restart apache (gracefully if you’re running a live site

$ sudo service httpd restart (or apachectl graceful, or apache2ctl graceful)

Check for availability by creating an info.php file in the web root with the following line:

<?php phpinfo(); ?>

Load info.php in your browser and check for JSON. You now should be all set, but if it doesn’t appear, verify all of the above steps very carefully.

Now load up your php info page and you should see the JSON extension listed. If not, make sure there were no errors in the steps above, and that you have reloaded Apache.

Listed in Linux, Web Development

Tags: CentOS, JSON, php, Redhat

7 responses to “Install JSON PHP Extension on CentOs or RedHat”

  1. Niket says:

    got one problem as below,
    No releases available for package “pecl.php.net/json”
    Cannot initialize ‘json’, invalid or missing package file
    Package “json” is not valid
    download failed

  2. radhaur says:

    @Niket February 2nd, 2011 at 8:30 am

    I had same problem as you, solution for this i founded in editing /etc/host and adding one more line to it 76.75.200.106 pecl.php.net

    try this

  3. Jonay Pelluz says:

    Just perfect! thanks for the tutorial… just copy and paste and works as it says 🙂

  4. Roger Miller says:

    Step 3 did not work for me.

    I’m on CentOS 6, and completed steps 1 and 2 with no errors or warnings. My working directory is my account home directory, and when I do step 3 I get:

    11 source files, building
    running: phpize
    Cannot find config.m4
    Make sure that you run ‘/usr/bin/phpize’ in the top level source directory of the module

    Any help would be much appreciated.

    • Roger Miller says:

      More info for the problem above, my phpize version says:

      Configuring for:
      PHP Api Version: 20090626
      Zend Module Api No: 20090626
      Zend Extension Api No: 220090626

  5. Fernando Olvera says:

    Works like a charm!! thanks!!

  6. surdet says:

    Thank you. It working on my server.

Leave a Reply

Your email address will not be published. Required fields are marked *