LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-20-2006, 03:57 PM   #1
mr_scary
Member
 
Registered: Aug 2006
Posts: 39

Rep: Reputation: 15
Running shell script with PHP in Apache


What is the best way to run a simple Bourne shell script from a PHP script in Apache?

I thought sudo would do the trick.

Contents of /etc/sudoers:

apache ALL = (<user>) NOPASSWD: /home/<user>/bin/test.sh

The shell script:

#!/bin/sh

echo
echo "This is a test."
echo


The PHP code:

$r = exec("sudo /home/<user>/bin/test.sh", $arrayOutput, $exeStatus);
if($exeStatus == 1)
{
print_r($arrayOutput);
}
else
{
print("Process Failed!");
}

But I keep getting "Process Failed!". What am I missing?

I originally had nologin as apache user shell so I put /bin/sh.

--
Peter

Last edited by mr_scary; 10-20-2006 at 04:00 PM.
 
Old 10-20-2006, 05:06 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 77
I am not sure, but I have seen plenty of problems in these forums of people trying to run sudo scripts through PHP. Perhaps you can have a search and see if any of them have been resolved.

Perhaps it is also a permissions issue. Does apache have permission to access /home/<user>/bin/test.sh? Typically your home directory is chmod 700, so apache will not be able to access the script.

As an aside, it is probably better to rewrite whatever code is in this script into pure PHP if possible.

Quote:
I originally had nologin as apache user shell so I put /bin/sh
Please do change that back. apache does _not_ need a login shell to run a script.
 
Old 10-20-2006, 05:17 PM   #3
mr_scary
Member
 
Registered: Aug 2006
Posts: 39

Original Poster
Rep: Reputation: 15
I gave apache user a shell because I thought it was necessary for sudo to work.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running shell commands thru PHP JonathonReinhart Linux - Software 1 12-23-2005 03:05 AM
Call a shell script from php? jharper101 Programming 2 02-15-2005 01:51 AM
PHP -- How to execute a shell script from PHP using FTP functions?? zoonalex Programming 3 07-29-2004 12:51 PM
converting shell script to php script ? ibro Linux - General 6 05-24-2004 06:19 AM
c/c++ running a shell script? thermalpants Programming 3 05-12-2002 12:41 PM


All times are GMT -5. The time now is 06:10 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration