PHP  JSON extension not avaliabl…

According to php.net, “there is no installation needed to use [json_encode() and json_decode()]; they are part of the PHP Core“. While it’s certainly true that they are part of the source code, many of the binary packages available for RPM-based platforms (like Red Hat, CentOS and Fedora) have them disabled by default.

There are a number of extensions (PEAR and otherwise) available as RPMs in the official repositories, but sadly not php-json. To enable these functions on CentOS (and by nature, RHEL) 5, the process is simple but not immediately obvious:

  1. Make sure you have php, pear and the necessary development packages installed:
    $ sudo yum install php php-pear php-devel
    $ sudo yum install gcc make
    
  2. Use PECL to download the json package:
    $ sudo pecl download json
    
  3. Owing to some odd default memory settings we can’t download and install the package with PECL, we have to use PEAR:
    $ sudo pear install json-1.2.1.tgz
    

    PEAR will then trundle through and handle the configure, make and make install commands for you

  4. Create a new file in /etc/php.d called json.ini, containing the following:
    ; php-json package - http://pecl.php.net/package/json
    extension=json.so
    
  5. Reload apache:
    $ sudo service httpd reload
    
  6. Test your work:
    $ php -r 'var_dump(function_exists("json_encode"));'
    

    All being well, that’ll return bool(true)

…and there you have it.

Note: There’s a chance you’ll run in to an error that looks like this:

/bin/sh: bad interpreter: Permission denied
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF
environment variable is set correctly and then rerun this script.

… most likely, this is because your temporary partition is mounted with ‘noexec’, check the output of mount and look for the line that refers to /tmp to confirm the presence of ‘noexec’ in the mount options. In this instance you’ll either have to re-mount /tmp without noexec (by removing it from /etc/fstab) or untar, phpize, configure, make and make install manually.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值