Monday, October 21, 2013

Fixing json_encode() Problem in PHP 5.5 on Ubuntu 13.10

I upgraded to Ubuntu 13.10 over the weekend and everything went pretty well. It automatically brings PHP 5.5 with it, too. When I tried to run a web app I was working on, though, I received this message:

Fatal error: Call to undefined function json_encode()

I subsequently Googled around and came across a highly-ranked blog article which makes it sound like PHP 5.5 drops support for json_encode because of some silly licensing argument. The truth is, PHP 5.5 does NOT drop support for json_encode. For a much better and much clearer explanation, I recommend reading this article.

Now, enough of the balleyhoo! How do we fix it?

It was was easy! Install the php5-json package and restart Apache. VoilĂ !

sudo apt-get install php5-json
sudo /etc/init.d/apache2 restart

Note that the author of the blog article linked above mentions that re-installing the php5-dev pacakged fixed his woes. While that didn't help me, you may want to give it a try if the above didn't help you.


Anonymous said...

Awesome thanks for posting this!

I didn't receive an error at all, but this problem was screwing with the page load speeds of one of my dev WordPress installations.

It's now fixed by specifically installing php5-json, Thanks.

Anonymous said...

Hi everyone,

I've been having trouble with the son_encode for quite some time now, and I finally figured it out.

You simply have to make sure that your connection as well as the file is uff-8 encoded. The connection used to be irrelevant before PHP 5.5.

Kind regards