title: Can't execute python script that imports cv2.so from php
body: <p>i am trying to run a python script for image proccessing from php</p>
  
  <p>php script</p>
  
  <pre><code>&lt;?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 "&lt;br&gt;";
  echo exec('echo $PATH');
  echo "&lt;br&gt;";
  echo exec('whoami');
  echo "&lt;br&gt;";
  echo exec('/usr/bin/python /var/www/html/wordspot/uploads/editimage1.py /var/www/html/wordspot/uploads/test.jpg 2&gt;&amp;1'); ?&gt;
  </code></pre>
  
  <p>python script</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>while on terminal when executing "php test.php" it works (i run it as root)</p>
  
  <p>on browser i get this output</p>
  
  <pre><code>/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
  </code></pre>
  
  <p>i think that the import cv2.so is causing this error (it runs for example on hello world python example)
  What can i do to make the opencv libraries visible from apache user? </p>
  
  <p>Edit
  Solution: adding the path of the library in <code>/etc/ld.so.conf.d/opencv.conf</code> and <code>executing ldconfig -v</code>
   changed the error to <code>"ImportError: libopencv_core.so.3.0: cannot enable executable stack as shared object requires: Permission denied"</code></p>
  
  <p>After disabling SELinux with <code>setenforce 0</code> it worked. (This is will not survive a reboot, SELinux needs to be disabled from in <code>/etc/selinux/config</code> and change to <code>SELINUX=disabled</code>, or providing the correct permissions in SELinux to allow access to the library.)</p>