1

I have a php/action.php. That script creats a file in the folder ../data/myfile.kml. After creating this file I want to modify it. So I call a python script by

exec("python mypythonscript.py someparams");

Php errors are shown, when I call the website. Is there a way to show the python erros on the webseite, too?

It seams that the python script works, when I execute it by terminal but php doesn't seam to get the script running. So I need some hints to track down, where the problem lays. I must say, I am new to web programming, so please have a little patience with me. If there is more you need to know to be able to help me, I'll be glad to answer your questions.

Kind regards Aufwind

2 Answers 2

6

You can see the output of exec if you pass it an additional array (and later see its contents):

exec("python mypythonscript.py someparams",$my_output);
var_dump($my_output);

You should be able to debug from there.

Sign up to request clarification or add additional context in comments.

Comments

2

The most likely explanation is that php executes the script as a different user and, therefore, with different permissions than you do calling it from the command line. You'll need to give the user running php (usually www-data) permission to do whatever your python script is doing.

5 Comments

Is this your own server or are you running on shared hosting?
What is the python script trying to do? And did you get the output of it when run by php? What's the error message?
The python script modifys some files, which are created by action.php before. I figured out how to run the python script by php. If I did not try to modify the files, it worked. So I thinl your guess, that there are permission issues was right. Because I couldn't solve that issue I tryed another approach. Thank you for your effort though. It is nice to know at least where the error was.
I do have same issue user is apache and python need to run using root user. But not able to find anything to make it work. Can anyone suggest something?
The same question getting this error No module named mysql.connector

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.