Remote Database Connections

During the initial development phase of a project, you may need to continue working locally while the authorative database source is being actively updated on the (infodev) staging server. For example, a client or other team members may be updating content on the remote database while you still need to make programmatic changes and test with live content.

This guide explains how to connect to the remote (infodev) database server from your local dev environment.

Assuming you already have a valid SSH key:

Run the command below in your local terminal and leave the window open:

ssh -N -L 5555:127.0.0.1:3306 user@107.170.79.132 -vv

Change user to your actual infodev username.

This forwards infodev port 3306 to your local port 5555: 127.0.0.1:5555.

Now, in your WordPress root directory, change the DB connection using the configuration below:

/**
 * local-config.php
 * Change credentials to infodev values!
 */
define( 'DB_HOST', '127.0.0.1:5555' ); // this is the new connection
define( 'DB_NAME', 'YOUR_DB_NAME_HERE' ); // e.g; infodev_clientname
define( 'DB_USER', 'infomed3_admin' );
define( 'DB_PASSWORD', 'DB_PASSWORD_HERE' ); // removed for security. get from staging-config.php

This is an edge-case last resort solution, so please use sparingly and responsibly and always remember to close the terminal window while not in use.

also...

Be smart. Do not assume that local file uploads will be automagically syncronized to the staging server.

Be sure your local-config has WP_HOME and WP_SITEURL to avoid 404 errors:

define( 'WP_HOME', 'http://clientname.dev' );
define( 'WP_SITEURL', 'http://clientname.dev' );