• H2GD Part 29: Error establishing a database connection on WPMS local install

    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 is qw.
    • So my root install is http://qw
    • Each installation is in a separate folder, e.g. wpms, accessed as http://qw/wpms

    This gives me the following values to set in the database, .htaccess and wp-config.php


    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/


    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


    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.



    Last updated:

    May 17, 2019

Today’s word is this:







Tide times from tidetimes.org.uk

Tide Times & Heights for Langstone Harbour on
14th April 2024
03:54 High Tide ( 4.45m )
09:07 Low Tide ( 1.41m )
16:32 High Tide ( 4.33m )
21:33 Low Tide ( 1.73m )

Tide times from tidetimes.org.uk

Tide Times & Heights for Northney on
14th April 2024
04:13 High Tide ( 4.3m )
09:12 Low Tide ( 0.9m )
16:49 High Tide ( 4.13m )
21:36 Low Tide ( 1.31m )