如何使用exec PHP关闭Ubuntu [英] How to shutdown Ubuntu with exec PHP

查看:66
本文介绍了如何使用exec PHP关闭Ubuntu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的需要使用PHP exec关闭ubuntu.但是我的许可可能有问题.

I really need to shut down ubuntu with PHP exec. But I probably have some problem with permission.

echo exec('whoami')

返回没人";

所以我放入控制台

adduser nobody admin

并尝试

exec("shutdown -h now");

但是它不起作用;(

推荐答案

授予用户PHP作为root权限运行是高度危险.这根本不是一个好主意,因为如果利用了PHP脚本中的漏洞,则可以打开整个服务器.在生产服务器上,这绝对是不可接受的.

Giving the user PHP runs as root rights is highly dangerous. This is not a good idea at all, because you open up your whole server if a vulnerability in a PHP script gets exploited. On a production server, this is absolutely not acceptable.

我知道,安全地执行此操作的唯一方法是让cron作业每分钟左右以root身份运行一个shell脚本. Shell脚本会测试是否存在诸如shutdown_now.txt之类的文件.如果文件存在,脚本将启动关闭过程.如果指示,PHP脚本将创建关闭文件.

The only way to do this securely that I know of is having a cron job run a shell script as root every minute or so. The shell script tests for the presence of a file like shutdown_now.txt. If the file exists, the script starts the shutdown procedure. The PHP script creates the shutdown file if so instructed.

我对Shell脚本不够精通,无法提供示例,但是我敢肯定,如有必要,有人可以.

I'm not well versed enough in shell scripting to provide an example, but I'm sure somebody can if necessary.

这篇关于如何使用exec PHP关闭Ubuntu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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