Making a local MAMP development copy of your LIVE WordPress site
This post explains how to make a local development version of a standalone WordPress website (e.g. self installed not hosted at wordpress.com). Crucially, it will automatically amend your url’s from mysite.com/file to localhost:8888/file without having to alter the DataBase.
I’ve done this many times in the past. However, perhaps it’s my imagination but it seems I always have to do things differently to get things working. Hopefully, if you’re in the same boat this will help. Here was my situation:
I had my WordPress site here (benfrain.com) and wanted a local MAMP based version for testing changes before pushing it live. Whenever I have done this previously I have used something like Velvet Blues Update URL’s plugin so that URL’s went to the local links (e.g. localhost:8888/file), rather than the remote ones (e.g. benfrain.com/file). However, I noticed this entry on the WordPress Codex: http://codex.wordpress.org/Running_a_Development_Copy_of_WordPress. It promised to let me keep the DataBase in tact and still get the updated URL’s – perfect, no? Sadly, as ever things didn’t go exactly right. Here’s what I did to get things working.
I was using WordPress v3.3.1:
- Download the existing WordPress site files from the LIVE site (either FTP or SSH) to a local folder on OSX (e.g. /Users/benfrain/Sites/WordpressSite)
- Export the LIVE database from phpMyAdmin or with SSH and save it into the same local folder (if using phpMyAdmin and you have a large DB, you can gzip the export file as phpMyAdmin can import gzip files in MAMP (up to 32MB in size))
- Open MAMP, open phpMyAdmin and make a new blank database with the SAME DB NAME as your LIVE DB.
- Import the LIVE DB into the MAMP DB with the same name (using phpMyAdmin).
- You are now done with the LIVE site by the way, you can close your FTP/SSH session for it.
- Open the LOCAL copy of wp-config.php (in the root of WordPress) and edit your settings to match the DB name but change the DB_USER and DB_PASSWORD settings to this:
/** MySQL database username */ define('DB_USER', 'root'); /** MySQL database password */ define('DB_PASSWORD', 'root');
Then add this to the end of the same file. Change ‘YOURSITE’ to match the URL of your LIVE site:
/** Sets up WordPress vars and included files. */ define('WP_CACHE', true); $currenthost = $_SERVER['HTTP_HOST']; $mypos = strpos($currenthost, 'localhost'); if ($mypos === false) { define('WP_HOME','http://YOURSITE.com'); define('WP_SITEURL','http://YOURSITE.com'); } else { define('WP_HOME','http://localhost:8888'); define('WP_SITEURL','http://localhost:8888'); }
It should go just above this line:
require_once(ABSPATH . 'wp-settings.php');
Now restart your browser and view http://localhost:8888 and as long as your other MAMP settings are correct (remember to set the document root in the Apache tab to match where the downloaded files are (/Users/benfrain/Sites/WordpressSite in this example) you should see a local version of your site with URL’s linking to localhost:8888 file instead of the live URL’s.
Thanks for the article. I just got a new client that is already running a pretty complicated WordPress site. They want me to make some changes to it, so I thought running a local copy in MAMP would be a good way for me to experiment before taking the changes live.
I followed all your steps and checked them against several other articles as well. The home page loads up fine, but I can’t get to any of the other pages, and most importantly, the wp-admin screen. When I go to http://localhost:8888/site_folder/wp-admin I just get a blank screen (no error messages).
Any ideas? Could it be anything to do with the .htaccess file? Should I delete the plugins (they have a lot) and add them back in one by one?
Any help would be much appreciated.