I plan to bulid up a nice developer environment and for this I need to clone the actual running website to a 100% into a dev directory.

I've now uploaded the same version of wordpress as on my running site and wondering if I could enter the same database and the same prefix as for the running site while running through the installation process. My goal is to connect the development website to the same database, so that it displays the same articles as the running website. Both sites should be in sync in terms of database content!

But I fear that it overwrites everything in my database and that I lose my data (I've got a backup, but I don't want down-time of the real website), so I'm asking you: What will happen if I enter the same details that are used by the running website? Will the development website display all the existing articles or will it overwrite everything in the database?

  • Take a look at migrate db plugin on github. Allows you to sync db from production into local dev. Sync takes about 4-10 minutes depending on db size. You will need to copy your db to Local first, then you can push/pull db fluently (I recommend only pulling at first)
    – RobBenz
    Jan 17, 2017 at 2:39
  • That looks pretty good. I'll definitely try it. Thanks!
    – Sam
    Jan 17, 2017 at 10:14

2 Answers 2


Based on your question, I am not exactly sure where your local build sits right now.

This answer is assuming you are starting from scratch, but have a copy of a working wordpress website on a live web server, and working on a mac.

You need to install a web server onto your local computer. I am recommending MAMP. https://www.mamp.info/en/

After getting mamp installed your next step would be to configure the root folder for your web server, we will move forward with the default settings Applications/MAMP/htdocs/

You will then need some sort of FTP client. Filezilla, Cyberduck, etc. login to your production server, and download the entire website ( probably something like public_html/your_site/ ) into a new folder withing the MAMP root ie: /Applications/MAMP/htdocs/your_site

You will then need to log into a SQL client to download a copy of your wordpress database, depending on your web hosting provider, they should have something called phpmyadmin. you will need to download the entire database.sql file to your local machine, lets say save it to your desktop.

Take a backup too at this point, just in case.

From there you will need to navigate to phpmyadmin through mamp on your local machine, and upload the .sql file to your local SQL database. if you are comfortable with the command prompt, this will work wonders...

/applications/MAMP/library/bin/mysql -u root -p wordpress_db < /Users/you/Desktop/backupDB.sql

if not, you can compress and upload, if the db is huge, you might need to break down the structure, & content into two different downloads & uploads, respectively

You will then to run a few SQL queries to change some core options about your wordpress install, ( to configure for local build )

UPDATE wp_options SET option_value="http://newdomain.com" WHERE option_name="siteurl";
UPDATE wp_options SET option_value="http://newdomain.com" WHERE option_name="home";
UPDATE wp_options SET option_value = replace(option_value, 'http://olddomain.com', 'http://newdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://olddomain.com','http://newdomain.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://olddomain.com', 'http://newdomain.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://olddomain.com', 'http://newdomain.com');

new domain will be something like, localhost/your_site

You then need to update your wp-config.php file to pull from the correct database on your local machine.

define( 'DB_NAME', 'wordpress_db' );  // only if you changed db name (don't)
define( 'DB_USER', 'root' );
define( 'DB_PASSWORD', 'root' );
define( 'DB_HOST', 'localhost' );

Now, I believe your localhost/your_site should be working, in the event that only the home page is working, and none of the other pages are, you may need to configure your .htaccess file as follows ( at the same root level as wp-config.php )

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /your_site/index.php [L]

So at this point you will have a exact copy of your live website.... now how to sync? .....

check out this plugin... https://github.com/wp-sync-db/wp-sync-db will need to install on your live site, and dev site.

Once active it will allow you to pull your live database into your dev database. you will need to configure an api key on your live site, and configure settings to allow for a pull then copy that api key and paste into dev site plugin settings ( tools > migrate-db ) sync once or twice per day.

please note: I do not recommend pushing your local db to your live db. I only ever pull my live db into my local build.

I hope this tutorial worked for you.

  • Wow! Thank you vey much @RobBenz!! My production site is actually on the webserver under a dev-directory so I can access it everywhere and show it to clients, but your tutorial should work for this too, I think. Again, many thanks for your understandable tutorial!
    – Sam
    Jan 17, 2017 at 14:07
  • also - you should consider setting up a local dev work space. it is a lot faster ( no need to upload files after every change ) and you can work off line. -- no wifi needed.
    – RobBenz
    Jan 17, 2017 at 14:25
  • You are right, it definitely has some great advantages. Maybe I'll set this up at a given time, but I'm working with two people on this project, so it's nice to have everything up and running on a server.
    – Sam
    Jan 17, 2017 at 14:29
  • we like git for team collaboration. - steep learning curve, but worth your time.
    – RobBenz
    Jan 17, 2017 at 14:31
  • I know git from other projects and I'm planning to include it to this one too. Not only for the better collaboration but even for the versioning and backuping.
    – Sam
    Jan 17, 2017 at 14:33

If you production server allows database connection from anywhere - it will connect. but every update you will do in your dev environment, it will affect the production database - very bad idea.

  • Well, do you have an idea, how I could sync in one direction only? So that the development database is always the same as the production one, but id changes are made to the dev database, they are nt synced to the prod one?
    – Sam
    Jan 17, 2017 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.