我正在尝试运行一个用于从php
进行图像处理的python脚本php脚本
<?php
echo exec('echo $PATH ');
putenv("PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/user/.local/bin:/home/user/bin");
echo "<br>";
echo exec('echo $PATH');
echo "<br>";
echo exec('whoami');
echo "<br>";
echo exec('/usr/bin/python /var/www/html/wordspot/uploads/editimage1.py /var/www/html/wordspot/uploads/test.jpg 2>&1'); ?>
python脚本
import sys,getopt
import numpy as np
import cv2
imname=str(sys.argv[1])
print imname
img=cv2.imread(imname,0)
ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
cv2.imwrite(imname,thresh1)
在执行“php test.php”时在终端上运行(我以root身份运行)
浏览器上的我得到了这个输出
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/user/.local/bin:/home/user/bin
apache
ImportError: libopencv_core.so.3.0: cannot open shared object file: No such file or directory
我认为导入cv2.so导致此错误(例如在hello world python示例中运行) 我该怎么做才能从apache用户看到opencv库?
编辑
解决方案:在/etc/ld.so.conf.d/opencv.conf
和executing ldconfig -v
中添加库的路径
将错误更改为"ImportError: libopencv_core.so.3.0: cannot enable executable stack as shared object requires: Permission denied"
使用setenforce 0
禁用SELinux后,它工作正常。 (这不会在重新启动后继续存在,需要在/etc/selinux/config
中禁用SELinux并更改为SELINUX=disabled
,或者在SELinux中提供正确的权限以允许访问库。)
答案 0 :(得分:1)
libopencv_core.so.3.0
位于何处?如果它在/usr/local/lib
中,请在执行程序之前尝试设置LD_LIBRARY_PATH
:
putenv("LD_LIBRARY_PATH=/usr/local/lib");