2

I am trying to execute a exec command, and I am having problems. When I run the following code, it doesn't work when I run it through the browser. but if I take the output of $str copy and paste it into a terminal it works just fine. What would be causing this and how can I fix it? Currently I am running on localhost.

$php_location = "/usr/bin/php";
$data = str_replace("\"", "\\\"", json_encode($_POST));
$cwd = __DIR__;

shell_exec($str = "$php_locataion $cwd/phpExcel.php \"$data\" > /home/ryannaddy/Desktop/phpExcel.txt &");

echo $str;

Here is the file shell_exec is calling:

<?php
set_time_limit(0);
$args = $argv[1];

$data = json_decode(str_replace("\\\"", "\"", $args), true);
echo "hello!";
0

2 Answers 2

5

When you run it through the browser, it executes as the user for the web server who may not have the correct permissions. When you run it in the terminal it executes as whatever user you are logged in as. Check that the apache (assuming you are using apache) user has the correct permissions to the script / directory.

Sign up to request clarification or add additional context in comments.

2 Comments

if I do top it says apache is running as root
Basically apache didn't have access to write to my desktop, So I told it to write to my web dir. Thanks!
2

The issue likely has to do with permissions.

When you run something from the shell, it runs under your user account. The web server will be running as something differently, generally with very few permissions to anything. Either give the web server's account the appropriate permissions, or run the server under a different account (not recommended!).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.