Snaver.net

PHP JSON Module Install on a CentOS 5 Server

So I was messing around with jQuery‘s new little piece of sex – the jQuery Mobile Framework, when bam!

Call to undefined function json_decode() in /var/www/server/path/secret/h4x.php on line 56

Oh no! My PHP skills have failed me so I thought. But alas I had not made this magical mystical function up, it is of course a PHP Module, and soon to be included in PHP 5.2

After a quick bit of googling I came across an excellent tutorial for installing the said module, however I then ran into another problem after trying to execute ‘pecl install json’.

[*@*]# pecl install json
WARNING: channel “pear.php.net” has updated its protocols, use “channel-update pear.php.net” to update
downloading json-1.2.1.tgz …
Starting to download json-1.2.1.tgz (17,780 bytes)
……done: 17,780 bytes
11 source files, building
running: phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20050922
Zend Extension Api No:   220051025
building in /var/tmp/pear-build-snave/json-1.2.1
running: /tmp/tmpT1xwHb/json-1.2.1/configure
checking for egrep… grep -E
checking for a sed that does not truncate output… //bin/sed
checking for gcc… no
checking for cc… no
checking for cc… no
checking for cl… no
configure: error: no acceptable C compiler found in $PATH
See `config.log’ for more details.
ERROR: `/tmp/tmpT1xwHb/json-1.2.1/configure’ failed

I had no compilers installed.. apparently. No worries I thought, yum to the rescue!

[*@*]# yum install gcc
Loaded plugins: fastestmirror
Determining fastest mirrors
* addons: mirror.sov.uk.goscomb.net
* base: mirror.sov.uk.goscomb.net
* extras: mirror.sov.uk.goscomb.net
* updates: www.mirrorservice.org
addons                                                                                                                                                                             |  951 B     00:00
addons/primary                                                                                                                                                                     |  202 B     00:00
base                                                                                                                                                                               | 2.1 kB     00:00
base/primary_db                                                                                                                                                                    | 1.6 MB     00:00
extras                                                                                                                                                                             | 2.1 kB     00:00
extras/primary_db                                                                                                                                                                  | 188 kB     00:00
updates                                                                                                                                                                            | 1.9 kB     00:00
updates/primary_db                                                                                                                                                                 | 672 kB     00:00
Excluding Packages in global exclude list
Finished
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package gcc.i386 0:4.1.2-48.el5 set to be updated
–> Processing Dependency: cpp = 4.1.2-48.el5 for package: gcc
–> Processing Dependency: libgomp >= 4.1.2-48.el5 for package: gcc
–> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc
–> Running transaction check
—> Package cpp.i386 0:4.1.2-48.el5 set to be updated
—> Package glibc-devel.i386 0:2.5-49.el5_5.5 set to be updated
–> Processing Dependency: glibc = 2.5-49.el5_5.5 for package: glibc-devel
–> Processing Dependency: glibc-headers = 2.5-49.el5_5.5 for package: glibc-devel
–> Processing Dependency: glibc-headers for package: glibc-devel
—> Package libgomp.i386 0:4.4.0-6.el5 set to be updated
–> Running transaction check
–> Processing Dependency: glibc = 2.5-49.el5_5.4 for package: nscd
—> Package glibc.i686 0:2.5-49.el5_5.5 set to be updated
–> Processing Dependency: glibc-common = 2.5-49.el5_5.5 for package: glibc
—> Package glibc-headers.i386 0:2.5-49.el5_5.5 set to be updated
–> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers
–> Processing Dependency: kernel-headers for package: glibc-headers
–> Running transaction check
—> Package glibc-common.i386 0:2.5-49.el5_5.5 set to be updated
—> Package glibc-headers.i386 0:2.5-49.el5_5.5 set to be updated
–> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers
–> Processing Dependency: kernel-headers for package: glibc-headers
—> Package nscd.i386 0:2.5-49.el5_5.5 set to be updated
–> Finished Dependency Resolution
glibc-headers-2.5-49.el5_5.5.i386 from updates has depsolving problems
–> Missing Dependency: kernel-headers >= 2.2.1 is needed by package glibc-headers-2.5-49.el5_5.5.i386 (updates)
glibc-headers-2.5-49.el5_5.5.i386 from updates has depsolving problems
–> Missing Dependency: kernel-headers is needed by package glibc-headers-2.5-49.el5_5.5.i386 (updates)
Error: Missing Dependency: kernel-headers >= 2.2.1 is needed by package glibc-headers-2.5-49.el5_5.5.i386 (updates)
Error: Missing Dependency: kernel-headers is needed by package glibc-headers-2.5-49.el5_5.5.i386 (updates)
You could try using –skip-broken to work around the problem
You could try running: package-cleanup –problems
package-cleanup –dupes
rpm -Va –nofiles –nodigest
The program package-cleanup is found in the yum-utils package.

