Solved

exec() works locally but not remotely

Posted on 2003-11-23
2
719 Views
Last Modified: 2013-12-13
I have this:

index.php
-----------
<?
echo "Execute Test<br>";
$num = 1;
$array = array();
$str = exec("php.exe myFile.php",$array,$num);
echo "$str<br>";
foreach($array as $k=>$v)
  echo "$k $v<br>";
?>

This works locally on my computer (Apache 2.0.47) but doesn't work my host's server (Apache 1.3.28).  I know exec() is permitted on my host's server b/c I told them I needed to use this function and they put me on a server that allows it (also, the first server they had me on gave me an error saying exec() was disabled for security reasons when I tried to use it).  So I think the problem is in the path I giving.  I've tried these variations:

exec("/php.exe myFile.php",$array,$num)
exec("./php.exe myFile.php",$array,$num)
exec("/www/php.exe myFile.php",$array,$num)
exec("/home/{my username}/www/php.exe myFile.php",$array,$num)

php.exe is the Command Line Interface version of PHP which is in the same directory as myFile.php and index.php.  There's no output from the 'echo $str' line or the foreach loop, but I do see "Execute Test" at the top of the screen.  One difference between my local and remote exec() lines is that I give the full path (C:\...) to the php.exe locally but not remotely b/c I don't know the full remote path.  What's going wrong here?

bmh
0
Comment
Question by:bmh777
2 Comments
 

Accepted Solution

by:
bmh777 earned 0 total points
ID: 9815553
I got it to work.  I had to put a server directive in myFile.php that tells the server to use the PHP executable to parse the file.  I also had to chmod myFile.php to 755.

bmh
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
The viewer will learn how to count occurrences of each item in an array.

825 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