Localhost:3000 and devUrl redirecting to staging URL?

Hi, I’ve decided to give the roots stack a try for the first time. All was going well until I ran into this error. I’m not sure were the problem would be as I have this project running with trellis, bedrock as well as sage.

For some strange reason when i run gulp and gulp watch the browsersync kicks in, but the url redirects to my staging url instead of my development url (ie. goes to staging.DOMAIN-NAME.com instead of DOMAIN-NAME.dev/localhost:3000). Why would this happen?

I have not set up or provisioned the production settings as yet. I’ve been just testing depolys and building via dev and staging first.

these are the settings that I have in their respective files:

trellis > group_vars > staging > wordpress_sites.yml:
wordpress_sites:
kerryreddiar.com:
site_hosts:
- canonical: staging.kerryreddiar.com
local_path: …/site
repo: MY-GIT-REPO-URL
repo_subtree_path: site
branch: master
multisite:
enabled: false
ssl:
enabled: false
provider: letsencrypt
cache:
enabled: false

trellis > group_vars >development > wordpress_sites.yml:

wordpress_sites:
kerryreddiar.com:
site_hosts:
- canonical: kerryreddiar.dev
redirects:
- www.kerryreddiar.dev
local_path: …/site
admin_email: email@address.com
multisite:
enabled: false
ssl:
enabled: false
provider: self-signed
cache:
enabled: false

trellis > hosts > staging:

[staging]
DO droplet IP

[web]
DO droplet IP

trellis > hosts > development:
[development]
192.168.50.5 ansible_connection=local

[web]
192.168.50.5 ansible_connection=local

And in my sage theme:
site/web/app/themes/MY-THEME/assets/manifest.json:
“config”: {
“devUrl”: “http://kerryreddiar.dev
}

Do date I cannot figure out where I’m going wrong and why my development environment url (kerryreddiar.dev or localhost:3000) keeps redirecting to the staging url (staging.kerryreddiar.com).

Any guidance here would be appreciated. Thanks in advance.

Did you copy your database down from Staging and import it to local at any point? If so, you’ll want to do wp search-replace [staging url] [dev url]

2 Likes

Thanks for the reply. Yes I did do a db sync using the wp-sync-db plugin prior to a test deploy to staging. I will give this a try, thanks

OK, I ran that command in the site directory and got this error:

PHP Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /Users/shaunreddiar/dev/kerryreddiar.dev/site/web/wp/wp-includes/wp-db.php on line 1538

Trying to figure out what I’m doing wrong.

The strange thing is that if I try access the backend on my development environment via DEVURL/wp-admin, i can log in correctly. It seems to be affecting the url only on the front-end. After logging in, I checked my general settings and the urls are correct as shown below:

Another odd thing is that when gulp watch is running, it only goes to the correct development environment if i use the external IP address:

ie. http://192.168.1.104:3000

Not sure what went wrong here. This seems to have happened after I test ran a deploy by running ansible-playbook deploy.yml -e “site=mysite.com env=staging” from my trellis directory.

Trying not to have to re-build the project as understanding how this all works will help a lot more

@MWDelaney to answer your initial question, I actually did the opposite, I pushed my DB from development to staging just after I ran the staging deploy. Not sure if that could have caused this.

The search-replace command should be run from the vagrant box; change to your Trellis directory and type vagrant ssh then cd /srv/path-to-your-site/current and do the search-replace from there.

I’m not sure what else to check. Everything seems to be set correctly from your reports.

2 Likes

Hey @MWDelaney it worked :grin:

After vagrant ssh’ing and doing that search and replace as you suggested, I ran vagrant reload, cleared my browser cache and it seems to be working now.

Thanks again :+1:

1 Like