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

查看:578
本文介绍了如何以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正在使用的用户).我该怎么做才能以根用户身份执行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"文档.

Have a look at the "sudo" documentation.

您应该能够将所需的所有命令设置为"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天全站免登陆