UnCaught Error Call to undefined json decode
Enjoying this content? Subscribe to the Channel!
Quick Fix: Resolve the ‘Call to undefined json_decode’ Error on CentOS 8 (Moodle Install Guide)
Hi there, and welcome back to Darren’s Tech Tutorials!
If you’ve recently tried setting up Moodle on a CentOS 8 server—or perhaps another PHP application—you might have run straight into a wall: the dreaded “Uncaught Error: Call to undefined function json_decode”.
This error stops your installation dead in its tracks. But don’t worry! This is a classic issue that has a ridiculously easy fix. It simply means your PHP environment is missing a critical component necessary for processing data.
In this short guide, we’ll dive into why this happens and get you past that error screen in less than two minutes. Let’s jump right in and get that Moodle install running smoothly!
Understanding the ‘json_decode’ Error
The function json_decode() is fundamental to nearly all modern web applications. It is what allows PHP to read data formatted in JavaScript Object Notation (JSON), which is how many applications (including Moodle) communicate, store configuration, and handle API calls.
If PHP cannot find this function, it means the necessary PHP extension for handling JSON operations is not installed or enabled on your server.
The Diagnosis: When installing Moodle on my CentOS 8 server, the core PHP installation was missing the php-json package. Fortunately, installing it is all it takes to resolve the issue!
Step-by-Step Solution: Installing the PHP JSON Extension
Since we are operating on a CentOS environment, we will be using the yum package manager to quickly download and install the required component.
Step 1: Access Your Server Terminal
Log into your server via SSH or open the terminal window if you are working locally. You will need sudo privileges to install new software packages.
Step 2: Run the Installation Command
We need to tell the system to find and install the JSON handling module for PHP. Use the following command:
sudo yum install php-json
This command will:
- Search the CentOS repositories for the
php-jsonpackage. - Calculate any necessary dependencies.
- Prompt you for confirmation.
Step 3: Confirm the Download
When prompted to confirm the installation and size of the download (usually with Is this ok [y/d/N]:), type y and press Enter.
The package manager will quickly download and install the extension.
Step 4: Verify the Fix
Once the installation is complete, go back to your web browser where you encountered the Moodle error page.
Simply refresh the page.
You should now see the Moodle installation process continue without interruption! The json_decode function is now available, and your application can proceed with setup.
Congratulations, Error Resolved!
It’s amazing how a missing line of code can bring a whole setup to a halt, but knowing which package to target makes troubleshooting incredibly fast.
I hope this quick guide was helpful and got you back on track with your Moodle installation! If this solution worked for you, please hit that Like button below and consider subscribing to Darren’s Tech Tutorials for more quick, clear, and actionable tech guides.
Happy installing, and thank you for watching!