artudp
By:
artudp

How to execute script pyhon with php?

October 13, 2017 198 views
PHP Python

I have a project PHP in my droplet LEMP 16.04 with script python, when I run in terminal is ok, but when I run in the browser don't execute the script.

My PHP

$vehicleJSON = shell_exec('python vehiclepy.py ' . $plate);

I've already tried:

  1. change to $vehicleJSON = shell_exec('python vehiclepy.py ' . $plate . ' 2>&1');
  2. change to $vehicleJSON = shell_exec('usr/bin/python /var/www/myapp/vehiclepy.py ' . $plate);
  3. add in sudoers www-data NOPASSWD: /var/www/myapp but don't execute.

Please help me kkkkk, thanks!

2 Answers

First off, be careful running shell_exec like this, If the user can change ** $plate** they would be free to run any command they like.

You may find if you can't execute it when running via HTTP it may be a blocked function.

https://stackoverflow.com/questions/24999673/how-to-enable-shell-exec-and-exec-on-php

Do you have anything in your error logs?

I did it! I change the function to system().

Have another answer? Share your knowledge.