LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-10-2014, 03:38 AM   #1
bellhuang
LQ Newbie
 
Registered: Feb 2010
Location: China
Posts: 18

Rep: Reputation: 0
Thumbs up how to use web to invoke php program, and the php program call c program


with apache as server and safe_mode = off, after the data submitted by form post mode, the php program was invoked, then the php program call c program which located in an other directory by exec command. The problem is that it is seemed that exec command can run, but the c program couldn't be called. How to solve this problem? thanks.
 
Old 01-10-2014, 01:55 PM   #2
mpapet
Member
 
Registered: Nov 2003
Location: Los Angeles
Distribution: debian
Posts: 548

Rep: Reputation: 72
Does the apache user have permission to execute your program??

Does the apache server have access to the executable's path??
 
Old 01-10-2014, 02:02 PM   #3
Smokey_justme
Member
 
Registered: Oct 2009
Distribution: Slackware
Posts: 534

Rep: Reputation: 203Reputation: 203Reputation: 203
Could you at least provide some sort of error message or more details about "exec command can run, but the c program couldn't be called"?

Also, a copy/paste of your relevant php lines would be great... Maybe there lies the problem..
 
Old 01-10-2014, 07:23 PM   #4
bellhuang
LQ Newbie
 
Registered: Feb 2010
Location: China
Posts: 18

Original Poster
Rep: Reputation: 0
1. In the log/messages exists:
Executable '/usr/local/bin/excutableCprogram' doesn't belong to any package

2.
a. test1.php
<?php exec("/usr/local/bin/excutableCprogram $a",$output); ?>
It can run with php test1.php

b. test2.php
<?php
$a=$_POST['data'];
$output=NULL;
exec("ls /usr/local/bin/",$output);
?>
It can run after form submitted.

c. test3.php
<?php
$a=$_POST['data'];
$output=NULL;
exec("/usr/local/bin/excutableCprogram $a",$output);
?>
It can't output anything.

thanks.
 
Old 01-10-2014, 08:23 PM   #5
bellhuang
LQ Newbie
 
Registered: Feb 2010
Location: China
Posts: 18

Original Poster
Rep: Reputation: 0
Maybe it give some hints: example in a can only run with root, general user can't output anything. Is it helpful set env to locate executable program as ls command?
 
Old 01-11-2014, 12:59 PM   #6
Smokey_justme
Member
 
Registered: Oct 2009
Distribution: Slackware
Posts: 534

Rep: Reputation: 203Reputation: 203Reputation: 203
Please run the following php script and see the output:

PHP Code:
<?php

echo "<pre>"//Just in case you run it from a browser
echo "Exec returned: " exec('echo "All Ok!"',$output) . "\n";
echo 
$output;
echo 
"</pre>";
If you'll see All Ok!.. Then it all works as expected...

If it does, can you run the executableCprogram as a normal user and see if it works..
Also try (while being root, since it won't work otherwise):
Code:
su -c /usr/local/bin/executableCprogram apache
Please replace 'apache' in the last command with the user in which your apache server works (usually 'apache' or 'httpd')
 
Old 01-12-2014, 02:55 AM   #7
bellhuang
LQ Newbie
 
Registered: Feb 2010
Location: China
Posts: 18

Original Poster
Rep: Reputation: 0
hi Smokey_justme, it can output "ALL OK", I'll try your other suggestion. Thanks.
 
Old 01-12-2014, 04:17 AM   #8
bellhuang
LQ Newbie
 
Registered: Feb 2010
Location: China
Posts: 18

Original Poster
Rep: Reputation: 0
I guess it's a privilege problem, can change to other user in exec function from php scrip?
 
Old 01-12-2014, 04:34 AM   #9
Smokey_justme
Member
 
Registered: Oct 2009
Distribution: Slackware
Posts: 534

Rep: Reputation: 203Reputation: 203Reputation: 203
Not really.. But can't you simply
Code:
chmod a+x /usr/local/bin/executableCprogram
?
 
Old 01-12-2014, 07:39 AM   #10
bellhuang
LQ Newbie
 
Registered: Feb 2010
Location: China
Posts: 18

Original Poster
Rep: Reputation: 0
in command line, with root privilege, the program can run in its directory, while using an other user e.g. user1, it can't work;
so I change the path to 777, user1 can work; but the browser still can't invoke the program.
What about to run it with cgi?
 
Old 01-13-2014, 06:09 AM   #11
bellhuang
LQ Newbie
 
Registered: Feb 2010
Location: China
Posts: 18

Original Poster
Rep: Reputation: 0
I have tried an other c program, it is no problem. So, maybe the previous program use unsuitable functions cause to its failure. Thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any way to execute a program which needs some input through a php web page?? maradnus Programming 1 12-07-2011 03:58 AM
LXer: Can't Program, won't Program? Then Mash the Web with Mozilla's Ubiquity LXer Syndicated Linux News 0 05-01-2010 12:30 PM
Ready-Made PHP program that lets me upload and access files on the web? apache2 Linux - Software 5 12-01-2008 10:48 PM
sms program and database in linux web program in windows.. does not see each other.. keikun_naruchan Programming 0 07-06-2005 01:40 AM
Is it possible to interact with java program on web by using PHP? antony_csf Programming 8 06-25-2004 09:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration