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
localhost
I use my computer name, which isqw
. - So my root install is
http://qw
- Each installation is in a separate folder, e.g.
wpms
, accessed ashttp://qw/wpms
This gives me the following values to set in the database, .htaccess and wp-config.php
Database
Table | Rows | Values |
---|---|---|
wp_options | siteurl | http://qw/wpms |
wp_options | home | http://qw/wpms |
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/ |
.htaccess
The following line should be included:
RewriteBase /wpms/
You may also need to comment out a line that sets the PHP version.
#AddHandler application/x-httpd-php72 .php .php5 .php4 .php3
wp-config.php
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 );
See also
How to fix the Error establishing a database connection in WordPress Update to WordPress 3.6 WAMP configuration
Other notes
- My local development site is now
https://s.b
- On some installations the table prefix is not
wp_
- 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_plugins
then create a symbolic link to my primary development directory.