简体   繁体   中英

Run a bash script, which starts a screen from a specific user in php

I have dug through everything I can find on the topic of starting a screen from PHP. I'm starting a game server, so I must run it from a specific user so that the server executable looks in the right folder for its other files. I have changed Apache's user from its default to the user I must run the server from. When I have exec('cd /User/FolderWithScript && bash script.sh); to emulate what I would do to start it, it doesn't report any errors in /var/log/apache2/error.log, but also doesn't start the server or its screen.

The same thing happens if I were to use exec('cd /User/FolderWithExecutable && screen -dmS ServerExcutable +Args'); which is essentially what the script does.

If I use exec(cd /User/FolderWithScript && bash ServerExcutable +Args); it spits out all of the usual stuff for the server in /var/log/apache2/error.log, but unfortunately also appears to be looking in the wrong directory for most of the game files, which are located in /User/.game.

Thanks!

I had to add in my sudoers file www-data ALL=(ALL) NOPASSWD: /Path/To/Script and then in PHP run exec('cd /Path/To/Script(AndExecutable) && sudo -u User /Path/To/Script); Basically, It wouldn't run correctly unless I ran the script from the folder the executable was in, and it wouldn't run unless I used the entire path to the script as entered in my sudoers file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM