如何以 root 身份运行 PHP exec()? [英] How to run PHP exec() as root?

查看:59
本文介绍了如何以 root 身份运行 PHP exec()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 PHP 构建防火墙管理器,但是当我执行时,<?php exec('iptables -L');?>,结果数组为空.

I'm trying to build a firewall manager in PHP, but when I execute, <?php exec('iptables -L'); ?>, the result array is empty.

我试过了,<?php echo exec('whoami');?>,响应为 www-data(Apache 正在使用的用户).我该怎么做才能以 root 身份执行 exec 函数?(最好不要更改 Apache 用户.)

I have tried, <?php echo exec('whoami'); ?>, and the response is www-data (the user that Apache is using). What can I do to execute the exec function as root? (Preferably without changing the Apache user.)

推荐答案

不要这样做!您将面临各种恶意黑客攻击.

Don't do it! You will leave yourself wide open to all sorts of malicious hackery.

查看sudo"文档.

您应该能够将您需要的所有命令设置为sudo"脚本.编写功能有限的特定脚本比公开要好得多底层特权命令.

You should be able to set up all the commands you need as "sudo"able scripts. It is much better to write specific scripts with limited functions than to expose the underlying priviledged command.

如:

exec ('sudo getIpTables.ksh')

这篇关于如何以 root 身份运行 PHP exec()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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