If you have just set up a RHEL 8 server, this includes CentOS 8, AlmaLinux 8, and Rocky Linux 8, you might have run into a fatal PHP error when using JSON related functions. For example:
PHP Fatal error: Uncaught Error: Call to undefined function json_encode()
This is because in RHEL 8, standard PHP installation is no longer including JSON support, which is different when you installed PHP in RHEL 6 or 7.
The solution is very simple. Just install the PHP JSON support separately. Run this as root using yum or dnf:
dnf install php-json
Remember to restart your web server (e.g. Apache, Nginx, etc).
Running phpinfo(), you should see a JSON section indicating “json support: enabled”.
Now, you should be able to use JSON related functions like json_encode() and json_decode(). If you have any questions, please do not hesitate to contact me at info@focalx.com, and I am happy to discussion with you further.