php - 未为 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/
解决方案
好的,一切都解决了,一件事是给文件系统,实际上是安装的单元,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'
推荐阅读
- spring-boot - 如何使用spring boot在thymleaf中设置聚合对象的输入字段
- angular - 如何从 URL 获取域名 - Angular 7
- scala - Spark 将 TimestampType 转换为格式为 yyyyMMddHHmm 的字符串
- pygame - 树莓派上未显示徽标
- ios - 如何在某个时间线后更改 UITextView 的输入?例如,每 24 小时?迅速
- android - 从导航的深层链接调用我的应用程序会导致我的片段被多次实例化
- canvas - 使用 Fabric.js 中的自定义对象选择功能进行缩放和平移时鼠标偏移的奇怪问题
- django - django manytomanyfield 过滤器
- laravel - Laravel 刀片模板一次回显变量并且一次没有错误
- rrdtool - 使用rrdtool RRD PDP或RRA合并函数计算平均读数的区别?