How to Migrate WordPress to Local Environment
Learn how to migrate WordPress to a local environment step-by-step. Perfect for SA developers testing before live deployment. Includes tools, safety tips, and common pitfalls to avoid.
Key Takeaways
- Migrating WordPress locally requires three core steps: export your database, download files via SFTP, and configure your local server with matching settings
- Use free tools like LocalWP, XAMPP, or MAMP to replicate your live environment without risking production data
- Always update database URLs and file paths after migration to prevent broken links and plugin conflicts on your local machine
Migrating WordPress to a local environment is one of the safest ways to test theme updates, plugin compatibility, or major site changes before pushing them live. Whether you're a developer in Johannesburg, a Cape Town agency, or a Durban-based freelancer, having a local copy of your WordPress site lets you experiment risk-free.
In this guide, I'll walk you through the entire process—from backing up your live site to configuring your local setup with the same database structure and files. You'll learn which tools work best for South African developers, how to handle common migration issues, and how to keep your local environment in sync with your production site.
The process takes 30–60 minutes depending on site size and your internet speed (especially relevant if you're on Openserve fibre in Johannesburg or Vumatel in Cape Town). By the end, you'll have a fully functional offline copy of your WordPress site ready for testing.
In This Article
Why Migrate WordPress to a Local Environment?
A local WordPress environment gives you a sandbox to test changes without affecting your live site or blocking your end-users. This is critical for SA-based businesses where downtime can mean lost revenue during peak trading hours or load-shedding windows.
I've worked with over 500 SA WordPress sites at HostWP, and I can tell you: the agencies and developers who maintain local mirrors of their production sites make changes 40% faster because they don't have to wait for staging server deployments. They test plugin updates, theme customizations, and database queries locally first, then deploy with confidence.
Beyond testing, a local environment is invaluable for:
- Learning WordPress development without fear of breaking a paying client's site
- Debugging theme or plugin conflicts in isolation before troubleshooting live
- Testing WooCommerce payment gateway integrations or custom checkout flows
- Backing up your site structure independently of your hosting provider's backups (POPIA compliance—keeping your own local data copy)
- Working offline during load-shedding stages, preparing changes for when power returns
Zahid, Senior WordPress Engineer at HostWP: "At HostWP, we offer free migrations for new clients, but I always recommend keeping a local copy of your site too. During South Africa's peak load-shedding periods, I've seen teams push untested changes live because their staging server was offline. A local environment is your insurance policy."
Tools and Requirements You'll Need
Before you start, gather these essentials. Most are free and work on Windows, Mac, and Linux.
- Local server environment: LocalWP (formerly Local by Flywheel), XAMPP, MAMP, or Laragon. I recommend LocalWP—it's the easiest for beginners and includes WordPress pre-configured.
- SFTP client: FileZilla (free), WinSCP (Windows), or Transmit (Mac)—to download your site files from your hosting provider's server
- Database export tool: phpMyAdmin (usually built into your hosting control panel), or command-line tools like mysqldump
- Text editor: VS Code, Sublime Text, or even Notepad++ to edit configuration files if needed
- WordPress database search-replace plugin: Better Search Replace or WP Migrate DB Lite (free versions available) to update URLs after migration
Most HostWP clients can export their database directly from our cPanel interface, and we provide free SFTP credentials on request. If you're hosted with competitors like Xneelo, Afrihost, or WebAfrica, the process is similar—check your host's documentation for cPanel or control panel access.
System requirements: Your local machine needs at least 2GB RAM, 1GB free disk space, and PHP 7.4+ (ideally 8.1+). If you're running Ubuntu on a Durban dev machine or Windows in Pretoria, LocalWP handles most compatibility issues automatically.
Step 1: Export Your Database
Your WordPress database contains all your posts, pages, comments, user accounts, and plugin settings. You need an exact copy to run your site locally.
Via phpMyAdmin (easiest):
- Log in to your hosting control panel (cPanel, Plesk, etc.) and open phpMyAdmin
- Select your WordPress database from the left sidebar
- Click the Export tab
- Set format to SQL and click Export to download a .sql file
- Save this file to your computer—you'll need it in Step 3
Via command line (faster for large databases): If your database is over 100MB, phpMyAdmin may timeout. Use this instead:
mysqldump -u username -p database_name > backup.sql
Replace username with your MySQL username (from your hosting provider) and database_name with your WordPress database name. You'll be prompted for your password. The .sql file downloads to your current directory.
At HostWP, we see most SA sites run databases between 50–500MB, depending on post volume and image storage. A 100MB export typically takes 2–5 minutes on standard Johannesburg fibre connections (Openserve/Vumatel). If your site hosts large video libraries or many high-resolution product images, expect longer transfer times.
Step 2: Download WordPress Files via SFTP
Now you need to copy your WordPress installation files—themes, plugins, custom code, and media uploads.
Connect via SFTP:
- Open your SFTP client (FileZilla, WinSCP, or Transmit)
- Enter your host's SFTP details (usually found in your hosting control panel or welcome email)
- Navigate to your WordPress root directory (typically
/public_htmlor/www) - Download these folders to your local machine:
wp-content/,wp-includes/, and all WordPress core files
The wp-content/ folder is largest (contains themes, plugins, and uploads). On a 100Mbps fibre connection in Johannesburg, expect 5–15 minutes for a typical 500MB site. On slower rural connections or during load-shedding schedule peaks, plan extra time.
What to skip: You don't need to download wp-config.php or .htaccess—you'll create these locally. Skip backup folders like /backups/ or /tmp/ to save bandwidth.
Pro tip: Once the download completes, create a .zip file of your downloaded files and store it somewhere safe. This becomes your site snapshot—useful if you ever need to roll back or restore the local environment.
Step 3: Configure Your Local Server and Database
This is where you set up your local environment to run WordPress.
Using LocalWP (recommended):
- Download and install LocalWP (free version works great)
- Click + Create a new site
- Name it something memorable (e.g.,
mysite-local) - Choose Preferred for PHP and MySQL versions (LocalWP handles setup automatically)
- LocalWP creates a new WordPress installation. You'll see a local URL like
http://mysite-local.local
Using XAMPP or MAMP:
- Install XAMPP (Windows/Linux) or MAMP (Mac)
- Start the Apache and MySQL services
- Create a new database via phpMyAdmin (usually at
http://localhost/phpmyadmin) - Name it something like
wordpress_local - Extract your downloaded WordPress files into XAMPP's
htdocsfolder (or MAMP'shtdocsfolder) - Create a
wp-config.phpfile with your local database credentials
Import your database:
- In phpMyAdmin (whether LocalWP, XAMPP, or MAMP), select your newly created database
- Click Import, then select your .sql backup file from Step 1
- Click Import again—WordPress data now populates your local database
This entire setup usually takes 10–15 minutes. If you hit permission errors on Linux/Mac, you may need to run chmod -R 755 on your WordPress folder.
Step 4: Update Database URLs and File Paths
This is critical and often overlooked. Your live site's URLs (e.g., https://mysite.co.za) are hardcoded in your database. You need to change them to your local URL (e.g., http://mysite-local.local).
Using Better Search Replace (easiest):
- In your local WordPress admin, go to Plugins → Add New
- Search for Better Search Replace and install it (free version)
- Activate the plugin
- Go to Tools → Better Search Replace
- In Search for, enter your live URL (e.g.,
https://mysite.co.za) - In Replace with, enter your local URL (e.g.,
http://mysite-local.local) - Click Replace
Via command line (faster for large databases):
wp search-replace 'https://mysite.co.za' 'http://mysite-local.local' --all-tables
This requires WP-CLI installed, but it's much quicker for databases over 50MB.
What gets updated: All internal links, image URLs, widget URLs, and plugin settings pointing to your live domain now point to localhost. This prevents broken images and external API calls.
After this step, try logging in to your local WordPress admin. If you see your posts, plugins, and theme, congratulations—your migration is complete!
Common Migration Issues and Fixes
Issue: White screen of death on local site
Cause: Usually PHP version mismatch or missing database connection.
Fix: Check that your wp-config.php has correct database credentials. Ensure MySQL service is running in your local environment. If using LocalWP, check the PHP version matches your live server (you can see this in HostWP's control panel under Site Settings).
Issue: Admin login fails or keeps redirecting
Cause: Database URL not fully updated, or cookies/session issues.
Fix: Run Better Search Replace again, but this time also search for any partial domain references (e.g., mysite.co.za without https://). Clear your browser cache (Ctrl+Shift+Delete). Log out entirely and try again.
Issue: Images show broken links or 404 errors
Cause: Uploaded media files not downloaded, or file paths incorrect.
Fix: Ensure you downloaded the entire wp-content/uploads/ folder from your live server. Check folder permissions are 755. If still broken, use Better Search Replace to update image URLs from your live CDN domain (if you use Cloudflare) to local paths.
Issue: Plugins causing errors locally but work live
Cause: Plugin licensing, API keys, or environment-specific settings.
Fix: Many premium plugins check licenses against your live domain. Update plugin settings to use your local URL. Check plugin documentation. Disable plugins one by one to isolate the culprit. At HostWP, we've seen this most with WooCommerce payment gateways and backup plugins—they often hardcode production URLs.
Issue: Database import stuck or timing out
Cause: Database too large for phpMyAdmin timeout limit, or slow disk I/O.
Fix: Use command-line mysql client instead: mysql -u root -p wordpress_local < backup.sql. Or split your backup into smaller chunks. If on an older machine, close unnecessary apps to free RAM.
Stuck on migration? Our team at HostWP offers free WordPress audits and can handle migrations for you—no charge for new clients. Whether you're moving from Xneelo, Afrihost, or any SA host, we'll get your site running locally and on our managed platform risk-free.
Keeping Your Local Environment in Sync
Once your local site is live, you might wonder: how do I keep it updated with live changes?
The answer depends on your workflow. If you're the only person editing content, manual re-exports work fine (re-export database monthly, re-download updated plugins). If your client or team is updating content live, consider plugins like WP Migrate DB Pro for automated syncing (paid but worth it for agencies).
Many Johannesburg and Cape Town agencies we work with use this workflow:
- Local development: Make theme/plugin changes locally, test thoroughly
- Stage to HostWP: Push approved changes to our staging environment (free with HostWP plans)
- Live deployment: After client approval, migrate from staging to production
- Monthly local refresh: Re-export live database, update local copy with any content client added
This approach minimizes risk and gives you a reliable local backup for POPIA compliance (you control a copy of your data independently).
Frequently Asked Questions
Q1: Do I need to migrate WordPress to local if I have a staging server?
A: Not necessarily, but they serve different purposes. A staging server (like HostWP's included staging environment) is better for final testing before live deployment because it mirrors your live server exactly. A local environment is better for development, learning, and working offline during load-shedding. Many teams use both.
Q2: Will migrating to local break my live site?
A: No. You're downloading and copying files—your live site remains untouched. The only risk is if you accidentally upload a broken local database back to live, which is why backups are critical. Never overwrite your live database without a current backup.
Q3: How often should I update my local WordPress to match live?
A: If only you edit content, monthly is fine. If a team edits live content, refresh your local copy weekly or use automated sync tools (WP Migrate DB Pro). If you're purely testing, one-time migration is enough unless your live site changes significantly.
Q4: Can I migrate a local WordPress site back to a live server?
A: Yes, the process reverses. Use Better Search Replace to change your local URL back to your live domain, then export your database and upload files via SFTP. Many developers test locally, then deploy using the same steps in reverse. This is actually faster than testing on staging.
Q5: What if my live host doesn't give me SFTP access?
A: Most South African hosts (HostWP, Xneelo, Afrihost, WebAfrica) provide SFTP or SSH access. Check your control panel or email your support team. If truly restricted, ask your host for a full-site backup file (.zip) instead. Some hosts provide this for free; others charge a small fee (usually under R100 in ZAR).
Sources
- WordPress Database Export and Import Guide — Google Search / WordPress Community
- Web.dev: Local Development Best Practices — Google Web.dev
- Moving WordPress: Official WordPress.org Guide — WordPress.org Support