I’m working on setting up a local WordPress development environment using Docker on my Ubuntu machine. I copied my production database and imported it into the MySQL container that runs on port 8080 through phpMyAdmin. Even though I used a plugin to update the home and site URLs in the database, I’m still having issues.
Whenever I try to access my local site at localhost:8000, it keeps redirecting me back to the live production website instead of showing my local development version. I can’t figure out what’s causing this redirect problem.
check your browser cache first - chrome and firefox cache 301 redirects like crazy. try opening localhost:8000 in incognito or clear your cache completely. same thing happened to me and it was just the browser remembering the old redirect from the production site.
This redirect problem is usually from cached redirects or .htaccess rules that didn’t get updated during migration. First, check if there’s a .htaccess file in your wp-content volume with redirect rules pointing to your production domain. WordPress and plugins write redirect rules there that stick around even after database updates. Some caching plugins also store redirect mappings in the database under weird option names that standard URL replacement tools don’t catch. Try renaming your .htaccess file to .htaccess-backup and test again. WordPress Customizer settings are another common culprit - they can have hardcoded URLs that most migration tools miss. You could also add WP_HOME and WP_SITEURL constants directly to your wp-config.php file pointing to localhost:8000. This forces WordPress to ignore whatever URL settings are in the database.
I’ve encountered the same issue when moving a production site to a local Docker environment. WordPress often hardcodes URLs in various locations, not just the main site URL settings. Even after updating those in the database, you might still find old production URLs embedded in serialized data, widgets, and other option fields. The plugin you used likely only addressed basic entries in the wp_options table, missing the more complex serialized data. To fix this, consider using WP-CLI’s search-replace command to comprehensively update URLs. Run wp search-replace 'yourproductiondomain.com' 'localhost:8000' --dry-run inside your container to review the changes it would make. Additionally, check your wp-config.php for any hardcoded constants like WP_HOME or WP_SITEURL; these can completely override your database settings and may need adjusting for local development.