Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-10-2014, 03:38 AM
|
#1
|
LQ Newbie
Registered: Feb 2010
Location: China
Posts: 18
Rep:
|
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.
|
|
|
01-10-2014, 01:55 PM
|
#2
|
Member
Registered: Nov 2003
Location: Los Angeles
Distribution: debian
Posts: 548
Rep:
|
Does the apache user have permission to execute your program??
Does the apache server have access to the executable's path??
|
|
|
01-10-2014, 02:02 PM
|
#3
|
Member
Registered: Oct 2009
Distribution: Slackware
Posts: 534
|
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..
|
|
|
01-10-2014, 07:23 PM
|
#4
|
LQ Newbie
Registered: Feb 2010
Location: China
Posts: 18
Original Poster
Rep:
|
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.
|
|
|
01-10-2014, 08:23 PM
|
#5
|
LQ Newbie
Registered: Feb 2010
Location: China
Posts: 18
Original Poster
Rep:
|
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?
|
|
|
01-11-2014, 12:59 PM
|
#6
|
Member
Registered: Oct 2009
Distribution: Slackware
Posts: 534
|
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')
|
|
|
01-12-2014, 02:55 AM
|
#7
|
LQ Newbie
Registered: Feb 2010
Location: China
Posts: 18
Original Poster
Rep:
|
hi Smokey_justme, it can output "ALL OK", I'll try your other suggestion. Thanks.
|
|
|
01-12-2014, 04:17 AM
|
#8
|
LQ Newbie
Registered: Feb 2010
Location: China
Posts: 18
Original Poster
Rep:
|
I guess it's a privilege problem, can change to other user in exec function from php scrip?
|
|
|
01-12-2014, 04:34 AM
|
#9
|
Member
Registered: Oct 2009
Distribution: Slackware
Posts: 534
|
Not really.. But can't you simply
Code:
chmod a+x /usr/local/bin/executableCprogram
?
|
|
|
01-12-2014, 07:39 AM
|
#10
|
LQ Newbie
Registered: Feb 2010
Location: China
Posts: 18
Original Poster
Rep:
|
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?
|
|
|
01-13-2014, 06:09 AM
|
#11
|
LQ Newbie
Registered: Feb 2010
Location: China
Posts: 18
Original Poster
Rep:
|
I have tried an other c program, it is no problem. So, maybe the previous program use unsuitable functions cause to its failure. Thanks.
|
|
|
All times are GMT -5. The time now is 12:38 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|