Unable to provision site, cannot edit hosts file

Hi, I’m running Ubuntu 24.04.1 and I’m getting the following errors when trying to create a new site:


Looks like LocalWP can’t get write permissions on the /etc/hosts file via pkexec (part of the policykit-1 ubuntu package)

These are the permissions of /ect/hosts:

.rw-r--r-- 230 root 2024-08-11 16:20 /etc/hosts

And this is the pkexec executable:

.rwsr-xr-x 31k root 2024-04-03 19:26 /bin/pkexec

System Details

  • Local Version: 9.1.0

  • Operating System (OS) and OS version: Ubuntu 24.04.1

Local Logs

I think these are the relevant lines from the logs:

{"class":"SiteProcessManagerService","level":"error","message":"Unable to start site.","stack":"Error: Error: User did not grant permission.\n\npkexec must be setuid root\n\nexitCode: 127\n    at %%appPath%%/main/_helpers/sudo.js:1:1076\n    at %%appPath%%/node_modules/sudo-prompt/index.js:191:11\n    at ChildProcess.exithandler (node:child_process:430:5)\n    at ChildProcess.emit (node:events:517:28)\n    at ChildProcess.emit (node:domain:489:12)\n    at maybeClose (node:internal/child_process:1098:16)\n    at Socket.<anonymous> (node:internal/child_process:450:11)\n    at Socket.emit (node:events:517:28)\n    at Socket.emit (node:domain:489:12)\n    at Pipe.<anonymous> (node:net:350:12)","thread":"main","timestamp":"2024-11-20T13:35:58.958Z"}
{"class":"Process","level":"info","message":"Killing process","pid":875876,"process":"mailpit","thread":"main","timestamp":"2024-11-20T13:36:25.656Z"}
{"class":"Process","level":"info","message":"Killing process","pid":875881,"process":"phpFpm","thread":"main","timestamp":"2024-11-20T13:36:25.667Z"}
{"class":"Process","level":"info","message":"Killing process","pid":875882,"process":"nginx","thread":"main","timestamp":"2024-11-20T13:36:25.678Z"}
{"class":"Process","level":"info","message":"Killing process","pid":875888,"process":"mysql","thread":"main","timestamp":"2024-11-20T13:36:25.688Z"}
{"class":"SiteProvisionerService","level":"error","message":"Unable to provision site.","stack":"Error: Error: User did not grant permission.\n\npkexec must be setuid root\n\nexitCode: 127\n    at %%appPath%%/main/_helpers/sudo.js:1:1076\n    at %%appPath%%/node_modules/sudo-prompt/index.js:191:11\n    at ChildProcess.exithandler (node:child_process:430:5)\n    at ChildProcess.emit (node:events:517:28)\n    at ChildProcess.emit (node:domain:489:12)\n    at maybeClose (node:internal/child_process:1098:16)\n    at Socket.<anonymous> (node:internal/child_process:450:11)\n    at Socket.emit (node:events:517:28)\n    at Socket.emit (node:domain:489:12)\n    at Pipe.<anonymous> (node:net:350:12)","thread":"main","timestamp":"2024-11-20T13:36:25.698Z"}
{"eventId":"4d0d5c196c424a48aa764b0048d37fad","level":"warn","message":"Unhandled Rejection.","p":{},"reason":{},"thread":"main","timestamp":"2024-11-20T13:36:38.641Z"}

Anyone has any idea how to solve this?

Hi @deedeedev

Have you checked for any antivirus, security, or firewall applications that could be blocking Local?

Yes, I don’t have any antivirus installed nor a firewall.

Is your Hosts File set to Read Only?

Are you an admin user on this device?

Are you running other developer applications simultaneously? That could also cause similar issues. Apps like MAMP, XAMPP, or Docker for example.

I managed to solve the problem setting the setuid bit on the /etc/hosts file like this:

sudo chmod u+s /etc/hosts

With these new permissions everything works fine:

.rwSr--r-- 230 root 2024-08-11 16:20 /etc/hosts

1 Like

Glad to hear it! Thank you for following up with the solution @deedeedev :green_heart: