Skip to content

TUTORIAL: Developing Locally on WordPress with Remote Database Over SSH

Today, I went about setting up a local WordPress install for some development I am doing at work. The problem that existed is that I didn’t want to bring the database from the existing development server site into my local MySQL instance. It’s far too big. I figured this could be done via an SSH tunnel and so, I set abut trying to figure it out. The situation worked flawlessly and so, for your sake (and for myself for the future), I give you the steps.

Setting up the SSH Tunnel

I run a local MySQL server and that runs on the standard MySQL port 3306. So as these things go, I can’t bind anything else to port 3306 locally. I have to use an alternate port number. I chose 5555, but you can use whatever you want.

The command to run in a Terminal window is:

ssh -N -L 5555: -vv

A little bit about what this means.

the -N flag means that when connecting via SSH, we are not going to execute any commands. This is necessary for tunnelling as, we literally, will not execute any commands on the remote server. Therefore, we won’t get a command prompt.

the -L flag tells SSH that we are going to port forward. The following portion, 5555: combined with the -L flag means, literally, forward all traffic on localhost ( connecting on port 5555 to the remote server’s port 3306 (standard MySQL listening port).

The remote server and ssh connection is handled by This seems obvious, but just in case. You may be prompted to enter your SSH password.

The final part can be omitted, but I like to keep it there so I know what’s happening. The -vv flag tells the SSH daemon to be extra verbose about what is happening with the connection. It’s sort of a good way to debug if you need to, and to know that the port forwarding is actually taking place.

Configuring WordPress to use the Tunnel

Now that we have a successful SSH tunnel, you have to configure WordPress to use it. In the wp-config.php file, simply modify the DB_HOST constant to read:

define( 'DB_HOST', '' );

You need to add two more variables, though, to override WordPress’ existing siteurl and home options to allow you to work with the localhost domain, instead of redirecting to the that is configured in WordPress.

define( 'WP_HOME', 'http://localhost' );

define( 'WP_SITEURL', 'http://localhost' );


With these configurations in place, loading up WordPress should now load in the database content from the remote host and you can get to work on local development. Word to the wise… don’t close the terminal window with the tunnel or the tunnel will be severed. If you have to minimize it so it’s not annoying you, go for it… just don’t close it.


  1. sean sean

    Why did you choose to do this via an SSH tunnel, rather then just via HTTP? Before i knew what i was doing (its debatable that i know now) i used to just create the database on the server which i knew the site was going to be hosted on, and connect my local installation to that database so i didn’t have to move the database when it was ready to launch

    • Aaron Aaron

      Security. Don’t open up your MySQL server to be accessed over HTTP. Ever.

  2. Amazing post!, but I have a question. I have to remove the variables (defines) ‘DB_USER’ and ‘DB_PASSWORD’ ?

    Thanks a lot! regards from Chile

    • Aaron Aaron

      No! Never remove those or WordPress won’t work.

Comments are closed.