-1

i am trying to execute pkill command by php script.

killengine.sh script runs fine from terminal, both with ./killengine.sh and php restart.php.

this is killengine.sh

#!/bin/bash
sudo pkill -f  engine

and this is restart.php

$out = shell_exec("/var/www/killengine.sh 2>&1");
var_dump($out);

Both files have 755 permissions. Ownew of restart.php is apache, and root is owner of killengine.sh. Also i tried with both owners to be root/apache.

In visudo i made this changes:

Defaults:apache !requiretty

but i get: "sudo: no tty present and no askpass program specified"

Then i tried with

Defaults!/var/www/killengine.sh !requiretty

then i get: "sudo: sorry, you must have a tty to run sudo"

Also, this line is present all the time at the EOF

apache ALL=NOPASSWD: /var/www/killengine.sh

but without success.

OS is Centos 6

Any ideas?

Aleks
  • 45
  • 9
  • Running `sudo` from a script is never really the best of ideas. - Although if that is the necessity, which is understandable please do refer to [this link.](https://stackoverflow.com/questions/3173201/sudo-in-php-exec) – Julian Camilleri Feb 27 '18 at 14:18

1 Answers1

0

solution:

changed restart.php to

$out= @shell_exec("sudo /var/www/killengine.sh");
Aleks
  • 45
  • 9