Solved Wordpress - "There has been a critical error on your website."

I have just installed Wordpress using pkg install wordpress, created the mysql database, user and password and Wordpress is starting up but then I get error msg mentioned in the title.

It also says Learn more about debugging in WordPress.

So, I follow instructions and get the following in /tmp/wp-errors.log:

Code:
[19-Feb-2020 21:50:39 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function json_encode() in usr/local/www/apache24/data/wordpress/wp-includes/functions.php:3820
Stack trace:
#0 /usr/local/www/apache24/data/wordpress/wp-includes/widgets/class-wp-widget-text.php(58): wp_json_encode('text')
#1 /usr/local/www/apache24/data/wordpress/wp-includes/class-wp-widget.php(260): WP_Widget_Text->_register_one()
#2 /usr/local/www/apache24/data/wordpress/wp-includes/class-wp-widget-factory.php(112): WP_Widget->_register()
#3 /usr/local/www/apache24/data/wordpress/wp-includes/class-wp-hook.php(288): WP_Widget_Factory->_register_widgets('')
#4 /usr/local/www/apache24/data/wordpress/wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters('', Array)
#5 /usr/local/www/apache24/data/wordpress/wp-includes/plugin.php(478): WP_Hook->do_action(Array)
#6 /usr/local/www/apache24/data/wordpress/wp-includes/widgets.php(1765): do_action('widgets_init')
#7 /usr/local/www/apache24/data/wordpress/wp-includes/class-wp-hook.php(288): wp_widgets_init('')
#8 /usr/local/www/ in /usr/local/www/apache24/data/wordpress/wp-includes/functions.php on line 3820

This is the function causing the problem. Does it mean anything to anyone?
Code:
function wp_json_encode( $data, $options = 0, $depth = 512 ) {
<------>$json = json_encode( $data, $options, $depth );    ####<-------------------- line 3820 ------------------*********

<------>// If json_encode() was successful, no need to do more sanity checking.
<------>if ( false !== $json ) {
<------><------>return $json;
<------>}

<------>try {
<------><------>$data = _wp_json_sanity_check( $data, $depth );
<------>} catch ( Exception $e ) {
<------><------>return false;
<------>}

<------>return json_encode( $data, $options, $depth );
}
 
Last edited by a moderator:
Thanks, that seems to have sorted it out, although I was under the impression that using pkg install wordpress would install all the dependencies, although looking at Freshports it shows the following dependencies:

Runtime dependencies:
  1. php.h : lang/php72
  2. curl.so : ftp/php72-curl
  3. gd.so : graphics/php72-gd
  4. hash.so : security/php72-hash
  5. mysqli.so : databases/php72-mysqli
  6. tokenizer.so : devel/php72-tokenizer
  7. xml.so : textproc/php72-xml
  8. zip.so : archivers/php72-zip
  9. zlib.so : archivers/php72-zlib
  10. ftp.so : ftp/php72-ftp

Shouldn't devel/php72-json be included?
 
If this code is part of wordpress itself (not a plugin for example) and mandatory (can't be disabled), you are right, it also should be a dependency to me.
 
Balanga, I saw you solved the problem.
But I recommend you not use Php7.2

Php 7.2 is outdated, with lifetime terminated at Jan/2021. So, we can have many security holes.
Php 7.4 receive only security updates. So, I suggest you to install Php 8.0.
Apart from that, Json is now part of core of Php80.
 
Balanga, I saw you solved the problem.
But I recommend you not use Php7.2

Php 7.2 is outdated, with lifetime terminated at Jan/2021. So, we can have many security holes.
Php 7.4 receive only security updates. So, I suggest you to install Php 8.0.
Apart from that, Json is now part of core of Php80.
The post is almost three years old. I suspect that running pkg install -y wordpress would yield different results today. I have not tried personally.
 
Back
Top