Page 1 of 1

problems in executing linux commands from php

Posted: Thu Apr 15, 2004 8:46 am
by tushar_akolkar
hi to all,
i am running php 4.3 on fedora core 1 in my script i am trying to execute some linux commands such as service vsftp stop . i am using backtick operator, shell_exec,exec commands but still the service is not stopping when i check it from console. i am executing the script not with root user but with a user in which the uid value is 0 i.e i am also included in root,apache and ftp groups.

can someone help me to solve this problem i am in very urgent need to solve this problem.

waiting for a reply from the form.

thanks..

tushar akolkar.

Posted: Thu Apr 15, 2004 11:36 am
by penguinboy
It would be helpful if you posted the code that's giving you trouble.

Posted: Thu Apr 15, 2004 12:10 pm
by Deemo
try doing another command, like mkdir in your home directory. this would find out whether it is the php or if it is th vsftpd that is causing the problem ;)

Posted: Thu Apr 15, 2004 3:02 pm
by Pyrite
Remember that PHP executes commands under the same user/group that the Apache (or Web Server) daemon runs as. In short, you will probably need to setup sudo to do this, so that the user that Apache runs under (nobody or http) can execute a sudo command to stop vsftpd.

here's the code in which getting problem

Posted: Fri Apr 16, 2004 1:27 am
by tushar_akolkar
hi to all,
thanx for your reply i am posting here the code in which i am getting error.

<?php
$status = `service vsftpd status 2>&1 1>/dev/null`;
$result = `service vsftpd stop 2>&1 1>/dev/null`;

system('service vsftpd status');
system('service vsftpd stop');

if(strcmp(trim($status),"" == 0))
echo "<BR>vsftpd is running....";
else
echo "<BR>Error....";

if(strcmp(trim($result),"" == 0))
echo "<BR>service vsftpd stopped successfull...";
else
echo "<BR>Error .....";
?>

after running this script i am getting output as follows:
vsftpd (pid 1805) is running... Shutting down vsftpd: [FAILED]
vsftpd is running....
service vsftpd stopped successfull...


well i still want to add one thing that i am running php module under apache so does it makes any effect for executing linux commands from php and well most other commands like mkdir, ls, etc. r running from my php script but well the problem above is still unsolved and i want to implement this thing. if this is not possible this way then is there any other way to solve the problem . pls help me its urgent......

i hope my problem is now quite clear with u....
plese do the need ful.
waiting for a reply from u....


tushar akolkar

Posted: Sat Apr 17, 2004 10:40 am
by Pyrite
Look into sudo man ..