Running shell script from PHP as different (non ro

2019-07-05 02:56发布

I'm trying to run a shell script owned by a non-privileged user from PHP on an Ubuntu server. Issues with permissions make running it with exec() impractical, as it's www-data that's running it. I've googled a bit and found varius references to suExec (which seems too much of a hassle to get working for such a small problem), setting the suid bit, and an interesting approach here on Stackoverflow involving a Python server listening for commands sent by PHP.

Anyway, of all of these solutions, I lean towards the one involving setting the suid bit, tried it and it didn't work : chmod u+s script.sh, and my Apache logs still show permission errors, so I know the script is not running as it's owner but as www-data.

What do I have to do to get this working, and is there a simpler solution for this problem ?

1条回答
成全新的幸福
2楼-- · 2019-07-05 03:35

Take a look at the man page for sudo: sudo -u your_other_user will let you execute the command as the other user.

Also use man sudoers to look for options on which user can execute what commands with sudo.

查看更多
登录 后发表回答