After updating a WordPress Multisite site to WordPress 3.6 and the latest versions of plugins that it used we noticed some strange results. I decided to create a local copy from the pre-update backup and try the process again. Unfortunately, I had difficulty getting the local install working since I kept getting
Error establishing a database connection
This is a brief explanation of this specific problem, with minor updates in January 2017 and May 2019.
Creating a local install
Assuming you already have a local development environment, creating a local install of a WordPress website should be a fairly easy process.
- Source website: Export the database and files
- Local: Download the database and files
- Local: Unpack the files into a new WordPress installation directory
- Local: Create a local user and database matching values in wp-config.php
- Local: Import the database
- Local: Update wp_options: set “siteurl” and “home” to your local URL
- Local: Update wp_options: set “upload_path” to null
- Local, optional: perform other database updates to replace URL with local values.
- Local, optional: Disable Jetpack publicize, having first ensured you know how it’s connected.
- Local: Disable the wordpress-mu-domain-mapping plugin
Additional steps for WPMS
- Local: Update wp_blogs: set the domain and path for blog_id=1
- Local: Update wp_site; set the domain and path for id=1
- Local: Update wp-config.php
- Local: Update .htaccess
That should be enough to get the local site up and running. Having gained access to the first site it’s then possible to use Network Admin > Sites to edit the other sites in the system.
Note: If you fail to update wp_blogs or wp_site correctly then you will get the “Error establishing a database connection” message. This is produced from ms_not_installed() in ms-load.php file.
The message is not helpful as it doesn’t tell you that the actual problem is that the values you have for domain and path don’t match the URL you’re attempting to access.
My local values
- Rather than using
localhostI use my computer name, which is
- So my root install is
- Each installation is in a separate folder, e.g.
wpms, accessed as
This gives me the following values to set in the database, .htaccess and wp-config.php
|wp_blogs||for blog_id=1||domain = qw|
|wp_blogs||for blog_id=1||path = /wpms/|
|wp_blogs||for blog_id=2||path = /wpms/site-2/|
|wp_site||id =1||domain = qw path = /wpms/|
The following line should be included:
You may also need to comment out a line that sets the PHP version.
#AddHandler application/x-httpd-php72 .php .php5 .php4 .php3
The following lines should be included:
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false );
$base = '/wpms/';
define( 'DOMAIN_CURRENT_SITE', 'qw' );
define( 'PATH_CURRENT_SITE', '/wpms/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );
- My local development site is now
- On some installations the table prefix is not
- More often than not, after importing the site, I find that I need to update some plugins to the latest version. I save the original plugin to
..\saved_pluginsthen create a symbolic link to my primary development directory.