Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 10-20-2006, 03:57 PM   #1
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/

The shell script:


echo "This is a test."

The PHP code:

$r = exec("sudo /home/<user>/bin/", $arrayOutput, $exeStatus);
if($exeStatus == 1)
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.


Last edited by mr_scary; 10-20-2006 at 04:00 PM.
Old 10-20-2006, 05:06 PM   #2
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: 78
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/ 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.

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
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.


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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:22 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