Jul 22 2013 0

Running it all on the Raspberry Pi (Part 1)

My project’ for logging environmental data now relies on an additional server for logging and displaying the data. To make the project completely self-contained the web server component is going to be moved onto the Raspberry Pi as well.

Based on the current setup, roughly the following tasks will need to be performed to get rid of the additional server;

  • install Lighttpd
  • install SQLite
  • install PHP
  • configure Lighttpd (enable PHP)
  • configure PHP (enable SQLite module)
  • update ds18b20.py (log directly into local SQLite database, remove web call)
  • update sensor-data.php (remove obsolete code)
  • update chart-sensor.js (update URL for calling sensor-data.php)

Install Required Software onto the Raspberry Pi

Install Lighttpd and PHP5

sudo apt-get install lighttpd
sudo apt-get install php5 php5-cgi php5-common php5-dev

Install SQLite3 and enable SQLite for PHP5

sudo apt-get install sqlite3 php5-sqlite

Configure Lighttpd

Enable the fastcgi module and the php configuration using

sudo lighty-enable-mod fastcgi
sudo lighty-enable-mod fastcgi-php

Restart the Lighttpd service to active the changes

sudo service lighttpd force-reload

Testing the setup

The DocumentRoot for Lighttpd is located at /var/www/, by default the user root is the owner. The following command will ensure that the user pi is the owner of the folder and its content

sudo chown -R pi /var/www/

In order to test changes to the setup, place a file named index.php’ into the /var/www/ folder. It should contain the following line of code

<?php phpinfo(); ?>

The phpinfo()-command will return information about PHP’s configuration. If everything has been setup correctly you should see a page with detailed information about the PHP configuration running on the Raspberry Pi

Make sure that SQLite is present in the list of loaded modules.

PDO

Output from phpinfo()Output from phpinfo()

SQLite3

Output from phpinfo()Output from phpinfo()

If all is fine remove the index.php again, no need to expose your configuration to others…

Exposing the Raspberry Pi to the outside (optional)

The Lighttpd server is accessible within your current network. If you want to make it available to the outside world you will have to make update your router, so it will route web requests to Lighttpd (port 80) running on the Raspberry Pi.

Check the documentation of your router on how to make this happen.

What is left to be done

In the next instalment I will describe the changes that need to be made to my own scripts involved in the project

  • update ds18b20.py (log directly into local SQLite database, remove web call)
  • update sensor-data.php (remove obsolete code)
  • update chart-sensor.js (update URL for calling sensor-data.php)

Continue reading in Running it all on the Raspberry Pi (Part 2) and Running it all on the Raspberry Pi (Part 3)


Previous post
Adding a DHT sensor to the Raspberry Pi Today I received a new sensor in the mail that I had ordered from Kiwi Electronics. Time to hook it up…. The sensor that I bought is a AM2302 (which
Next post
Running it all on the Raspberry Pi (Part 2) In my last post, (Running it all on the Raspberry Pi (Part 1), I went through the additional software and services that were required to move all
This blog is powered by Blot