Solved

apache & PHP 'exec'??

Posted on 2010-11-27
6
545 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

726 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