首页 > 解决方案 > 未为 Web 用户执行二进制文件

问题描述

我有一个 php 脚本,它创建了一个最终以 www-data 用户身份执行的 shell 脚本文件,所有命令都被执行,除了最后一个暗示二进制文件的命令。如果我以root身份运行命令,它运行正常...

这是脚本的最后一部分:

&& echo "Tokenizing the file........" >> Logs/table_of_contents.php \
&& perl ../common/Scripts/xmltokenize.pl --filename=xmlfiles/table_of_contents.xml >> Logs/table_of_contents.php \
&& perl ../common/Scripts/xmlrenumber.pl --filename=xmlfiles/table_of_contents.xml >> Logs/table_of_contents.php \
&& echo "Tagging the file........" >> Logs/table_of_contents.php \

# I have added this line to check if it helps but id doesn't
&& export HOME="/tmp/" \

# And this is the command that calls the binary file
&& perl tagfile.pl xmlfiles/table_of_contents.xml \

这里有tagfile.pl的内容

use File::Find;
$\ = "\n";

$fn = shift;

if ( $fn =~ /([^\/\.]+)\.xml/ ) { $fileid = $1; } else { exit;};
print $fileid;

$cmd = "perl tagfl2/makevrt.pl 'xmlfiles/$fileid.xml' > 'tagtmp/$fileid.vrt'";
print $cmd;
print `$cmd`;

#ALL OF THE PREVIOUS WORKS
#THIS IS THE ONE THAT GIVES PERMISSION ERRORS 
# OF COURSE: "www-data:www-data tagtmp/" and "www-data:www-data $fileid.vrt = table_of_contents.vrt"
$cmd = "cut -f 1 tagtmp/'$fileid.vrt' | tagfl2/treetagger/bin/tree-tagger -no-unknown -token -lemma tagfl2/treetagger/lib/english.par  > 'tagtmp/$fileid.tagged'";
print $cmd;
`$cmd`;
$cmd = "perl tagfl2/mrg.pl 'tagtmp/$fileid.vrt' 'tagtmp/$fileid.tagged' > 'tagtmp/$fileid.mrg'";
print $cmd;
`$cmd`;
$cmd = "perl tagfl2/tagxml.pl 'tagtmp/$fileid.mrg' 'xmlfiles/$fileid.xml'";
print $cmd;
`$cmd`;

这是错误:

sh: 1: tagfl2/treetagger/bin/tree-tagger: Permission denied

另外,以防万一:

chown -R www-data:www-data tagfl2/
chmod -R g+rwx tagfl2/

标签: phpbashapacheshellperl

解决方案


好的,一切都解决了,一件事是给文件系统,实际上是安装的单元,exec 属性。

第二件事是将treetagger目录移动到/usr/local/

然后,/usr/local/bin/我以这种方式创建了一个软链接:

ln -s ../treetagger/bin/tree-tagger

使二进制文件全局可执行。实际上,这最后一步是最终的解决方案。

然后在tagfile.pl perl 脚本中,包含tree-tagger命令的行,我已经改变了它:

cut -f 1 'tagtmp/$fileid.vrt' | /usr/local/bin/tree-tagger -no-unknown -token -lemma tagfl2/treetagger/lib/english.par  > 'tagtmp/$fileid.tagged'

推荐阅读