Solved

apache & PHP 'exec'??

Posted on 2010-11-27
6
557 Views
Last Modified: 2012-05-10
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
Comment
Question by:simonlai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 18

Expert Comment

by:Sudaraka Wijesinghe
ID: 34224198
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
 
LVL 1

Author Comment

by:simonlai
ID: 34224227
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
 
LVL 1

Author Comment

by:simonlai
ID: 34224229
this my command

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

Open in new window

0
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 
LVL 18

Accepted Solution

by:
Sudaraka Wijesinghe earned 500 total points
ID: 34224269
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
 
LVL 1

Author Closing Comment

by:simonlai
ID: 34224338
thanks for your guide...... sudaraka
0
 
LVL 18

Expert Comment

by:Sudaraka Wijesinghe
ID: 34224389
You are welcome, Thanks for the points.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question