如何从php文件重启Linux [英] how to do a linux reboot from php file

查看:242
本文介绍了如何从php文件重启Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的linux系统上有一个brftv用户,我有运行nginx的www-data.

I have a user brftv on my linux system and I have www-data that runs the nginx.

从终端我可以让我的brftv用户运行

from the terminal I can let my brftv user run

sudo /sbin/reboot

,它工作正常,因为我在/etc/sudoers文件的#用户权限规范"部分中添加了以下内容:

and it works fine since I added the following to my /etc/sudoers file's "#user privilege specification" section:

brftv ALL=NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/poweroff
www-data ALL=NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/poweroff

但是当我的php文件运行以下代码时,什么也没发生

But when my php file runs the following code, nothing happens

exec('nohup sudo -u brftv /sbin/reboot');

我将www-data行添加到上面的etc/sudoers中,以防在运行上述exec()时有必要(即使我以-u brftv身份运行它,但我不是Linux专家,只是认为更好以防万一).

I added the www-data line to the etc/sudoers above in case it was necessary when running the above exec() (even though I run it as -u brftv, but I'm no linux expert, just thought better be safe just in case).

运行exec()的php文件归www-data所有,而chmod为777,因此所有文件都应具有从其执行的特权.

The php file that runs this exec() is owned by www-data, and chmod is 777, all should thus have privilege to execute from it.

我尝试通过浏览器(我假设用户www-data运行)和从终端$ php myFile.php运行php文件.

I have tried running the php-file both through browser (would be run by user www-data I assume) and from terminal $ php myFile.php.

-------------------更新-----------------

------------------- UPDATE -----------------

我做到了

sudo chmod u s /sbin/reboot

这允许我系统上的所有用户在没有密码的情况下运行重新启动cmd.它可以工作,但是我宁愿不打开它,所以如果有人暗示我的问题是...,那么使用/etc/sudoers的其他解决方案会更好.

Which allows all users on my system to run the reboot cmd without password. It works, but I rather not leave it THAT open, so the other solution with /etc/sudoers would be better, if someone would have a hint at what my problem is...

我遵循了此教程 http ://linux.byexamples.com/archives/315/how-to-shutdown-and-reboot-without-sudo-password/,第二个例子几乎是我所得到的,但不适用于我..

I followed this tut http://linux.byexamples.com/archives/315/how-to-shutdown-and-reboot-without-sudo-password/ and the second example is pretty much what I got above that didn't work for me..

推荐答案

在系统上运行此方法的唯一方法是通过更改/sbin/reboot上的chmod来破解"它 像这个家伙一样

The only way I got this to work on my system was to "hack" it by changing chmod on /sbin/reboot like this guy did

http://linux .byexamples.com/archives/315/如何关闭和重新启动而没有sudo密码/

sudo chmod u + s/sbin/reboot

sudo chmod u+s /sbin/reboot

我意识到这在很多情况下可能不是最佳选择,但是该mediaPlayer已被锁定,因此无论如何都无法访问任何终端.

I realize this might not be optimal in many cases, but this mediaPlayer is very much locked down so there is no accessing a terminal for anyone else anyways.

这篇关于如何从php文件重启Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