ext-php-rs icon indicating copy to clipboard operation
ext-php-rs copied to clipboard

Consider escalating priviledge to `sudo` automatically when copying `.so` file or editing ini file

Open dilawar opened this issue 6 months ago • 3 comments

https://github.com/davidcole1340/ext-php-rs/blob/060c8bfb2dacffe35cffb558d4f3738d86a5d34c/crates/cli/src/lib.rs#L224

The problem

If you are outside docker and/or don't have permissions to write into PHP's config directory.

  • cargo php install will fail if normal user don't have permissions to copy file or write to .ini file.
  • sudo cargo php install is likely to fail with cargo not found error since cargo is typically installed in user's ~/.cargo/bin directory.
  • sudo ~/.cargo/bin/cargo php install is likely to rebuild and change the owner to root of many intermediate files to make normal cargo b to fail.

Solution: before copying file or editing INI file, check if it requires admin privilege and use sudo2 or elevate crate to escalate privilege.

dilawar avatar Jul 03 '25 05:07 dilawar

Would you accept a MR if this make sense?

dilawar avatar Jul 03 '25 05:07 dilawar

I really like that idea. I would also like to add a root check and just fail unless something like --bypass-root-check is passed.

Xenira avatar Jul 03 '25 06:07 Xenira

Getting root check on Windows may be tricky. I am not even sure how PHP installation works on Windows.

dilawar avatar Jul 03 '25 06:07 dilawar