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

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

  • 9 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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