Xinu

php在ubuntu环境下使用脚本命令
之前写的项目部署在Centos环境中,需求变更,将项目迁移至Ubuntu环境,迁移后发现,部分功能无法使用,排查发...
扫描右侧二维码阅读全文
26
2017/10

php在ubuntu环境下使用脚本命令

之前写的项目部署在Centos环境中,需求变更,将项目迁移至Ubuntu环境,迁移后发现,部分功能无法使用,排查发现是<font style='color:blue;'>exce()</font>执行失败。Ubuntu的权限和Centos的用户权限区分不同。

查看当前服务器运行用户

<?php
$res = [];
$status = '';
exec('whoami',$res,$status);
print_r($res);

给服务器的运行用户授权

假设查询出的用户为www
执行命令
nano /etc/sudoers
或者
vim /etc/sudoers
在文件中添加如下代码
www ALL=(ALL) NOPASSWD:ALL
说明:格式为{用户名 网络中的主机=(执行命令的目标用户) 无需密码}

应用,执行命令

<?php
$command = "sudo rm /var/www/* -rf";
$res = array();
$status = '';
exec($command,$res,$status);
print_r($res);

原文出处:http://www.cnblogs.com/kuoaidebb/p/4286730.html

Last modification:October 26th, 2017 at 09:08 pm

Leave a Comment