Last Updated: September 21, 2017
· hi_dm

Remote Database with local WordPress instance

How to use a remote database with your local instance of WordPress

The goal is to not have to make changes locally in your WordPress dashboard AND then make the same changes to your live site. I am extremely interested in hearing your take on this technique. It works well for me, so far, but there is probably an easier way.

What you need

  • MAMP or some Apache/PHP/MySQL application
  • The ability to install and configure WordPress on your server

My procedure

  • Install WordPress on your server (
  • Configure it with your database
  • Pull down the entire WordPress directory onto your local machine into a project folder
  • Add project folder to MAMP or your local web server app of choice (make a note of your Server Name)
  • Open your LOCAL copy of wp-config.php
  • Change 'DB_HOST' to ''
  • Add the following just above 'require_once(ABSPATH . 'wp-settings.php');'

    define('WP_CACHE', true); $currenthost = $_SERVER['HTTP_HOST']; $mypos = strpos($currenthost, 'localhost'); if ($mypos === false) { define('WP_HOME',''); define('WP_SITEURL',''); } else { define('WP_HOME','http://localhost'); define('WP_SITEURL','http://localhost'); }

  • Replace each instance of 'localhost' with your 'Server Name' in MAMP. (localhost is default)

You should be good. If not try whitelisting your IP in "Remote MySQL" within your hosting panel

2 Responses
Add your response

This works with any local hosting solution. XAMPP, MAMP, etc.

over 1 year ago ·

I'm not really sure what the last step means? What do you mean "replace each instance of localhost with Server Name in MAMP"?

over 1 year ago ·