pandoc (/root/.cabal/bin/pandoc)问题:最初通过命令行作为根用户访问了一个名为的包,该包安装在根文件夹中。当我尝试使用shell_exec(),通过php访问这个包时,它失败了。
shell_exec()问题:为了安全目的,是否对php 不访问根包有任何限制?如果是的话,如何解决?
我尝试过:给根文件夹写权限,然后我可以通过命令行访问根包,而不是以根用户的身份访问。但是我无法通过php shell_exec().访问它。
php代码:
shell_exec("cd /home/quotequadsco/public_html/pandoc_jats ; sudo -u quotequadsco
-S /root/.cabal/bin/pandoc ex.tex --filter /root/.cabal/bin/pandoc-citeproc
-t JATS.lua -o ex.xml");也尝试过,
shell_exec("cd /home/quotequadsco/public_html/pandoc_jats ;/root/.cabal/bin/pandoc
ex.tex --filter /root/.cabal/bin/pandoc-citeproc -t JATS.lua -o ex.xml");Expectation:我需要在php中通过shell_exec()执行pandoc包。
发布于 2015-01-03 13:15:35
在/etc/sudoer文件中添加了以下行
#Defaults requiretty //commented this line
usergroup ALL=(ALL) ALLPHP代码,
shell_exec("cd /home/quotequadsco/public_html/pandoc_jats ;echo password | sudo
-S command"); //added a password for sudo command to run as a root user.发布于 2016-05-20 10:21:59
我最近发布了一个项目,允许PHP获得真正的Bash并与之交互(如果请求作为根),它解决了exec()和shell_exec()的限制。到这里来:https://github.com/merlinthemagic/MTS
下载后,只需使用以下代码:
$shell = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);
$return1 = $shell->exeCmd('pandoc (/root/.cabal/bin/pandoc)');
//the return will be a string containing the return of the command
echo $return1;https://stackoverflow.com/questions/27753363
复制相似问题