Fixing Common Localhost WordPress Migration Issues: A Troubleshooting Guide
Content
Migrating a live WordPress site to a local development environment is a crucial task for developers, but it's often fraught with unexpected errors. Based on community reports, this guide covers the most frequent problems and their solutions when moving a site to XAMPP, MAMP, or Local by Flywheel.
Why Do These Localhost Migration Issues Happen?
The core of most migration problems lies in the fundamental differences between a live server and a local environment. Paths, server configurations, PHP versions, and database URLs are all hardcoded throughout a WordPress installation. When these values are not properly updated for the local setup, it leads to a cascade of errors, from broken styles and white screens to database connection failures.
Common Localhost Migration Problems and Solutions
1. PHP File Downloads Instead of Rendering
Symptoms: When you navigate to your local site URL (e.g., http://localhost/mysite), your browser prompts you to download a file (often index.php or download.php) instead of displaying the website.
Cause: This almost always indicates that PHP is not processing the .php files. The web server (Apache, Nginx) is treating them as plain text files to be served, not executed.
Solution:
- Check PHP Processing: Ensure your local server stack (XAMPP, MAMP, etc.) is running correctly. Create a simple
info.phpfile containing<?php phpinfo(); ?>and access it. If it also downloads, PHP is not configured. - Restart Services: Fully stop and restart your Apache and MySQL services through your stack's control panel.
- Reinstall Stack: If the issue persists, a corruption in the server stack itself is likely. Consider reinstalling XAMPP or MAMP.
2. White Screen of Death (WSOD) or Blank Pages
Symptoms: You access your local site or the /wp-admin area and are greeted with a completely blank, white page.
Cause: A fatal PHP error is occurring, but error reporting is disabled, so nothing is displayed.
Solution: Enable WordPress debugging to reveal the underlying error.
- Open your local site's
wp-config.phpfile. - Find the line
define( 'WP_DEBUG', false );. - Replace it with these lines:
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); // Logs errors to wp-content/debug.log define( 'WP_DEBUG_DISPLAY', false ); // Hides errors from the screen - Save the file and refresh the page. The error will now be written to
wp-content/debug.log. Check this log file for the specific error message, which will point you to the problematic theme, plugin, or configuration.
3. Broken Permalinks and 404 Errors
Symptoms: The homepage loads, but clicking on any post or page link results in a 404 "Not Found" error. The admin login page (/wp-login.php) might also return a 404.
Cause: Apache's mod_rewrite module is disabled, or the .htaccess file is missing/not being read.
Solution:
- Enable mod_rewrite: In XAMPP, open
httpd.confand ensure the lineLoadModule rewrite_module modules/mod_rewrite.sois uncommented (does not have a#at the start). - Allow .htaccess Overrides: In your Apache configuration, find the
<Directory>block for your web root (e.g.,/opt/lampp/htdocs) and changeAllowOverride NonetoAllowOverride All. - Restart Apache after making these changes.
- Refresh Permalinks: Log into your WordPress dashboard (you may need to use "Plain" permalinks temporarily), go to Settings > Permalinks, and simply click "Save Changes" to regenerate the
.htaccessrules.
4. Missing Styles, Scripts, and Formatting
Symptoms: The site loads but looks completely unstyled, like a plain text document. The browser's console shows 404 errors for .css and .js files.
Cause: The site URL or home URL in the database is still pointing to the old live domain, so the browser is trying to fetch assets from a server that doesn't exist locally.
Solution: Perform a complete search-and-replace on the database for the old URLs.
- Use a Tool: The safest method is to use a dedicated script like Interconnect IT's Search and Replace script. Upload it to your local site root, run it via the browser, and replace all instances of
http://my-live-site.comwithhttp://localhost/my-local-site. - Manual SQL Query (Advanced): In phpMyAdmin, you can run an SQL query on the
wp_optionstable (note: table prefix may vary):
Warning: Manually editing the database can break serialized data if not done carefully. Always back up first and prefer the dedicated script.UPDATE wp_options SET option_value = replace(option_value, 'http://old-url.com', 'http://localhost/new-url') WHERE option_name = 'home' OR option_name = 'siteurl';
5. Database Connection and "Error Establishing a Database Connection"
Symptoms: WordPress cannot connect to the database on your local server.
Cause: Incorrect credentials in the wp-config.php file.
Solution: Double-check the database connection details in your local wp-config.php file.
- Database Name: The name of the database you created in phpMyAdmin.
- Username: For XAMPP/MAMP, this is often
root. - Password: For XAMPP/MAMP, this is often blank (an empty string
''). - Host: This should be
localhost.
General Best Practices for a Smooth Migration
- Use a Migration Plugin: Plugins like Duplicator or All-in-One WP Migration can automate much of the database search-and-replace process, though they can sometimes fail with very large sites.
- Match PHP Versions: If your live site runs on an older PHP version (e.g., 5.6), try to match that version locally to avoid compatibility errors with old themes/plugins. Tools like Local by Flywheel make switching PHP versions easy.
- Check Server Logs: When all else fails, your local server's error logs are your best friend. Check the Apache error log (often in a
logs/directory within XAMPP/MAMP) for detailed error messages that can pinpoint the exact issue.
Migrating a WordPress site to localhost can be complex, but methodically working through these common issues will usually lead to a successful setup. The key is to enable debugging, check logs, and ensure your local server configuration matches WordPress's requirements.
Related Support Threads Support
-
Getting error “Sorry, you are not allowed to access this page” in Admin sectionhttps://wordpress.org/support/topic/getting-error-sorry-you-are-not-allowed-to-access-this-page-in-admin-section/
-
Getting 404 error message for wp-login.php on localhosthttps://wordpress.org/support/topic/getting-404-error-message-for-wp-login-php-on-localhost/
-
WP install ok on localhost but not serving via public URLhttps://wordpress.org/support/topic/wp-install-ok-on-localhost-but-not-serving-via-public-url/
-
Can’t access wordpress admin sitehttps://wordpress.org/support/topic/cant-access-wordpress-admin-site-2/
-
Failed to open stream: No such file or directory (wordpress/admin.php)https://wordpress.org/support/topic/failed-to-open-stream-no-such-file-or-directory-wordpress-admin-php/
-
missing base href in wp-admin (needed for PHP built-in webserver)https://wordpress.org/support/topic/missing-base-href-in-wp-admin-needed-for-php-built-in-webserver/
-
debug.log file, WP_DEBUG_DISPLAY and WP_DEBUG_LOG constants missinghttps://wordpress.org/support/topic/debug-log-file-wp_debug_display-and-wp_debug_log-constants-missing/
-
Error http 500 on a local LEMP installationhttps://wordpress.org/support/topic/error-http-500-on-a-local-lemp-installation/
-
Problem copying site from server to local: undefined function nocache_headers()https://wordpress.org/support/topic/problem-copying-site-from-server-to-local-undefined-function-nocache_headers/
-
‘Page not found’ issue on XAMPP localhost wp installhttps://wordpress.org/support/topic/page-not-found-issue-on-xampp-localhost-wp-install/
-
WordPress theme can’t activatehttps://wordpress.org/support/topic/wordpress-theme-cant-activate/
-
The requested URL was not found on this serverhttps://wordpress.org/support/topic/the-requested-url-was-not-found-on-this-server-24/
-
accessing localhost xampp wordpress website downloads a file called downloadhttps://wordpress.org/support/topic/accessing-localhost-xampp-wordpress-website-downloads-a-file-called-download/
-
Issue with WooCommerce Pages on Localhost – Object Not Found!https://wordpress.org/support/topic/issue-with-woocommerce-pages-on-localhost-object-not-found/
-
Problems with new Apache2 install and MIME typeshttps://wordpress.org/support/topic/problems-with-new-apache2-install-and-mime-types/
-
Can’t visit site anymorehttps://wordpress.org/support/topic/cant-visit-site-anymore/
-
Object Not Found on trying to accesshttps://wordpress.org/support/topic/object-not-found-on-trying-to-access/
-
Errors on WP multisite on Local (Flywheel)https://wordpress.org/support/topic/errors-on-wp-multisite-on-local-flywheel/
-
Broken theme/no access to editorhttps://wordpress.org/support/topic/broken-theme-no-access-to-editor/
-
New Post – white page: IIS Serverhttps://wordpress.org/support/topic/new-post-white-page-iis-server/
-
find empty content post in wp sitehttps://wordpress.org/support/topic/find-empty-content-post-in-wp-site/
-
Javascript console always shows 404 error for /nullhttps://wordpress.org/support/topic/javascript-console-always-shows-404-error-for-null/
-
After installation wordpress not workinghttps://wordpress.org/support/topic/after-installation-wordpress-not-working/
-
CAPTCHA ‘time expired’ error – copying live WordPress site to a localhosthttps://wordpress.org/support/topic/captcha-time-expired-error-copying-live-wordpress-site-to-a-localhost/
-
localhost/admin not foundhttps://wordpress.org/support/topic/localhost-admin-not-found/
-
404.php is displayed instead of index.phphttps://wordpress.org/support/topic/404-php-is-displayed-instead-of-index-php/
-
Ebeding issueshttps://wordpress.org/support/topic/ebeding-issues/
-
White page after migrationhttps://wordpress.org/support/topic/white-page-after-migration-3/
-
Not able to load site and can’t login to WP-Adminhttps://wordpress.org/support/topic/not-able-to-load-site-and-cant-login-to-wp-admin/
-
Blank pages in XAMPPhttps://wordpress.org/support/topic/xampp-redirects-to-live-site-on-web/
-
Errors when trying to install live site locallyhttps://wordpress.org/support/topic/errors-when-trying-to-install-live-site-locally/
-
Localhost install on XAMPP: imagick, is not installedhttps://wordpress.org/support/topic/localhost-install-on-xampp-imagick-is-not-installed/
-
Fresh install does not load correctlyhttps://wordpress.org/support/topic/fresh-install-does-not-load-correctly/
-
Live to Local with MAMP downloads PHP file instead of loading websitehttps://wordpress.org/support/topic/live-to-local-with-mamp-downloads-php-file-instead-of-loading-website/
-
Problem in local white pageshttps://wordpress.org/support/topic/problema-in-locale-dopo-la-prima-installazione/
-
Localhost get error “not allowed to access page”https://wordpress.org/support/topic/localhost-get-error-not-allowed-to-access-page/
-
Localhost user.php errorshttps://wordpress.org/support/topic/localhost-user-php-errors/
-
Pages not showing up (error 404 instead)https://wordpress.org/support/topic/pages-not-showing-up-error-404-instead/
-
Unable to connect to localhost sitehttps://wordpress.org/support/topic/its-happened-again-and-im-angry-please-help/
-
ERR_CONNECTION_REFUSEDhttps://wordpress.org/support/topic/err_connection_refused-7/
-
Error: ¡Vaya! No se ha podido encontrar esa página.https://wordpress.org/support/topic/error-vaya-no-se-ha-podido-encontrar-esa-pagina/
-
Theme Problemhttps://wordpress.org/support/topic/theme-problem-78/
-
WordPress Redirect Issuehttps://wordpress.org/support/topic/wordpress-redirect-issue/
-
Preview/view not workinghttps://wordpress.org/support/topic/preview-view-not-working/
-
Error message when to trying to access WP-admin pagehttps://wordpress.org/support/topic/error-message-when-to-trying-to-access-wp-admin-page/
-
Cache errorhttps://wordpress.org/support/topic/cache-error-16/
-
Styles are not loadedhttps://wordpress.org/support/topic/styles-are-not-loaded-2/
-
Local PC Hosting – No Images Appear and No Pages Loadhttps://wordpress.org/support/topic/local-pc-hosting-no-images-appear-and-no-pages-load/
-
Images / videos / embeds disappeared Localhost install (to practice and learn)https://wordpress.org/support/topic/images-videos-embeds-disappeared-localhost-install-to-practice-and-learn/
-
localhost imprime el archivo de texto en lugar de la pagina web de wordpresshttps://wordpress.org/support/topic/localhost-imprime-el-archivo-de-texto-en-lugar-de-la-pagina-web-de-wordpress/
-
Content from live site won’t load locallyhttps://wordpress.org/support/topic/content-from-live-site-wont-load-locally/
-
Can’t access wordpress admin sitehttps://wordpress.org/support/topic/cant-access-wordpress-admin-site/
-
Mysterious 404 Server errors on localhosthttps://wordpress.org/support/topic/mysterious-404-server-errors-on-localhost/