Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 597
  • Last Modified:

apache & PHP 'exec'??

Dear all:

i try using with php 'exec' to execute a linux command. but it given non-response (not output).

but once i run the command with ssh, not problems on the command.

beside that i have check audit.log, can't found any log related. And i was add permission under sudoers file.

apache  ALL=NOPASSWD:/usr/local/bin/tesseract   ALL


can any one guide how to troubleshoot? I was try with & without SELINUX.


thanks.
0
simonlai
Asked:
simonlai
  • 3
  • 3
1 Solution
 
Sudaraka WijesingheWeb Application ProgrammerCommented:
Is it just not providing out put or command not executing at all?

To get an out put in exec you need to initialize the second parameter as an array.

$output=array();
exec('/command/here', $output);

Open in new window

0
 
simonlaiAuthor Commented:
thanks for reply. sudaraka.

The command wiill generate a txt file in the direction. But it was not. Even i disabled SELINUX, still not able to run the command with apache.

I checked the direction, the permission was open.


thanks.
0
 
simonlaiAuthor Commented:
this my command

exec("tesseract /var/www/html/ipc/ocr/".$destination." /var/www/html/ipc/ocr/uploadfile/".$nameFile."");

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Sudaraka WijesingheWeb Application ProgrammerCommented:
You can use the 3rd parameter on exec to get the error code returned from the OS, check that to see if you get something meaningful.
$error=0;
$output=array();

exec("tesseract /var/www/html/ipc/ocr/".$destination." /var/www/html/ipc/ocr/uploadfile/".$nameFile."", $output, $error);

echo "Error: $error";

Open in new window

0
 
simonlaiAuthor Commented:
thanks for your guide...... sudaraka
0
 
Sudaraka WijesingheWeb Application ProgrammerCommented:
You are welcome, Thanks for the points.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now