problems in executing linux commands from php

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
tushar_akolkar
Forum Newbie
Posts: 2
Joined: Thu Apr 15, 2004 8:46 am

problems in executing linux commands from php

Post 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.
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

Post by penguinboy »

It would be helpful if you posted the code that's giving you trouble.
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post 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 ;)
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post 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.
tushar_akolkar
Forum Newbie
Posts: 2
Joined: Thu Apr 15, 2004 8:46 am

here's the code in which getting problem

Post 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
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Look into sudo man ..
Post Reply