How to run a command remotely
I can run this command successfully over ssh.
#/usr/bin/mplayer [options] I want to be able to do the same using PHP. But doing the following inside a php script does not work: exec("/usr/bin/mplayer [options]"); I know the php's exec() works, since the following worked when I tried it: exec("echo '/usr/bin/mplayer [options]' > /tvoutput"); So, I concluded that it must be that apache, which my web server runs as must not have permission to run the command /usr/bin/mplayer. I then added apache to sudoers file. But then this still doesn't work: exec("sudo /usr/bin/mplayer [options]"); If I can issue /usr/bin/mplayer [options] from an ssh terminal and get the desired effect, I'm just baffled as to why I can't do it via a PHP script. This is obviously not a PHP issue, since the command is being handed to linux correctly. Any ideas? Sorry about the long explanation. Thx. |
This sounds like SELinux saving you from yourself. To verify check your /var/log/messages or /var/log/audit/audit.log for AVC denied messages. You can also temporarily disable SELinux to test with (as root):
setenforce 0 If it works, then you can re-enable SELinux with: setenforce 1 You'll either need to create a local policy to enable execution, or check the booleans under menu System->Administration->Security Level and Firewall on the SELinux tab, HTTPD Service. One of the booleans may allow you to do what you are trying to accomplish. |
I'm having EXACTLY the same issue running a shell script from PHP, because the shell script needs to modify some of root's files.
|
Quote:
# setenforce 0 setenforce: SELinux is disabled |
Quote:
I think it goes something like this: your_non_root_user ALL=(root) NOPASSWD: /command/to/run Although people say it's not advisable to allow a user to run as root, but you can restrict the permission to just a single command as shown above. |
Quote:
|
It wasn't enabled before. That's why I posted the ouput of the command.
|
Sorry, I was distracted. I see that SELinux is disabled.
|
Quote:
If you have other ideas, please share. Is there a way to know if an error message is returned? tail /var/log/messages shows nothing related to it. |
Well, if you are running through your web browser, the error logs in /var/log/httpd/ should indicate any errors that were encountered.
|
You're correct. /var/log/httpd/error_log has this
sudo: sorry, you must have a tty to run sudo After a little searching online, I found out FC6 has added more restrictions to sudo: Defaults requiretty I commented that out, and am no longer getting any errors in error_log, although my command still won't run. I'm one step closer, thanks to you, but not quite there yet. |
The next question I would have is, are you specifying the display (apache doesn't have one)? For example, if you are sending the video to your TV, the second head on your video card:
...mplayer -display :0.1 ... |
Quote:
DISPLAY=:0.1 /usr/bin/mplayer instead of your suggestion of: /usr/bin/mplayer -dispaly :0.1 Anyway, after brooding over a few more hurdles, I finally go it to do what I wanted. You've been a tremendous help. Not being formally trained in linux is a challenge for me. But with guys like you, and my resilience, it often works out in the end. |
All times are GMT -5. The time now is 07:09 PM. |