在PHP中运行Python脚本:

I make Relay-Website-with-Raspberry now python application is work but on php is no work this php screp,

<?php

    $output = shell_exec('sudo python 1on.py 2>&1');

    echo "<pre>$output</pre>";

    header("Location: ../index.php");

    exit;

?>

This is not a right procedure to run a python script, Instead running python script in sudo mode give your file permission to www-data

chgrp www-data /path/to/python-script.py

put first line in your python script: #!/usr/bin/env python so the script knows which program to open it with..

Make your script executable

chmod +x /path/to/python-script.py

then try running the script

<?php

    $output = shell_exec("/path/to/python-script.py");

    echo "<pre>$output</pre>";

    header("Location: ../index.php");

    exit;

?>