0

I have a short websites written in PHP that should execute a Python file when I submit a dedicated form. However, when I used the PHP page, the script is never executed (i.e. the output is empty and the script python did not what it is supose to do.

All the files are located in /var/www/html, the owner of the Webserver is www-data, I have change the rights of check_directory with :

sudo chown www-data:www-data check_directory.py
sudo chmod +x check_directory.py

Inside about.php, I have :

$output = exec('./check_directory.py');
echo $output

ls -la gives :

-rwxrwxrwx  1 www-data www-data    1334 nov.  10 11:46 check_directory.py
-rw-r--r--  1 root     root       13625 nov.  10 12:12 about.php

I already know it is necessary to give PHP the rights to execute the script according to www-data, and I thought to do it correctly. But, I changed from exec to shell_exec, I directly used python check_directory instead of create an executable ...

I cannot say if there is a problem of rights now, or functions inside Python file since in console, the code works properly.

I really appreciate to get some help :) Thanky you all

-A

  • I don't know much about php, but have you tried `python ABS_PY_PATH/check_directory.py`? Shell does not know how to execute py file unless you add `python`. – ZhaoYi Nov 10 '20 at 11:30
  • See if this helps: https://stackoverflow.com/questions/2429511/why-do-people-write-usr-bin-env-python-on-the-first-line-of-a-python-script – Justin Ezequiel Nov 10 '20 at 11:41
  • Thanks ZhaoYi for your answear ! Unfortunately it changed nothing by adding ```ABS_PY_PATH``` ! – ARTISTIC Nov 10 '20 at 12:22
  • It checked what you suggested Justin. After taking into account the log in ```/var/log/apache2```, i saw that the python line is executed but no library exist. that is why the code after is never executed. I added ```/usr/bin/env python``` or ```/usr/bin/env python3``` but still no library added. Does it suggest we need to install libraries for www-data user ?? – ARTISTIC Nov 10 '20 at 12:26

0 Answers0