Jump to content

My exec function in php is not working in centos


malam

Recommended Posts

I have a username alam for the server I have sudo access to execute linux commands. I could configure almost all files the root can do.

 

I wrote this script on the server for test as I need to provide the server some functionality

-----------------

<?php
$cmd="ls -l";

echo exec($cmd,$ret_value) . "<br />DONE";

echo "<pre>".shell_exec($cmd)."</pre>DONE";
?>

------------------

I get the OUTPUT as follows -

------------------

 

DONE

DONE

 

--------------------  :'(  :confused:  :o

 

I am novice user of Linux however any kind of help will be appreciated ..........

 

 

 

If your server is running in safe_mode, the exec related commands are disabled.  Also individual functions can be disabled via the php.ini file, using the disable_functions directive.  You should look at the output of phpinfo() to see if there are restrictions in place.  Your code should work fine on a server that doesn't have some sort of restriction in place.

Dear Gizmola

 

Thank you for your reply, I have checked disable functions in php.ini and my php is not running in safe mode. The same code is working in xampp but not the LAMP. I am attaching the phpinfo() file please have a look. please remove the .doc extension as this forum only support .doc and other image files.

 

Thank you once again for a quick reply.

 

[attachment deleted by admin]

It could also be that there is no $PATH variable setup for the Apache process. You'll need to supply the full path to any commands. eg;

 

$cmd="/bin/ls -l";

Dear Thorpe,

Thank you for your reply. I have tried but it did not work. Could you suggest me how to run system commands from php in linuxbox. I guess that will much easier to explain ......

Thanks once again for ur reply

 

 

  • 9 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.