When attempting to convert WordPress to a Multisite setup, I get the error:
Error establishing a database connection
I’m using WordPress 3.7.1 on Windows 7 with a WAMP server.
wp-config.php
define('WP_ALLOW_MULTISITE', true );
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'localhost');
define('PATH_CURRENT_SITE', '/wordpress_test4/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
.htaccess
RewriteEngine On
RewriteBase /wordpress_test4/
RewriteRule ^index.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L]
RewriteRule . index.php [L]
You need to add to your
wp-config.php
:I had the same problem. I skipped this line because I already had
define('WP_ALLOW_MULTISITE', true);
in my wp-config and it looked to me the same.Had same problem, found 3 possible solutions:
Make sure:
DB_NAME
,DB_USER
,DB_PASSWORD
, andDB_HOST
in your wp-config.php are really the ones expectected.As Dima L. mentioned before,
define('MULTISITE', true);
is expected too.But what solved it for me* is etting up multi-site for WordPress, changed the
wp_blogs
table’s columnpath
to an undefined location for my website. I changed it to/
and the DB connection was re-established.I struggled a long time because of this issue. And finally found a solution.
You should not add all those settings at once in the wp-config.php file. Follow the exact steps described here: http://codex.wordpress.org/Create_A_Network
Only add the following code as the first step:
And then refresh your page.
After that, in your administration panel go to Tools -> Network Setup and choose your sub-site settings.
For the rest, just use the instructions from the link above.
I had a strange encounter very recently. After setting up a dev server which runs under a different domain and moving a multisite setup to it I got the same error âError establishing a database connectionâ. I had checked that all the wp_options tables have the correct domains in the respective settings and that my database connection had the right credentials and would work under normal circumferences.
I found a way to get a better error reporting. I added an output of the database object in the function dead_db() in functions.php which then showed me that it couldnât find any blogs for my site in the table wp_blogs. I simply forgot to update the domains for the test server in this table.
My
DOMAIN_CURRENT_SITE
inwp-config.php
wasdefine('DOMAIN_CURRENT_SITE', 'www.example.com');
Removing
http://
in wp_blogs -> domain fixed my issue.I added $base = ‘/’; into the config, which solved the issue.
If you have taken an entire database dump of a multisite, you would have to change the domain name to match your localhost domain on the following tables:
For a multisite, defining WP_HOME and WP_SITEURL on the config.php will not work.
Ideally before importing the DB dump, if you have the .sql file, you could do a search and replace of all the domains to your own localhost domain.
These above steps worked for me.
Besides to all said above, if working with multisite environment please check also the following:
in the respective subdirectories (/home/subsitename) there exist separate wp-config.php and .htaccess files for each of (sub)sites, so the above mentioned parameters have to be adjusted in all of these files.
For example, my main site was working correctly since these files in my /home directory were OK, but when tried to access my sub-sites, I’ve been receiving database connection error message until I adjusted these files too.
Inspired by Sabin’s answer, I checked
wp_blogs
and found that thedomain
value was still pointing to the wrong domain (I was moving a multi-site to a dev server). RunningUPDATE wp_blogs SET domain='example.com';
fixed my issue (note that I’m using subfolder multisite, not subdomain – don’t blindly run that SQL!)If you’re running WHM/cPanel and you’ve already checked that you’ve added the
MULTISITE
/WP_ALLOW_MULTISITE
constant, you’re probably running into virtual host issues.If you’re getting the database error, chances are, your name servers or A record is correct. Otherwise your domain wouldn’t be pointing to your server with a database connection. But, you’ve probably forgotten, or missed, the domain name from the cPanel aliases.
Just head to cPanel, search for ‘Aliases’ and type in the domain name you’re missing under ‘Create a New Alias’.
You can also get to cPanel by logging into WHM, searching for ‘List Accounts’, searching for the account you want and clicking on the CP icon.
I had the problem after moving the multisite from a sub directory to the root directory.
What solved it for me was partly what has been mentioned by Sabin Chirila :
but I had to change some more things.
Here’s How I fixed it
config settings
then in the database table (found using phpmyadmin) wp_blogs set the values for your root blog (which should be lie/number 1) to
And finally – reset the sitrurl and homepage in options table (again found using phpmyadmin) to