Friday, October 29, 2010

JSON with Apache, Centos 4.4 and PHP 5.1.6

Although CentOS 4.4 and PHP 5.1.6 sounds a little ancient in these days, it can happen even in the best family when suddenly you're realizing one day you have to work with a configuration like that in order to keep a development environment entirely compatible with a live system (which is totally reasonable).

It's quite easy to upgrade Centos 4.4 to PHP 5.1.6 and it's also easy to add PEAR, PECL and JSON.
It's not necessary to mention how easy to add the JSON.so module properly to the CLI version of PHP and to Apache as well - here is a good description for that.

So now you have PHP 5.1.6, Apache2, Centos 4.4.
You type PHP -m and you see the JSON module is loaded.
You run the webserver on a page which containts PHPINFO(); and you can see the json.ini file is loaded.

But hey! The Webserver doesn't loads the .SO! What's going on?

It took me a couple of hours to figure out, and since I haven't found this solution, I'll provide it here - hopefully Google will cache it for other poor souls trapped in the same way and save a couple of hours for them.

The solution is:

cd /usr/lib/php/modules (or your modules directory where the json.so file is)
strip json.so
apachectl restart


As you can see, in some cases Apache doesn't loads unstripped shared binaries so you need to fix it manually if your scripts and compiler didn't do so already.

Enjoy!

4 comments:

Drew said...

Thanks for your solution. It worked for me with Centos 5.5 and PHP 5.1.6

munko said...

great post, your post works like charm,
thank you

munko

Anonymous said...

Thank you thank you and thank you. Finally a 5 hours struggle came to an end!

Bert said...

Thank you, thanks to you it didn't take me hours but minutes...
thanks again.