PHP Fatal Error: Call To Undefined Function Json_encode()
I just run into a problem, I deployed my php application on one of the production sever and a link started throwing the error PHP Fatal error: Call to undefined function json_encode()in the apache error logs. Here is what I did to fix it.
The code was working fine on my localhost machine because the local machine contained php of version 5.2.4 and php versions greater than 5.2 have json module built in. But on my production sever, Php version was 5.1.6. It was hactic process to upgrade the php version on non managed server.
Dont go around, the module can easily be installed via Pecl Module. But for Pecl module, its necessary that pear should be already present on your server. Install Pear Library with the following command:
yum install php-pear
Once the installation is over, you are ready to rock, run the following command to install json.
pecl install json
Once the installation is over, you will find json.so file located in you php modules directory. Normally php modules directory is /usr/lib/php/modules. Once you are sure that this module is available, simple add the following line to you /etc/php.ini file.
extension=json.so;
Now dont forget to restart apache service.
service httpd restart
Type php -m and you will find json loaded along with other modules of the php. Now your code will also work fine. Cheer!

