JSON on RHEL & PHP 5.1.6

Stuck with PHP 5.1.6 on RHEL or even CentOS (and a sysadmin who insists on using packages)? Need JSON? I did. The solution is easy:

yum install php-devel
pecl install json

The pecl install failed when it hit an 8MB memory limit, and I was clueless about how to fix it until I learned that the pecl installer ignores the php.ini. Turns out the best solution is to use the pear installer (which does follow php.ini settings):

pear install pecl/json

15 thoughts on “JSON on RHEL & PHP 5.1.6

  1. Pingback: Installing Clipperz password manager « Musings of a *IX guy

  2. Pingback: A Magic Web » php ? JSON ??? php-json

  3. I was migrating a CakePHP site to Rackspace’s Cloud server and ran into this issue. No repository had it so it was the pecl install for me. Worked like a charm.

  4. I am having the trouble with JSON and PHP as well.

    I have followed all the steps; running php -r ‘var_dump(function_exists(“json_encode”))’ return TRUE;

    However as soon as I run this from a PHP script in apache; I get False;

    Anyone care to help?

    Thanks

    • Hey, I’ve got exactly the same problem.
      JSON module appears in the command line PHP module (CentOS 4.4, PHP 5.1.6) but it doesn’t shows up in Apache (However phpinfo() shows the json.ini file loaded BUT not the .so)

  5. i tried to install it using the pear command.but showing something like this bash: pear: command not found.plz help

  6. Your method didn’t work for me, but I did get it to work like this:

    make sure you have a c complier installed (if you’re not sure do: yum install gcc)
    then do:

    pecl install json

    You’ll see a lot of info passing on your screen, just make sure the last 2 lines say the install is ok.

    cheate a new file:

    /etc/php.d/json.ini

    that contains the following line:

    extension=json.so

    now restart apache:

    service httpd restart

    That fixed the problem for me….

  7. This is how I did it:

    I have PHP 5.1.6 too.

    Run:

    yum install php-devel
    yum install php-pear
    yum install gcc
    pecl install json

    create a new file called json.ini in this directory: /etc/php.d/json.ini

    add this in json.ini: extension=json.so

    restart apache with this command:
    service httpd restart

    AND THAT”S ALL! Good luck! ;)

  8. Hi all,
    I did the complete process to install json on RHEL/php5.1.6 as exposed earlier.
    However as Andy earlier, php answer that json function exist on command line (return true) but not from a php script called by apache.
    I told php to load json.so module too but it’s still not working.

    Any help please here to nuderstand why the command line way works and the php’s script doesn’t.

    Thanks for help :)

  9. I have just found the answer on the net!!! Andy if u are here…

    do:
    cd /usr/lib/php/module/
    strip json.so

    And now all is good with a php script

    Have fun with json :)

  10. @Ecox method works. If you missed it
    Run:

    yum install php-devel
    yum install php-pear
    yum install gcc
    pecl install json

    create a new file called json.ini in this directory: /etc/php.d/json.ini

    add this in json.ini: extension=json.so

    restart apache with this command:
    service httpd restart

Comments are closed.