0

I know that this question has been discussed before but i still can't find a solution. I'm trying to execute a Bash script from a PHP file on a (really small) website which is run using the PHP built in webserver. When running the PHP file in the terminal with

php -f test.php

it works fine and the bash script executes. However when i start the webserver and call the PHP function from the website, nothing happens. The Bash script is invoked with:

exec('/home/user/website/bash_script', $out, $return);

inside the PHP-file and i get that return = 1. On the website the PHP script that executes the bash-script is called by another PHP script through:

<input type="button" value="..." onclick="location='test.php'"/>

I first thought that it was a problem with my permissions, but i added the script-file in visudo to be able to run it as super-user without password but still no luck. I also changed the file permissions to 755. Here is test.php (which works fine when run through the terminal):

<?php
        exec ('/home/user/website/test');
?>

Also i CAN execute exec('cp bla bla2'); from the webserver so theres no problem with exec()

EDIT------------------------------------------------------------------------

The Bash script is sending a command to a different screen and it seems that this is the root of the problem. I think that this can solve my problem: Screen -X isn't working ("No screen found")

7
  • Maybe a user issue. on web you are 'www-data' on shell mostly 'root', test it print `whoami`; Commented Sep 20, 2016 at 18:51
  • I ran exec('whoami') and it says my username, so this should not be a problem right? Commented Sep 20, 2016 at 18:53
  • On both, web and shell? Commented Sep 20, 2016 at 18:54
  • Just tried it again and since i changed all permissions it now says 'root' on both web and shell Commented Sep 20, 2016 at 19:02
  • 1
    This is the problem: stackoverflow.com/questions/22263204/… Commented Sep 20, 2016 at 19:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.