Error Messages Related to Local Not Able To Write to Hosts File in Linux

Issue Summary

Wordpress instances not being created because Local can’t write to hosts file in Linux

Troubleshooting Questions

  • Does this happen for all sites in Local, or just one in particular?

ALL sites

  • Are you able to create a new, plain WordPress site in Local and access it in a Browser?

No – see above!

Replication

Install Local on Linux

Run Local on Linux

‘Create’ new Wordpress site

Read the cryptic error messages (all four of them)

System Details

  • Which version of Local is being used?

5.10.3+5332

  • What Operating System (OS) and OS version is being used?

Linux Mint 19 Cinnamon

  • Attach the Local Log. See this Community Forum post for instructions on how to do so:

local-lightning.log (43.3 KB)

I know where the hosts file is in Mint, and I also have hosts.allow and hosts.deny files as well.

My question is what do I need to add, and where? This is basic stuff which should be covered somewhere in the docs for Local, especially given the number of similar threads for both Windows and Linux versions here.

Got a partial answer in another thread – Local needs to access and write to the hosts file to function preperly, which I already knew! My question still remains – how do I add Local to the hosts.allow file so that they can access the hosts file without making it available to every man and his dog?

In the meantime, Local has been uninstalled and I am using Bitnami Wordpress, which just works! If/when I get a sensible answer I will be happy to reinstall Local, but given my experience with the Windoze version I am not holding my breath!

Like I mentioned in the other thread:

I don’t think there’s an easy way to do this as it stands, but on the other hand, the hosts file is usually owned by root with 644 permissions. If the system has been compromised to the point that other users are able to edit root-owned files, there’s probably larger issues to take on.

That’s interesting that Bitnami doesn’t prompt for a system password to update the hosts file. I’d be curious to know how they are pulling it off!

My system hasn’t been compromised, and I don’t want it to be! As I keep mentioning, I have a file called ‘hosts.allow’ whose pourpose should be self-evident – all I need to know is what to put in it to allow Local full access, but not the bad guys.

I’ll be upfont and say that I’ve never worked with the hosts.allow file directly. Maybe I’m not bright enough to fully understand the self-evident nature of things, but reading through the man pages here:

It sounds like the hosts.allow file is meant more as a control mechanism for the server-client architecture – ie, defining what clients can access a host over TCP/IP.

This makes sense in a server environment because you’re trying to lock down the access to a system from other machines that would access it from the network.

In the above link, I’m not seeing any mention of how the hosts.allow file would be used to give fine-grain edit access to the hosts file. Maybe you can explain it better to me?

The reason why I don’t think there is anything to put in the hosts.allow file is that Local is already running on the host – it’s not accessing your computer through the TCP/IP layer.

Instead, Local is running on the system and is asking for elevated permissions to edit a file on that system – no networking layer involved. Since it sounds like the hosts file is set to be read-only for all users, this will fail. This sort of configuration is definitely more secure – nothing is going to edit that file without you knowing about it. But on the other hand, it’s fairly inconvenient since you’ll need to manually add any new Local domains to the hosts file.


All that being said, Local doesn’t really need to update the hosts file if you don’t want it to. You can set Local to use localhost Router Mode under “Preferences > Advanced” and Local will happily just create sites and give you access to them via a port that’s automatically listened to by WordPress.

There’s some limitations to running Local this way which you can read about in the help doc below, but on the whole, using the localhost Router Mode might be the way that you can keep the permissions you want on the hosts file while still using Local!

One of the ‘limitations’ makes it a non-starter for me because we need access to SSL to test WooCommerce and other plugins which won’t work without SSL.

Ahh yeah, SSL is definitely becoming more of a requirement for development.

Anyway, I hope I’ve given you a few things to consider as well as a few paths to investigate. Let me know if I’m not understanding something or if can help with anything else!

Hey! Thought I’d throw in my 10 cents! I am having the same issue here, a month later. I am running Debian. Local installs fine. I go in to create new site and I get 3 pop ups with the same vague error message. I am prompted to authenticate for the host file change twice then the process fails. When I use the locahost router, everything works fines.

Here is, I believe, the relevant log info:

