How to run an external command as a specific user in PHP

旧城冷巷雨未停 提交于 2019-11-29 08:54:43

You could try the shell_exec function and sudo

edit: seeing as sudo prompts for a password, you'd might wanna use proc_open, which allows you to use pipes. See this comment for how to create a custom password pipe.

I believe you should try another approach. The "setuid".

http://en.wikipedia.org/wiki/Setuid

Basically you ask the file to run as it's owner, not the program.

You can use that users CRON to execute the script. If this is a web application then you are limited to the Apache/Nobody user with limited permissions. If this just needs to run at a certain time I would use CRON.

Another approach is Sticky Bits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!