How to Restore a WordPress Backup to Localhost: A Step-by-Step Guide
Content
Restoring a WordPress backup to a local server like XAMPP, MAMP, or Local by Flywheel is a common task for developers and site owners who want to test changes safely or revive an old website. However, the process can be tricky, and many users run into issues where their site doesn't load correctly, the dashboard is inaccessible, or content appears broken.
Why Restoring a Backup to Localhost Fails
Based on common support threads, the most frequent reasons for a failed local restore include:
- Missing or Incorrect Database Import: The most critical step is often mishandled. Using the wrong command (e.g.,
mysqldumpto import instead ofmysql) or not importing the database at all will result in a fresh WordPress installation prompt. - Outdated File Paths and URLs: The database from your live site contains absolute URLs (e.g.,
http://yourdomain.com). When moved to localhost, these links break, causing missing CSS, images, and redirects to the old domain. - Version Mismatch: Trying to use a database from an old WordPress version with a new local installation can cause compatibility issues.
- Incomplete Backup: A backup must include both the wp-content files (themes, plugins, uploads) and a full database export (.sql file). Having only one will not work.
Step-by-Step Solution: The Manual Restore Method
This method, often recommended in community forums, gives you the most control over the process. Follow these steps carefully.
Prerequisites:
- Your complete website backup (all WordPress files + a
.sqldatabase dump). - A local server environment (e.g., XAMPP, MAMP, Local).
- Access to phpMyAdmin or the command line.
Step 1: Set Up Your Local Environment
- Start your local server (e.g., Apache and MySQL in XAMPP).
- Create a new, empty database for your project using phpMyAdmin. Note the database name, username, and password.
Step 2: Import the Database
- Open phpMyAdmin and select the new database you just created.
- Click the Import tab.
- Click Choose File, select your backup's
.sqlfile, and click Go. - Alternative (Command Line): If you prefer the command line or are dealing with a large file, navigate to your database file's directory and run:
mysql -u [username] -p [database_name] < [backup_file].sql. You will be prompted for the password.
Step 3: Upload the Website Files
- Navigate to your local server's root directory (e.g.,
XAMPP/htdocs/). - Create a new folder for your project (e.g.,
mywebsite). - Extract and upload all of your backed-up WordPress files into this new folder.
Step 4: Configure WordPress for Localhost
- In your project folder, locate the
wp-config.phpfile and open it in a text editor. - Update the database connection settings to match your new local database:
define( 'DB_NAME', 'your_new_database_name' ); define( 'DB_USER', 'your_local_db_user' ); define( 'DB_PASSWORD', 'your_local_db_password' ); define( 'DB_HOST', 'localhost' ); - Crucial Step: Update Site URLs. The database still points to your live site. You must change this. Add these two lines to
wp-config.php, above the line that says/* That's all, stop editing! Happy publishing. */:
Replacedefine( 'WP_HOME', 'http://localhost/mywebsite' ); define( 'WP_SITEURL', 'http://localhost/mywebsite' );/mywebsitewith the name of the folder you created in Step 3.
Step 5: Final Checks and Login
- Open your browser and go to
http://localhost/mywebsite. - Your site should now load. If styles are broken, you may need to run a search-and-replace tool on the database to update any remaining hard-coded URLs.
- Log in to the dashboard at
http://localhost/mywebsite/wp-admin. If you don't know the password, you can reset it directly in phpMyAdmin by following a guide on resetting WordPress passwords.
Alternative Solution: Using a Migration Plugin
If the manual process seems too complex, several plugins can automate the backup and restore process. The 'Localhost Installs' team often suggests plugins like All-in-One WP Migration, Duplicator, or UpdraftPlus. These tools bundle your files and database into a single package and handle the URL changes during import. However, be aware that advanced features often require a premium license.
Troubleshooting Common Problems
- "White Screen of Death" or 404 Errors: This is almost always a database connection error. Triple-check your
wp-config.phpsettings. - Missing Media/CSS (Broken Styling): This is caused by incorrect URLs. The method of defining
WP_HOMEandWP_SITEURLinwp-config.phpusually fixes this. If not, you may need a more thorough database search-and-replace. - Prompt to Install WordPress: This means WordPress cannot connect to your database. Ensure the database was imported correctly and the credentials in
wp-config.phpare perfect.
By carefully following these steps, you should be able to successfully restore your WordPress backup to a localhost environment for testing, development, or content recovery.
Related Support Threads Support
-
Help me restore from backuphttps://wordpress.org/support/topic/help-me-restore-from-backup/
-
Moving From Localhost to Localhosthttps://wordpress.org/support/topic/moving-from-localhost-to-localhost/
-
How do make an entire backup of localhosthttps://wordpress.org/support/topic/how-do-make-an-entire-backup-of-localhost/
-
Can I restore a site from a copy-paste backup of the directories?https://wordpress.org/support/topic/can-i-restore-a-site-from-a-copy-paste-backup-of-the-directories/
-
Computer stolenhttps://wordpress.org/support/topic/computer-stolen/
-
Recovering site from backuphttps://wordpress.org/support/topic/recovering-site-from-backup/
-
restor all site from full backup (files..data..ets)https://wordpress.org/support/topic/restor-all-site-from-full-backup-files-data-ets/
-
Restoring an old blog backup locallyhttps://wordpress.org/support/topic/restoring-an-old-blog-backup-locally/
-
Can’t Locate my site Using WordPress Studio on my local computer (localhost)https://wordpress.org/support/topic/cant-locate-my-site-using-wordpress-studio-on-my-local-computer-localhost/
-
Restore WordPress Backup on Local Serverhttps://wordpress.org/support/topic/restore-wordpress-backup-on-local-server/
-
Determine Localhost Addresshttps://wordpress.org/support/topic/determine-localhost-address/
-
moveing website backup to live website hosted in azurehttps://wordpress.org/support/topic/moveing-website-backup-to-live-website-hosted-in-azure/
-
How to download WordPress websites from Godaddy server to local PChttps://wordpress.org/support/topic/how-to-download-wordpress-websites-from-godaddy-server-to-local-pc/
-
Restoring locally hosted site from old computerhttps://wordpress.org/support/topic/restoring-locally-hosted-site-from-old-computer/
-
Manually backup and restore postshttps://wordpress.org/support/topic/manually-backup-and-restore-posts/
-
Recover wordpress site from folderhttps://wordpress.org/support/topic/recover-wordpress-site-from-folder/
-
Manually Moving Local Sites to work on Fresh MacOShttps://wordpress.org/support/topic/manually-moving-local-sites-to-work-on-fresh-macos/
-
how to access content in old WordPress fileshttps://wordpress.org/support/topic/how-to-access-content-in-old-wordpress-files/
-
Copying wordpress.COM content to localhosthttps://wordpress.org/support/topic/copying-wordpress-com-content-to-localhost/
-
Restore old WordPress sitehttps://wordpress.org/support/topic/restore-old-wordpress-site/
-
Converting old website into localhost websitehttps://wordpress.org/support/topic/converting-old-website-into-localhost-website/
-
recover backup on localhosthttps://wordpress.org/support/topic/recover-backup-on-localhost/
-
what to do with SQL backup when site is infected?https://wordpress.org/support/topic/what-to-do-with-sql-backup-when-site-is-infected/
-
Transferring localhost media to online sitehttps://wordpress.org/support/topic/transferring-localhost-media-to-online-site/
-
View my websitehttps://wordpress.org/support/topic/view-my-website/
-
Clean old WordPress installshttps://wordpress.org/support/topic/clean-old-wordpress-installs/
-
Local instal does not import posts and contenthttps://wordpress.org/support/topic/local-instal-does-not-import-posts-and-content/
-
Restore Backup to LocalHosthttps://wordpress.org/support/topic/restore-backup-to-localhost/
-
How to move site from one server running apache to another running cpanelhttps://wordpress.org/support/topic/how-to-move-site-from-one-server-running-apache-to-another-running-cpanel/
-
backup localhost wp questionhttps://wordpress.org/support/topic/backup-localhost-wp-question/
-
how restore wordpress versionhttps://wordpress.org/support/topic/how-restore-wordpress-version/
-
current to new wordpresshttps://wordpress.org/support/topic/current-to-new-wordpress/
-
Backing up local wp websitehttps://wordpress.org/support/topic/backing-up-local-wp-website/
-
Need to Recover Lost (Deleted?/Overwritten) Fileshttps://wordpress.org/support/topic/need-to-recover-lost-deleted-overwritten-files/
-
I downloaded entire wp directory from hosthttps://wordpress.org/support/topic/i-downloaded-entire-wp-directory-from-host/
-
Help for beginner with hacked sitehttps://wordpress.org/support/topic/help-for-beginner-with-hacked-site/
-
Moving a big wordpress websitehttps://wordpress.org/support/topic/moving-a-big-wordpress-website/
-
Reinstalling an old websitehttps://wordpress.org/support/topic/reinstalling-an-old-website/