LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-19-2006, 04:43 PM   #1
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Rep: Reputation: 31
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.
 
Old 11-19-2006, 05:02 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
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.
 
Old 11-19-2006, 05:10 PM   #3
Tralce
Member
 
Registered: Nov 2006
Location: Maine
Distribution: Debian, Ubuntu, Gentoo
Posts: 109

Rep: Reputation: 15
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.
 
Old 11-19-2006, 05:47 PM   #4
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by macemoneta
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.

# setenforce 0
setenforce: SELinux is disabled
 
Old 11-19-2006, 05:53 PM   #5
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by Tralce
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.
You may look into modifying the sudoers file to allow a particular user on your system to temporarily run as root.

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.
 
Old 11-19-2006, 05:56 PM   #6
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Quote:
# setenforce 0
setenforce: SELinux is disabled
OK, now that you have disabled SELinux, test your code.
 
Old 11-19-2006, 07:41 PM   #7
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
It wasn't enabled before. That's why I posted the ouput of the command.
 
Old 11-19-2006, 09:06 PM   #8
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Sorry, I was distracted. I see that SELinux is disabled.

Last edited by macemoneta; 11-19-2006 at 09:15 PM.
 
Old 11-20-2006, 02:23 PM   #9
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by macemoneta
Sorry, I was distracted. I see that SELinux is disabled.
Thank you for trying.
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.
 
Old 11-20-2006, 02:40 PM   #10
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Well, if you are running through your web browser, the error logs in /var/log/httpd/ should indicate any errors that were encountered.
 
Old 11-20-2006, 06:12 PM   #11
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
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.
 
Old 11-20-2006, 06:26 PM   #12
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
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 ...
 
Old 11-21-2006, 02:18 AM   #13
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by macemoneta
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 ...
I've been using:
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't run X programs remotely mcshen Linux - General 2 07-28-2005 07:47 PM
Is it possible to run ethereal remotely via the commandline? abefroman Linux - Security 5 05-09-2005 11:10 PM
Are you suppose to be able to run X remotely? abefroman SUSE / openSUSE 15 05-09-2005 03:34 PM
With GTK can you run it remotely? abefroman Linux - Software 2 05-08-2005 04:13 AM
Unable to run X applications remotely pree Linux - Software 0 06-27-2003 01:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration