Reverting Your Magento Local Site from Live URL
You’re not alone if you’ve found yourself struggling to get your local Magento development environment working correctly after an update or reinstall. The issue of the site reverting back to the live URL is a common one, but with some careful steps, it can be resolved.
Understanding the Problem
When you installed XAMPP and set up your local environment, you likely configured the base_url and secure_base_url settings in your Magento configuration file to point to “http://magento.local”. However, if these URLs don’t resolve correctly (or at all), Magento falls back to using the live site URL stored in cookies or session variables.
Resolving Your Issue
To fix this problem, youâll need to take a few steps:
- Check Your Hosts File
Make sure that your
hostsfile is properly configured for “magento.local”. On OSX, the hosts file can be found at/etc/hosts. It should contain an entry like:
127.0.0.1 magento.local
-
Flush Your Cache Even after deleting your cache manually, some session and cookie data may persist. To ensure a fresh start:
Open a terminal and navigate to your project root directory (the
htdocsfolder). Run the following commands:php maintenance/clean.php rm -rf var/cache/* rm -rf var/session/* -
Check Your Configuration Files Open the
app/etc/local.xmlfile in a text editor. Ensure that bothbase_urlandsecure_base_urlare set to “http://magento.local”:
<base_url>http://magento.local</base_url>
<secure_base_url>https://magento.local</secure_base_url>
- Check Your Cookie Domain
In the same
local.xmlfile, find thecookie_domainsetting:
<cookie_domain>magento.local</cookie_domain>
This should match your local domain exactly.
- Clear Browser Cookies and Cache Your browser may be holding onto old cookie and cache data from the live site. Clear these out completely (not just for one domain).
Preventing Future Issues
To prevent this problem in the future, consider a few best practices:
- Always keep your local environment separate from your development/live sites.
- Use a dedicated MySQL or PostgreSQL database for each environment.
- Don’t share the same
app/etc/local.xmlfile across environments. Each site should have its own configuration.
Conclusion
Remember that Magento is a robust platform, but it requires careful configuration to work properly in different environments. By following these steps and maintaining best practices, you can ensure your local development environment stays separate from your live sites.
Don’t forget to check out Laravel Company for more advanced tips on Magento development and how to optimize your workflow.