Beehive Instrumentation Project-3: Apache Server, Python in PHP


While running the Raspberry Pi 2-B off the drill battery, I installed the Apache-2 server and MySQL.

See http://elinux.org/RPi_Apache2 for details.

I want to run the temperature and humidity logging, IR and USB cameras, and other possible instruments like weight measurement from a local web server on the remote RPi.  The first step is to run a PHP script on the server, which in turn selects the “driver” code for the attached devices.  The learning PHP script runs a simple Python script.

See http://stackoverflow.com/questions/19735250/running-a-python-script-from-php for the basic ideas.

I wrote the PHP script “index.php”, which is placed in the RPi directory /var/www, where the Apache server runs it as the default start up code instead of index.html.

<?php
echo “hello world.”;
echo “<br>”;
$command = escapeshellcmd(‘python test2.py’);
$output = shell_exec($command);
echo $output;
echo “<br> I’m here in php”;
?>

The Python script “test2.py”:

#!/usr/bin/env python
print “I’m here in Python”

When the IP address of the RPi is entered into the Firefox browser, this is the result:

RPi2B server Firefox browser image

RPi2B server Firefox browser image

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s