Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
5
Help us understand the problem. What is going on with this article?
@kenichiro-yamato

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

More than 3 years have passed since last update.
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権限にて実行することが可能となる。

5
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
kenichiro-yamato
やまと・けんいちろう。1977年生。IT・Web業界での実務経験23年(正社員16年、フリーランス7年)。サーバサイドを中心にインフラからフロントまで幅広く対応。部下10名以上の管理職経験あり。東京在住。ITシステム常駐開発やコンサルティング案件に対応中。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
5
Help us understand the problem. What is going on with this article?