用PHP调用python脚本[重复]

This question already has an answer here:

I have the following PHP code that I want to use to call a python script (ring.py)

  <?php echo '<p>Hello World</p>'; 
    $output = exec('python ring.py');
  ?> 

The program ring.py creates 2 files. When I run the PHP script from command line:

php index.php

then the php script correctly runs the python script and 2 files are created as desired.

However when someone accesses the PHP page through a web browser, it doesn't seem to run the python script and no files are created. How can I fix this?

Thanks so much!

</div>

Make sure the Python script on the server is executable

chmod +x ring.py

and make sure it's either in the same directory as the PHP script or use the full path.

You should do chmod 0777 ring.py, because just doing +x will affect just your user. Normally, PHP is executed by another user (usually, anonym), that probably is not in the same group as yours.