admin管理员组文章数量:1314252
On my HostGator shared hosting with a CPanel option to set PHP per domain, if I turn on PHP 7.3 (or other 7.x versions) for my existing blog I get an error page:
Warning: Use of undefined constant WP_CONTENT_DIR – assumed ‘WP_CONTENT_DIR’ (this will throw an Error in a future version of PHP) in /my_site/public_html/wp-includes/load.php on line 141 Your PHP installation appears to be missing the MySQL extension which is required by WordPress
If I Google this, all the advice is about how to install mysqld
, but it's surely already installed as doing a fresh install of WordPress on a separate sub-domain works perfectly under PHP 7.3, so I must be missing something in my older site's WordPress wp-config.php
, perhaps. Looking at working and failing versions, though, I cannot see an obvious difference.
On my HostGator shared hosting with a CPanel option to set PHP per domain, if I turn on PHP 7.3 (or other 7.x versions) for my existing blog I get an error page:
Warning: Use of undefined constant WP_CONTENT_DIR – assumed ‘WP_CONTENT_DIR’ (this will throw an Error in a future version of PHP) in /my_site/public_html/wp-includes/load.php on line 141 Your PHP installation appears to be missing the MySQL extension which is required by WordPress
If I Google this, all the advice is about how to install mysqld
, but it's surely already installed as doing a fresh install of WordPress on a separate sub-domain works perfectly under PHP 7.3, so I must be missing something in my older site's WordPress wp-config.php
, perhaps. Looking at working and failing versions, though, I cannot see an obvious difference.
5 Answers
Reset to default 3Here's what worked for me: My Hostgator WordPress site was throwing the same error until I commented out the top-level .htaccess
file. Like so:
My website is a subdomain, so it had it's own .htaccess
, so that's where the php version was specified (cpanel did this automatically). I didn't have to edit wp-config.php
or anything else.
In the comments of this post is where I found this solution:
https://wordpress/support/topic/php-7-3-errors/#post-12720824
Ensure WP_CONTENT_DIR
is defined in your wp-config.php
file. It will be the path to your wp-content
directory.
define('WP_CONTENT_DIR', '/path/to/wordpress/wp-content');
Normally, the WP_CONTENT_DIR entry is defined in the https://developer.wordpress/reference/files/wp-includes/default-constants.php/ file (which is loaded after wp-settings.php):
if ( ! defined( 'WP_CONTENT_DIR' ) ) {
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
// No trailing slash, full paths only - WP_CONTENT_URL is defined further down.
}
This will set the WP_CONTENT_DIR
to default of your site's 'wp-content' folder, unless you (or someone/something) has defined this previously in the wp-config.php
with a command like this:
define('WP_CONTENT_DIR', '/path/to/wordpress/wp-content');
In a 'fresh'/default install, there should not be that DEFINE in the wp-settings
file. Perhaps you have a plugin or function that has moved the content folder to a new location as a 'security' method (although it is debatable whether that is useful -'security by obscurity' doesn't work all that well) and modified the WP_CONTENT_DIR
variable value.
So check your wp-settings.php
file for that DEFINE statement. Remove it (unless you really want your wp-content
files somewhere else), or look for a plugin in your site that is doing that.
In my case, there were two .htaccess files running simultaneously (one from the "public_html" and one above the root directory), and it was causing the conflict. I removed the file, and it worked. I was able to get this fixed with my Wordpress version upgrade issue.
Here's the original post of this solution: https://iiiji/fix-php-upgrade-error-whm-cpanel/
I just updated the PHP version 7.0 to 7.4 from Multi Php Editor for my website and I found the Use of undefined constant WP_CONTENT_DIR – assumed ‘WP_CONTENT_DIR’
After that, I degrade the version to 7.0 and got this error
Your PHP installation appears to be missing the MySQL extension which is required by WordPress.
Again I upgraded to 7.4
How I solved the error? Just deleted the .htacess file and refresh. All worked fine for me.
Thanks
本文标签: errorsUpgrading PHP version results in quotUse of undefined constant WPCONTENTDIRquot warning
版权声明:本文标题:errors - Upgrading PHP version results in "Use of undefined constant WP_CONTENT_DIR" warning? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741912178a2404508.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
.htaccess
in my root directory - the one abovepublic_html
- that had PHP 7.1-related commands that was mucking up the CPanel options. I've got a suspicion that I've been like that ever since I started with HostGator and they did an install for me from my previous host. – Ken Y-N Commented Jul 18, 2020 at 16:22