lando / docs

The main docs site for Lando
https://docs.lando.dev/
GNU General Public License v3.0
20 stars 57 forks source link

Developing offline not working. #112

Closed taher-pro closed 6 years ago

taher-pro commented 7 years ago

Bug Report

Setup

Lando version and operating system

v3.0.0-beta.22 on macOS High Sierra 10.13

Local .lando.yml

# Drupal 8 recipe
name: taher

# Start with the default Drupal 8 recipe
recipe: drupal8

# Configure the Drupal8 recipe
config:
  php: '7.1'
  via: nginx
  webroot: web
  drush: stable
  drupal: true
  database: mariadb:10.2
  xdebug: true

What am I trying to do?

Following the instructions for macOS verbatim from Documentation

Error

  1. I have appended the following 👇 to my /usr/local/etc/dnsmasq.conf

address=/local/127.0.0.1

  1. Restarted dnsmasq successfully using 👇

sudo brew services restart dnsmasq

  1. I have the following 👇 in my ~/.lando/config.yml file
proxyDomain: local
  1. When I run the lando start as per step 8 from Documentation I get the following
error

Offline development using the domain name is not working locally for me.

More Debugging Info

  1. The output of lando info in my apps directory (ran in a new terminal while the lando start command was stuck).
{
  "appserver": {
    "type": "php",
    "version": "7.1",
    "via": "nginx",
    "webroot": "web",
    "config": {
      "server": "/Users/taher/.lando/services/config/drupal8/drupal8.conf",
      "conf": "/Users/taher/.lando/services/config/drupal8/php.ini"
    }
  },
  "nginx": {
    "urls": [
      "https://localhost:32895",
      "http://localhost:32896",
      "http://taher.local",
      "https://taher.local"
    ]
  },
  "database": {
    "type": "mariadb",
    "version": "10.2",
    "creds": {
      "user": "drupal8",
      "password": "drupal8",
      "database": "drupal8"
    },
    "internal_connection": {
      "host": "database",
      "port": 3306
    },
    "external_connection": {
      "host": "localhost",
      "port": "32859"
    },
    "config": {
      "confd": "/Users/taher/.lando/services/config/drupal8/mysql"
    }
  }
}
  1. Not able to visit http://taher.local , https://taher.local

In Chrome I get the following

chrome_error
hussainweb commented 7 years ago

Unless I am mistaken, I think there is something missing in the documentation. The documentation only covers running a DNS server locally (dnsmasq), but does not talk about getting Mac OS X to find the nameserver. Most references I found about adding the TLD to /etc/resolver/TLD did not work for me.

After a bit of reading, I found that this address has to be added either via the System Preferences app (search for 'DNS') or the networksetup -setdnsservers Wi-Fi 127.0.0.1 command.

taher-pro commented 7 years ago

@hussainweb

Thank you for the analysis!

After a bit of reading, I found that this address has to be added either via the System Preferences app (search for 'DNS') or the networksetup -setdnsservers Wi-Fi 127.0.0.1 command.

Is ☝️ working for you?

Unfortunately in my case when I add 127.0.0.1 as a DNS, All the internet pages throw up DNS_PROBE_FINISHED_NXDOMAIN error along with http://taher.local , https://taher.local

hussainweb commented 7 years ago

@taherj Yes, I tried it and it worked. Make sure that 127.0.0.1 is the first IP in the list. Double check with scutil --dns.

Also, try running dig taher.local @127.0.0.1 to see if dnsmasq is working properly.

hussainweb commented 7 years ago

Okay, I reread and realised what happened. I should have clarified that add on 127.0.0.1 to output from existing entries from networksetup -getdnsservers Wi-Fi. Can you manually set it to your router's IP address for now?

e.g., networksetup -setdnsservers Wi-Fi 127.0.0.1 192.168.0.1 Replace 192.168.0.1 with your router's address.

hussainweb commented 7 years ago

On further reading, I found that there is an issue with .local TLD (not conclusive). In my case, dig was working fine but ping wasn't. Like suggested by the answer, I simply tried another TLD .site. Both dig and ping work fine now.

