UnCaught Error Call to undefined json decode

Published: October 11, 2020 (Updated: Oct 11, 2020)

Enjoying this content? Subscribe to the Channel!

Fixing the PHP Fatal Error: Call to undefined json_decode (The Quick Moodle/CentOS Solution)


Hi there! Darren from Darren’s Tech Tutorials here.

If you’ve hit that frustrating wall during a fresh server setup—specifically installing Moodle on a CentOS 8 or similar server—you’ve likely encountered this dreaded message:

UnCaught Error Call to undefined json_decode

This error stops your installation dead in its tracks, usually right before the main configuration screens appear. The good news? This is one of the easiest server errors to fix, and it simply means PHP is missing a critical component.

Let’s dive into what’s happening and resolve this issue in one simple command!


Why This Error Occurs

Modern web applications like Moodle heavily rely on handling data structures, and JavaScript Object Notation (JSON) is the universal format for that. PHP uses specific functions, like json_decode(), to read and parse this data.

However, on many minimal Linux installations, PHP packages are broken into separate modules. If you installed PHP but forgot the specific package responsible for JSON handling, PHP literally does not know that the function json_decode() exists—thus, the “undefined function” error.

The solution is straightforward: we need to install the missing PHP JSON module.

Step-by-Step Solution: Installing the PHP JSON Module

Because we are running on a CentOS system (which uses the YUM package manager), we can fix this problem quickly via the command line.

1. Access Your Server Shell

Log into your server using SSH (or open your terminal if you are working locally). You will need sudo privileges to install new software packages.

2. Execute the Installation Command

We need to instruct the system to download and install the specific PHP module required for JSON handling, which is called php-json.

Type the following command exactly as written and hit Enter:

sudo yum install php-json

3. Confirm the Download

The system will prompt you, listing the packages to be downloaded and their dependencies. When asked to confirm the installation, type y (for yes) and hit Enter.

Is this ok [y/d/N]: y

The system will quickly download and install the module.

Verifying the Fix and Continuing Moodle Installation

Once the command finishes executing, the php-json module is active and available to your PHP environment.

4. Refresh Your Browser

Return to the browser window where your Moodle installation page was showing the error. Refresh the page completely.

Success! The error should now be gone, and you will be able to proceed with the normal Moodle installation steps (database setup, configuration, etc.).

Pro Tip: In some highly configured environments, PHP may need a service restart to recognize new modules. If the error persists after installing the package, try restarting your web server service (e.g., sudo systemctl restart httpd or sudo systemctl restart nginx).

Wrap Up

And that’s all there is to it! In just a moment, you’ve installed the one missing module that was holding back your entire Learning Management System setup.

These little configuration hiccups are a normal part of setting up server software, but knowing exactly which package to install saves you hours of frustrating troubleshooting.

If this quick guide helped you bypass that installation roadblock, please smash that Like button! Don’t forget to subscribe to Darren’s Tech Tutorials for more practical, straightforward guides just like this.

Happy installing, and I’ll see you in the next video!