admin管理员组

文章数量:1122846

When I reinstalled my Wordpress site on a new server, I was stuck with a HTTP ERROR 500 page, and this showed in the logs :

[proxy_fcgi:error] [pid 87631:tid 140347891410624] [client xxxx:9316] AH01071: Got error
PHP message: PHP Fatal error:
  Uncaught Error: Undefined constant "WP_CONTENT_DIR" in /var/www/site/wp-includes/load.php:141
Stack trace:
#0 /var/www/site/wp-settings.php(29): wp_check_php_mysql_versions()
#1 /var/www/site/wp-config.php(92): require_once('/var/www/site...')
#2 /var/www/site/wp-load.php(37): require_once('/var/www/site...')
#3 /var/www/site/wp-blog-header.php(13): require_once('/var/www/site...')
#4 /var/www/site/index.php(17): require('/var/www/site...')
#5 {main}
  thrown in /var/www/site/wp-includes/load.php on line 141'

The error occurs inside the call of wp_check_php_mysql_versions() function.

I've seen that this WP_CONTENT_DIR should be loaded in wp-includes/default-constants.php which is loaded AFTER this call.

Is this a bug in Wordpress ?

When I reinstalled my Wordpress site on a new server, I was stuck with a HTTP ERROR 500 page, and this showed in the logs :

[proxy_fcgi:error] [pid 87631:tid 140347891410624] [client xxxx:9316] AH01071: Got error
PHP message: PHP Fatal error:
  Uncaught Error: Undefined constant "WP_CONTENT_DIR" in /var/www/site/wp-includes/load.php:141
Stack trace:
#0 /var/www/site/wp-settings.php(29): wp_check_php_mysql_versions()
#1 /var/www/site/wp-config.php(92): require_once('/var/www/site...')
#2 /var/www/site/wp-load.php(37): require_once('/var/www/site...')
#3 /var/www/site/wp-blog-header.php(13): require_once('/var/www/site...')
#4 /var/www/site/index.php(17): require('/var/www/site...')
#5 {main}
  thrown in /var/www/site/wp-includes/load.php on line 141'

The error occurs inside the call of wp_check_php_mysql_versions() function.

I've seen that this WP_CONTENT_DIR should be loaded in wp-includes/default-constants.php which is loaded AFTER this call.

Is this a bug in Wordpress ?

Share Improve this question asked Apr 21, 2024 at 9:21 OrabîgOrabîg 1113 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Yes, this is a bug, but it appear only when the WP configuration is not finished.

The error occurs on this line (in wp-includes/load.php) :

  if ( ! extension_loaded( 'mysql' ) 
       && ! extension_loaded( 'mysqli' ) 
       && ! extension_loaded( 'mysqlnd' ) 
       && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
(...)

This checks that mysql extension is installed, and tries several things for this. The last check will not work because WP_CONTENT_DIR is not defined yet at this stage.

The logical way to fix this is to ignore this error, and install PHP mysql extension, like so (in Debian) :

sudo apt install php-mysql

本文标签: phpUncaught Error Undefined constant quotWPCONTENTDIRquot