0

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>
<html>
     <head>
        <meta charset="UTF-8">
        <title>TEST</title>
     </head>
  <body>
    <form action="testexec.php">
        <input type="submit" value="Create file">
    </form>
  </body>
</html>

the php file:

<?php
$output = shell_exec("test.sh");
header('Location: http://192.168.25.16/index.html?success=true');
?>

script:

#!/bin/bash


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");

with

$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.

1 Answers1

0

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!:

$output=null;
$retval=null;
exec('echo $(pwd);', $output, $retval);
echo "${retval} with value:\n";
print_r($output);
Zlatov
  • 126
  • 1
  • 6
  • He says in a comment he's getting output from the script if he adds an echo, so it's not a permission problem. – Barmar Jan 04 '22 at 18:30
  • if we get a response from echo then it is worth checking echo $(pwd). – Zlatov Jan 04 '22 at 18:50
  • *0 with value: Array ( [0] => /var/www/html ) * <-- this is response to your script – Master1521 Jan 04 '22 at 19:10
  • but `exec('touch file.txt', $output, $retval);` the file is not created? – Zlatov Jan 04 '22 at 19:18
  • it didn't create file – Master1521 Jan 04 '22 at 20:05
  • Please show output `stat /var/www/html` and `systemctl | grep php` and `systemctl status phpX.X-fpm.service`. I have replicated your code on my local server. My file is being created. I am sure that the reason is precisely the lack of rights for the user to create files. You need to check the php-fpm user. – Zlatov Jan 05 '22 at 08:35