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:
- 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
- Use PECL to download the json package:
$ sudo pecl download json
- 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
andmake install
commands for you - 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
- Reload apache:
$ sudo service httpd reload
- 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.
'IT-Consultant' 카테고리의 다른 글
Apache 쓰레드 처리 방식 확인 (0) | 2011.04.04 |
---|---|
멍청한 짓거릴 하고 있었군.. (0) | 2011.03.29 |
Oracle 10g Table 데이터 삭제후 size변경관련 (0) | 2011.03.22 |
EJB 사용하기( Client 입장에서.. ) (0) | 2011.03.10 |
특정 디렉토리에 있는 파일중 7일 이전 파일 삭제하기 (0) | 2011.03.08 |