Oh dear. Now for some reason (If you know why please comment) by default yum asks for kernel files not to be automatically resolved and installed. You have to edit YUM’s configure file. For me this is located at ‘/etc/yum.conf’ and looks like this:

[main]
cachedir=/var/cache/yum
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
#exclude=kernel*

# Note: yum-RHN-plugin doesn’t honor this.
metadata_expire=1h

installonly_limit = 5

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

See the line that I’ve commented out? ‘#exclude=kernel*’ Yours should be lacking the hash character (Which comments that line out, effectively telling the parser to ignore that line), save the file and re-run ‘yum install gcc’

Now as it should be..

[*@*]# yum install gcc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: mirror.sov.uk.goscomb.net
* base: mirror.sov.uk.goscomb.net
* extras: mirror.sov.uk.goscomb.net
* updates: www.mirrorservice.org
addons                                                                                                                                                                             |  951 B     00:00
base                                                                                                                                                                               | 2.1 kB     00:00
extras                                                                                                                                                                             | 2.1 kB     00:00
updates                                                                                                                                                                            | 1.9 kB     00:00
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package gcc.i386 0:4.1.2-48.el5 set to be updated
–> Processing Dependency: cpp = 4.1.2-48.el5 for package: gcc
–> Processing Dependency: libgomp >= 4.1.2-48.el5 for package: gcc
–> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc
–> Running transaction check
—> Package cpp.i386 0:4.1.2-48.el5 set to be updated
—> Package glibc-devel.i386 0:2.5-49.el5_5.5 set to be updated
–> Processing Dependency: glibc = 2.5-49.el5_5.5 for package: glibc-devel
–> Processing Dependency: glibc-headers = 2.5-49.el5_5.5 for package: glibc-devel
–> Processing Dependency: glibc-headers for package: glibc-devel
—> Package libgomp.i386 0:4.4.0-6.el5 set to be updated
–> Running transaction check
–> Processing Dependency: glibc = 2.5-49.el5_5.4 for package: nscd
—> Package glibc.i686 0:2.5-49.el5_5.5 set to be updated
–> Processing Dependency: glibc-common = 2.5-49.el5_5.5 for package: glibc
—> Package glibc-headers.i386 0:2.5-49.el5_5.5 set to be updated
–> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers
–> Processing Dependency: kernel-headers for package: glibc-headers
–> Running transaction check
—> Package glibc-common.i386 0:2.5-49.el5_5.5 set to be updated
—> Package kernel-headers.i386 0:2.6.18-194.17.1.el5 set to be updated
—> Package nscd.i386 0:2.5-49.el5_5.5 set to be updated
–> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================================================================================================
Package                                            Arch                                     Version                                                    Repository                                   Size
==========================================================================================================================================================================================================
Installing:
gcc                                                i386                                     4.1.2-48.el5                                               base                                        5.2 M
Installing for dependencies:
cpp                                                i386                                     4.1.2-48.el5                                               base                                        2.6 M
glibc-devel                                        i386                                     2.5-49.el5_5.5                                             updates                                     2.0 M
glibc-headers                                      i386                                     2.5-49.el5_5.5                                             updates                                     602 k
kernel-headers                                     i386                                     2.6.18-194.17.1.el5                                        updates                                     1.0 M
libgomp                                            i386                                     4.4.0-6.el5                                                base                                         70 k
Updating for dependencies:
glibc                                              i686                                     2.5-49.el5_5.5                                             updates                                     5.3 M
glibc-common                                       i386                                     2.5-49.el5_5.5                                             updates                                      16 M
nscd                                               i386                                     2.5-49.el5_5.5                                             updates                                     165 k

Transaction Summary
==========================================================================================================================================================================================================
Install       6 Package(s)
Upgrade       3 Package(s)

Total download size: 34 M
Is this ok [y/N]:

Type ‘yes’ hit return and voila.. Now re-run ‘pecl install json’ and it should get a lot further and complete successfully.

Build process completed successfully
Installing ‘/var/tmp/pear-build-snave/install-json-1.2.1//usr/lib/php/modules/json.so’
install ok: channel://pear.php.net/json-1.2.1

One thing I thought Scott was a little vague on was step two and including the module in PHP loading start, you have to do the following in order for this to happen.

# cd /etc/php.d
# echo “extension=json.so” > json.ini
# service httpd restart

And that’s it! Hopefully this can save you the trouble that I personally had with YUM and Json, it seemed to be one problem after another!

Exit mobile version