LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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

Closed Thread
 
Search this Thread
Old 11-15-2005, 06:45 AM   #1
rome
LQ Newbie
 
Registered: Nov 2005
Posts: 3

Rep: Reputation: 0
PHP can't execute shell command !


Hello world,
I've installed my PHP application on a remote server with Debian Linux and
plesk 7.5 reloaded, my assigned php-user is www-data (instead of the default "apache") and every command that I call with "exec" or "shell_exec" or "system" return the error code 127.

if I enter the shell as root I can do anything but
whenever I type "su - www-data" the return is "no shell"

So I don't know wether this is caused by some php configuration directives or OS user permissions settings.

who knows debian and plesk ? who knows this problem ?
my server administrators don't know how to resolve this issue.

help me !
 
Old 11-15-2005, 07:17 AM   #2
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 56
The user hasn't been setup with a shell by the looks of it. Post the output of this command:
Code:
/etc/passwd | grep www-data | sed -e "s/.*://g"
You'll need to run it as root but that uses sed to chop out everything we don't need which may include an encrypted password. This will only show us the login shell and if my guess is right then you just need to change the end of this line to read /bin/bash
 
Old 11-15-2005, 07:49 AM   #3
rome
LQ Newbie
 
Registered: Nov 2005
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by cs-cam
The user hasn't been setup with a shell by the looks of it. Post the output of this command:
Code:
/etc/passwd | grep www-data | sed -e "s/.*://g"
You'll need to run it as root but that uses sed to chop out everything we don't need which may include an encrypted password. This will only show us the login shell and if my guess is right then you just need to change the end of this line to read /bin/bash
All right, I solved it.

The issue was a little bit more complicated than that.
/bin/bash had weird permissions: (was not executable but by root user)
Having changed them with
Code:
chmod o+rx /bin/bash
changes the error code returned by system("id", $ret_code) invoked in php, from 127 to 126.
That should, from "path not found", to "command was not executable".

Then I discovered that the whole bin/ and /usr/bin/ directories had weird permissions (group ownler couldn't execute nor read).
Giving read and execute permissions to all the commands solved the issue.
I guess it had to do with the plesk installation.

By the way, running
Code:
cat /etc/passwd | grep www-data | sed -e "s/.*://g"
returns
Code:
/bin/false
since usually there's no need to assign a shell to apache users.

And letting the user have /bin/false as a shell does not stop php from running shell commands through exec.

Thanks anyway for your help.





Any idea?

Last edited by rome; 11-15-2005 at 08:00 AM.
 
Old 11-15-2005, 12:46 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,485
Blog Entries: 54

Rep: Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902
Please do not crosspost again

//Moderator note: you have crossposted a message, which is against the LQ Rules. Cross-posting is considered bad netiquette on your part, a waste of resources on LQ's part and a waste of time for LQ members who take the time your question.
Please do not do that again.

FUP to: http://www.linuxquestions.org/questi...hreadid=383277
 
  


Closed Thread


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
execute shell command inside of c code? khucinx Programming 6 10-26-2010 09:30 PM
PHP can't execute shell command ! rome Programming 1 11-15-2005 09:12 AM
php/max time exceeded/execute via shell? jdc32 Linux - Software 0 01-31-2005 05:22 AM
cannot execute 'cd /' shell command from PL/SQL.... samyakm Linux - Newbie 1 01-03-2005 10:10 AM
PHP -- How to execute a shell script from PHP using FTP functions?? zoonalex Programming 3 07-29-2004 11:51 AM


All times are GMT -5. The time now is 01:19 PM.

Main Menu
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