LoginSignup
6
4

More than 5 years have passed since last update.

phpのshell_exec()でsudoコマンドを実行する方法

Last updated at Posted at 2016-09-24
passwd apache
任意のパスワードを入力

yum -y install sudo
visudo

下記のように編集する。

apache  ALL=(ALL)       ALL
#Defaults    requiretty

PHPの実装は下記のようにする。

$command = "echo 'パスワード' | sudo -S sh test.sh";
shell_exec($command);

これで、test.sh をroot権限にて実行することが可能となる。

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4