{"thread":"main","class":"SiteProvisionerService","stack":"Error: spawnSync getcap ENOENT\n    at 
Object.spawnSync (internal/child_process.js:1067:20)\n    at spawnSync (child_process.js:611:24)\n    
at Object.execFileSync (child_process.js:638:15)\n    at Object.func [as execFileSync] 
(electron/js2c/asar_bundle.js:5:1846)\n    at RouterService.doesNginxNeedBindCap 
(%%appPath%%/main/router/RouterService.js:1:6667)\n    at RouterService.<anonymous> 
(%%appPath%%/main/router/RouterService.js:1:2769)\n    at Generator.next (<anonymous>)\n    at 
n (%%appPath%%/main/router/RouterService.js:1:132)","level":"error","message":"Unable to 
provision site.","timestamp":"2021-05-18T14:42:28.638Z"}
{"thread":"main","reason":{},"p":{},"level":"warn","message":"Unhandled 
Rejection.","timestamp":"2021-05-18T14:42:29.376Z"}
{"thread":"main","level":"error","stack":"TypeError: Converting circular structure to JSON\n    --> 
starting at object with constructor 'Error'\n    --- property 'error' closes the circle\n    at JSON.stringify 
(<anonymous>)\n    at Printf.template (%%appPath%%/main/_helpers/localLogger.js:1:2390)\n    at 
Printf.transform (%%appPath%%/node_modules/logform/printf.js:11:26)\n    at Format.transform 
(%%appPath%%/node_modules/logform/combine.js:20:24)\n    at Console._write 
(%%appPath%%/node_modules/winston-transport/index.js:90:33)\n    at doWrite 
(%%appPath%%/node_modules/readable-stream/lib/_stream_writable.js:428:64)\n    at 
writeOrBuffer (%%appPath%%/node_modules/readable-stream/lib/_stream_writable.js:417:5)\n    at 
Console.Writable.write (%%appPath%%/node_modules/readable- 
stream/lib/_stream_writable.js:334:11)\n    at DerivedLogger.ondata 
(%%appPath%%/node_modules/winston/node_modules/readable- 
stream/lib/_stream_readable.js:662:20)\n    at DerivedLogger.emit 
(events.js:327:22)","message":"Converting circular structure to JSON\n    --> starting at object with 
constructor 'Error'\n    --- property 'error' closes the circle","timestamp":"2021-05-18T14:42:29.387Z"}
{"thread":"main","class":"HostsFileService","level":"info","message":"Updating hosts 
with","timestamp":"2021-05-18T14:42:29.418Z"}
{"thread":"main","class":"DeleteSiteService","message":"Deleting 
%%site.runData%%","level":"info","timestamp":"2021-05-18T14:42:30.457Z"}
{"thread":"main","reason":{},"p":{},"level":"warn","message":"Unhandled 
Rejection.","timestamp":"2021-05-18T14:42:30.536Z"}
{"thread":"main","class":"HostsFileService","level":"info","message":"Updating hosts 
with","timestamp":"2021-05-18T14:42:31.309Z"}
{"thread":"main","class":"HostsFileService","stdout":"Updating hosts file at  /etc/hosts\nUpdated 
hosts file at  /etc/hosts\n","stderr":"","level":"info","message":"Updated hosts.","timestamp":"2021-05- 
18T14:42:32.416Z"}
{"thread":"main","class":"HostsFileService","stdout":"Updating hosts file at  /etc/hosts\nUpdated 
hosts file at  /etc/hosts\n","stderr":"","level":"info","message":"Updated hosts.","timestamp":"2021-05- 
18T14:42:34.778Z"}

Also, I made sure that nothing is binding to port 80.

Here are some bits of interest:

  1. Since it is authenticating, you would think it had the permissions to write to the host file. But it is erroring out before it asks for write permissions.
  2. On my local system, I went ahead (not a good idea…cannot recommend…I really know what I am doing and I still probably shouldn’t have) and gave my user permission to edit the hosts file, so I can now edit it without using sudo…meaning that Local should be able to write to my hosts file witthout permissions anyway now.

Local-Error

1 Like

What version of Debian are you using?

This is basically saying that Local can’t find the getcap program. It looks like for Debian 9, that program is provided by the libcap2-bin package.

You might try installing that package and see if that allows Local to edit the Hosts file:

sudo apt-get install libcap2-bin

Thanks for the reply! I am on Debian 9. libcap2-bin is already installed on my system and getcap is available. It’s in /usr/sbin. Meaning that it requires root privileges to run. Local is not requesting sudo rights until AFTER the error is thrown.

Interestingly enough, I just tried switching from localhost to site router and when I converted a site I already had from localhost to domain, it seemed to convert it just fine. When I try and run it under .local, it will not load…host file looks right. But when I use ngrok/live link I am able to open the site without issue.

Well that is really crazy!

That makes me wonder if the DB was updated to have the new domain. Can you try searching and replacing using wpcli? To do that:

  1. Right-click on the site in Local and select “Open site shell”

  2. Run a search/replace with this command:

    wp search-replace 'localhost:10005' 'example.local'
    

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.