I am creating an API in PHP which pass some parameters to python and generate a report in pdf format.
in report_gen.py file I have code to get parameters and generate pdf. Which is working successfully through command line but when I run PHP file from browser or postman it do not works.
I want to run my PHP file through cronjob so it automatically call in specific time.
$data = 'Basic Will Johnyy Willson Smith';
$command = escapeshellcmd("python3 report_gen.py $data");
$output = shell_exec($command);
echo $output;
There can be (at least) two problems.
First you need to check/know, that the server maid use another environment. I believe, that you did not use the webserver-user for your local checks. So I would try to use absolute pathes. You also have to make sure, that the python-environment (whatever you have configured) has to be the same as your local user.
Second you need to make sure, that you have all rights to run the file (the webserver, that is used by the webserver needs to have at least reading right on report_gen.py).
By running python script with php - working in console but not in web browser