Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 06-26-2010, 07:51 PM   #1
LQ Newbie
Registered: May 2010
Posts: 13

Rep: Reputation: 0
How to execute shell commands that require root password from PHP ?

I am kinda new with php. I am developing a web-interface for an application that sometimes needs root privs. Editting /etc/sudoers is not an option since the web interface needs to be portable to other users when they install my application. Is there any workaround ?

PHP Code:
php code:

$command "./ /dev/$DISKNAME &";
$shellOutput shell_exec($command); 


sudo -u root -S ./a.out $DISK < /path/to/a/tmpfile/that/contains/root/password > check.log
check.log gets created. But the results of ./a.out dont show up in the log file. And the script works fine when run from the terminal. User doesnt have to enter password. But from PhP the log file is created and then the script exits with exit code 1. Is there anything i am doing wrong ? Anyone aware of how to achieve what I want to do ?

Any help would be highly appreciated.
Old 06-27-2010, 01:31 AM   #2
LQ Newbie
Registered: May 2010
Posts: 13

Original Poster
Rep: Reputation: 0
Old 06-27-2010, 08:16 AM   #3
LQ 5k Club
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
It's a bad idea to bump it yourself so soon because it disables the auto-bumping feature and also takes the thread of the zero-reply list.


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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to let the php/apache have the privileges to execute all the root shell commands another 1 Linux - Server 18 03-24-2009 08:37 AM
wesite which i can open and execute shell commands online sharma.kashyap Linux - General 1 02-12-2007 10:48 PM
Shell won't execute commands.... frank320 Red Hat 6 03-17-2006 11:12 AM
PHP -- How to execute a shell script from PHP using FTP functions?? zoonalex Programming 3 07-29-2004 11:51 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:39 PM.

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