我是ubuntu apache
visudo在最下面添加代码 apache ALL=NOPASSWD:/sbin/ifconfig sbin 是ifconfig的路径
php代码为 $output=shell_exe("/usr/bin/sudo/sbin/ifconfig eth0 down");但是执行下来没有效果 引用如下方法
http://www.hkcode.com/linux-bsd-notes/341请大神们 指点我一下吧 跪求啊
visudo在最下面添加代码 apache ALL=NOPASSWD:/sbin/ifconfig sbin 是ifconfig的路径
php代码为 $output=shell_exe("/usr/bin/sudo/sbin/ifconfig eth0 down");但是执行下来没有效果 引用如下方法
http://www.hkcode.com/linux-bsd-notes/341请大神们 指点我一下吧 跪求啊
1. 找到apache的执行用户名
在 httpd.conf 里找类似这样的:
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User daemon
Group daemon
我这儿的用户是 daemon2. 添加用户到 /etc/sudoers 免密码
shell> sudo gedit /etc/sudoers
编辑文件,给最后加上一行
daemon ALL=(ALL) NOPASSWD: /sbin/ifconfig3. 代码:
<?php
shell_exec("sudo ifconfig eth0 down");
// shell_exec() 不论执行是否成功,shell_exec()的返回值都是空的。
我自己已经测试过的,所以你只要确保每一步都别大意
但是我的apache2.conf不是空的
代码#these need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}我安装的有问题么
打开 /etc/apache2/envvars 文件,找到这么两行
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
那个 www-data就是用户名。然后接着2,3步