• Uncategorized

About php : Web-page-does-not-run-shell-script

Question Detail

I’ve made a simple webpage that has to run some simple bash scripts. I run apache2 on Jetson Nano and I have three files in /var/www/html folder:

  • index.html
  • testexec.php
  • test.sh

First one looks like:

<!DOCTYPE html>
        <meta charset="UTF-8">
    <form action="testexec.php">
        <input type="submit" value="Create file">

the php file:

$output = shell_exec("test.sh");



touch file.txt

My problem is that everything looks good, but the scrit doesn’t run. In future it will be used to run program written in python, but for now I can’t run even that simple one. Is the problem with location of files or with something else?

I’ve already tried to change php file

$output = shell_exec("test.sh");


$output = exec("test.sh");

with or without $output

My browser (firefox) returns no errors in console.

Script works fine when I run it from shell. It is executable.

I’ve already tried to look for similar problems, but there were no solutions.

Question Answer

Very often the problem is with user rights, first try installing chmod 777 test.sh to just check if this is the problem.
In addition, you should go back to the exec documentation

exec(string $command, array &$output = null, int &$result_code = null): string|false

and check what $result_code is equal to.

If we get echo result!:

exec('echo $(pwd);', $output, $retval);
echo "${retval} with value:\n";

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.