Cloning and syncing a WordPress website

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]
</IfModule>

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.

Leave a Comment