3

I am experimenting with GIT for version control. I have a production environment that I created a repo for HERE, then did a git clone locally. I created/modified the wp-config to work with my local DB. The index page loads, but all of the links for any pages or post point to the production URLs.

How can I make this so running the local instance allows me to browse to all the local pages/posts?

4
  • Do you have .htaccess file in the folder that also contains wp-config.php?
    – Greg36
    Oct 19, 2017 at 19:40
  • No, there is not .htaccess file locally. Should there be? Oct 19, 2017 at 20:01
  • 1
    If you locally use WAMP or MAMP that both use Apache as a server you should have the .htaccess file. Try deleting the local wp-config.php file, open WordPress URL in the browser and follow the installation process. The .htaccess file will be crated automatically.
    – Greg36
    Oct 19, 2017 at 20:07
  • Good call, I did this, and while my DB is out of sync, at least I can browse around the site. I am going to look into a db sync solution. Thanks! Oct 19, 2017 at 20:24

3 Answers 3

4

I would use WP DB Migrate to export the DB in the production environment. It allows you to rewrite URLs. Then you import that in your local DB.

3

Besides doing the find and replace on the domain as saved in the site's database, you'll also want to either:

  • ignore and remove the wp-config.php file from your git repo (so that the local development instance database connection info doesn't keep overwriting the server's and vice versa), or
  • add some environment specific configuration (can be a conditional statement in the wp-config, but better yet- should be a call to check for the existence of and use an external database config file whose name matches the environment)
2

My preferred method is to use WP CLI's search-replace command to swap out domains in my local site. If I have example.com on my live site, I'll use example.local on my local install, so the command to fix URLs on the dev site would be:

wp search-replace example.com example.local

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.