Lassie Posted October 13, 2017 Share Posted October 13, 2017 I need to execute a python program called from inside a php web page. the web page runs without errors and the python script will run from a terminal but the two together dont dance. Any help would be welcome. php <?php /* * Template Name:message * * */ ?> <?php get_header(); ?> <div id="container"> <div id="content" role="main"> <?php /* Run the loop to output the page. * If you want to overload this in a child theme then include a file * called loop-page.php and that will be used instead. */ get_template_part( 'loop', 'page' ); //get message //print_r($_GET); //echo "<br />"; //$message= $_GET['message']; Will be appened to $command $command= "/home/pi/sense-test.py"; exec($command); echo $message; echo "<br />"; echo "Message Recieved"; echo "The time is" . date9"h:i:sa"); ?> </div> </div> <?php get_footer(); ?> Python #!/usr/bin/env python3 from sense_hat import SenseHat sense = SenseHat() sense.show_message("Hello World") Quote Link to comment https://forums.phpfreaks.com/topic/305352-run-python-script-from-php-page/ Share on other sites More sharing options...
Lassie Posted October 13, 2017 Author Share Posted October 13, 2017 Please note this should be titled run PYTHON script from php webpage Apologies Quote Link to comment https://forums.phpfreaks.com/topic/305352-run-python-script-from-php-page/#findComment-1552688 Share on other sites More sharing options...
ginerjm Posted October 13, 2017 Share Posted October 13, 2017 Let's clarify things a bit. There are no PHP webpages. Web pages are basically HTML. So is your question really "how to run a python script from a PHP script"? And did you try googling THAT question? I did and found several responses. Quote Link to comment https://forums.phpfreaks.com/topic/305352-run-python-script-from-php-page/#findComment-1552691 Share on other sites More sharing options...
Lassie Posted October 14, 2017 Author Share Posted October 14, 2017 Yes you are right it is how to run the python script from a php script that happens to be a wordpress web pgae running on an apache server. Yes I have tried googling and my latest effort is $command = escapeshellcmd('/home/pi/sense-test.py'); $output = shell_exec($command); echo $output; I get no output. I have checked permissions to make it executable. My thinking now is to move the file to the Apache folder and work from there. Quote Link to comment https://forums.phpfreaks.com/topic/305352-run-python-script-from-php-page/#findComment-1552696 Share on other sites More sharing options...
ginerjm Posted October 14, 2017 Share Posted October 14, 2017 I have no idea how to do this but this google hit shows some other stuff to do: https://stackoverflow.com/questions/32598420/cant-execute-python-script-from-php-document Quote Link to comment https://forums.phpfreaks.com/topic/305352-run-python-script-from-php-page/#findComment-1552707 Share on other sites More sharing options...
Sepodati Posted October 15, 2017 Share Posted October 15, 2017 (edited) It may be executable, but is it executable by the user PHP (really Apache) runs as? Typically www-data. And does that user have access to that directory? Edited October 15, 2017 by Sepodati Quote Link to comment https://forums.phpfreaks.com/topic/305352-run-python-script-from-php-page/#findComment-1552708 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.