EDIT: More info: https://en.wikipedia.org/wiki/.local

hussainweb commented 7 years ago

I see this documentation was added in lando/docs#106 and the link over there is the one I referred to as well. However, the documentation missed out on the last section which is to let OS X know to check dnsmasq as well.

taher-pro commented 7 years ago

@hussainweb

Thank you for all of the above.

After detailed debugging and following the steps mentioned I found

  1. We need to add the DNS to mac using networksetup -setdnsservers Wi-Fi 127.0.0.1 192.168.0.1
  2. I was not restarting locally installed dnsmasq using sudo. Strangely restarting it without sudo does give a false positive. -- This was isolated by using dig.

I will supply a patch for the documentation inline with my learnings shortly.

hussainweb commented 7 years ago

I got stuck on the second issue as well. There is no error, but apparently it cannot bind to system ports as a regular user. It is an important gotcha for sure. :)

Mchampsee commented 7 years ago

Have you tried visiting http://localhost:32896 ?

taher-pro commented 7 years ago

@Mchampsee Yes http://localhost:32896 works.
The goal here is to get the TLD to work while we are offline.

dustinleblanc commented 7 years ago

I wrote that doc page, huh, weird. I ran through the whole thing and had no issues, but it may be because I had DNSMasq running previously and tore down / rebuilt, so maybe it had some preset magic going. It may also be possible that High Sierra changed something about the setup. The .local domain issue would definitely cause problems, but I've never, ever had to do the whole networksetup -setdnsservers Wi-Fi 127.0.0.1 business, I'd question if that is necessary. The need to add sudo to the restart of DNSMasq could definitely have been something I missed.

taher-pro commented 7 years ago

@dustinleblanc Would you please inform regarding the following :

  1. Which macOS version you are using for the documentation?
  2. Do you have 127.0.0.1 added in your networks entry already?

I understand the issue with the .local TLD. I have since changed it to .dev (as per the documentation) and checked as well. It does not seem to work on any browser without adding the 127.0.0.1 to the DNS.

It is probably a macOS High Sierra specific issue. I would propose we keep the docs updated to include these edge cases as well.

Thoughts??

Edit 1: @dustinleblanc You are right. Ideally, we don't really need networksetup -setdnsservers Wi-Fi 127.0.0.1. Here is a summary :

  1. Inform users to avoid using .local,.dev ( Google 😞 ) TLDs. refer 1, 2
  2. If the user really needs/want to use .dev or any other reserved TLDs they need to add the DNS locally using networksetup -setdnsservers Wi-Fi 127.0.0.1 <router_ip>

The current documentation has .dev TLD as the example so including 2 makes sense. Or we can update any other TLD instead of .local,.dev in the example and we don't need not handle the DNS entry business altogether.

Thoughts??

dustinleblanc commented 7 years ago

I had no clue .dev was a no go, wowsers! I've been using that for quite some time (hence the documentation). All four of tld's they list as safe look absolutely lame, but I guess .localhost makes semantic sense...

I'd definitely support updating it so folks don't run into that issue. I like to err on the side of humor as the Lando team have, so pick something comical imo :1st_place_medal:

jbertoen commented 6 years ago

Definitely recommend .localhost as well. What also might help with some dns issues on OSX is doing a dscacheutil -flushcache

jbertoen commented 6 years ago

I can't get localhost working without doing the following steps:

For OS X to resolve requests from *.local to localhost we need to add a resolver:

$ sudo mkdir /etc/resolver
$ sudo touch /etc/resolver/local
edit /etc/resolver/local

nameserver 127.0.0.1

re-start the computer to enable the resolver
jbertoen commented 6 years ago

@pirog, I updated the documentation to get it working on OS X and also added the recommendation to not use *.dev as a TLD for development.

pirog commented 6 years ago

@jbertoen awesome! thanks so much.

kamalkech commented 5 years ago

@jbertoen i had the same issue on archlinux (manjaro), there is another configuration for my system ??