Вроде бы очевидный момент, но вы можете запустить скрипт python из терминала? Это на самом деле работает?
Убедитесь, что скрипт исполняется любым пользователем PHP, который запускается как - chmod 777 myfile.py
, и просто на всякий случай chmod 777 /usr/local/python25/bin/python
. Также убедитесь, что скрипт python находится в том же каталоге, что и скрипт PHP, что и требуется для его метода вызова.
Попробуйте изменить свой PHP-скрипт на это и скажите мне, что вы видите: ( EDITED )
<?php
// Path to the python script - either FULL path or relative to PHP script
$pythonScript = 'myfile.py';
// Path to python executable - either FULL path or relative to PHP script
$pythonExec = '/usr/local/python25/bin/python';
// Check the file exists and PHP has permission to execute it
clearstatcache();
if (!file_exists($pythonExec)) {
exit("The python executable '$pythonExec' does not exist!");
}
if (!is_executable($pythonExec)) {
exit(("The python executable '$pythonExec' is not executable!"));
}
if (!file_exists($pythonScript)) {
exit("The python script file '$pythonScript' does not exist!");
}
// Execute it, and redirect STDERR to STDOUT so we can see error messages as well
exec("$pythonExec \"$pythonScript\" 2>&1", $output);
// Show the output of the script
print_r($output);
?>