PHP run sudo command with shell_exec () [closed]

3

I have the following problem, I'm trying to run a sh file with php using shell_exec for example:

echo shell_exec("./example etc etc");

My problem is that it does not run, is it some permission problem? When I type: php x.php it returns right (I just tested it with the root user)

    
asked by anonymous 11.11.2016 / 01:12

1 answer

4

If you want to run the command through the file url, example link and in that test.php has your shell_exec, you need make sure Apache is allowed to execute this command.

To give permission to Apache just know the user, this will depend on the distribution of Linux you are using. If you are using CentOS it will be Apache even if you are using Ubuntu will be www-data .

After you know that, check the file path where the files you want to run the sudo permission by Apache, then you edit the sudoers

vim /etc/sudoers

and add the following line.

apache          ALL=(root)  NOPASSWD: /caminho/da/sua/pasta

or

www-data        ALL=(root)  NOPASSWD: /caminho/da/sua/pasta

You will basically be telling the server that your Apache is allowed to run the files in this folder as root .

    
11.11.2016 / 05:44