# Localhost:3000 and devUrl redirecting to staging URL?

**URL:** https://discourse.roots.io/t/localhost-3000-and-devurl-redirecting-to-staging-url/8490
**Category:** trellis
**Created:** 2017-01-08T19:04:35Z
**Posts:** 7

## Post 1 by @shaun.reddiar — 2017-01-08T19:04:35Z

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](http://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](http://kerryreddiar.com):  
site\_hosts:  
- canonical: [staging.kerryreddiar.com](http://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](http://kerryreddiar.com):  
site\_hosts:  
- canonical: kerryreddiar.dev  
redirects:  
- www.kerryreddiar.dev  
local\_path: …/site  
admin\_email: [email@address.com](mailto: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](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](http://staging.kerryreddiar.com)).

Any guidance here would be appreciated. Thanks in advance.

---

## Post 2 by @MWDelaney — 2017-01-08T21:04:48Z

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]`

---

## Post 3 by @shaun.reddiar — 2017-01-08T21:33:56Z

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

---

## Post 4 by @shaun.reddiar — 2017-01-08T22:00:05Z

> [@MWDelaney](#):
>
> wp search-replace [staging url] [dev url]

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.

---

## Post 5 by @shaun.reddiar — 2017-01-08T22:10:54Z

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:

![](https://discourse.roots.io/uploads/default/original/2X/d/d782e8f0466ae6fd4bcd7ac3642b34fbb5bc7429.png)

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:  
 ![](https://discourse.roots.io/uploads/default/original/2X/7/797cf58ca532e99a9c9a6e9c33a6f17f5fa7a899.png)  
ie. [http://192.168.1.104:3000](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](http://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.

---

## Post 6 by @MWDelaney — 2017-01-08T22:29:18Z

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.

---

## Post 7 by @shaun.reddiar — 2017-01-08T22:44:10Z

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:
