Home > Backend Development > PHP Tutorial > 为什么用exec执行一个命令时,在脚本内执行不成功,放到服务器命令行就可以了,我在/etc/sudoers也做了配置

为什么用exec执行一个命令时,在脚本内执行不成功,放到服务器命令行就可以了,我在/etc/sudoers也做了配置

WBOY
Release: 2016-06-23 14:22:47
Original
1178 people have browsed it

shell

   我首先在/etc/sudoers做了如下配置

   接着重启了下apache服务器
   在tp框架内写到
exec('/usr/bin/unoconv --server localhost --port 8100 -o /usr/local/webserver/www/server/Exam/Public/Uploads/Resource/transform/document/201309/52419a788a553.pdf -f pdf /usr/local/webserver/www/server/Exam/Public/Uploads/Resource/untransform/document/201309/52419a788a553.doc');
Copy after login

运行了下,没有效果,转码不成功,把代码直接拿出来就可以执行。

同时,我又把转码的部分写到一个shell脚本里
#!/bin/shturnCode() {local pdf=`echo $1 | cut -d: -f1`;local file=`echo $1 | cut -d: -f2`;echo $pdf;echo $file;  `/usr/bin/unoconv --server localhost --port 8100 -o $pdf -f pdf $file`}action="$1"setting="$2"case $action in    turnCode)        turnCode "$setting"    ;;    *)    ;;esac
Copy after login

通过exec调用
 exec("sudo ./bash turnCode $save_path1:$file_path1", $out, $status);
Copy after login

结果仍旧是无法转码,哪位过来人烦请指点下,不甚感激!!!

回复讨论(解决方案)

命令行时,使用的是你的账号的权限。而脚本则可以不同,完全由该脚本的拥有者或创建者的账号权限控制。

哦,已经弄好了
    1、配置visudo给apache用户设置权限,具体操作
     注释掉 Defaults    requiretty
     添加   www     ALL=(ALL)       NOPASSWD:ALL
  2、重启apache服务 /usr/local/webserver/apache2/bin/apachectl restart

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template