In this series, we are going to turn our BeagleBone into a web server.  Then we are going to use that web server to monitor the temperature in a room.  To do this, we are going to leverage a couple of common open source programs.  We are going to use lighttpd as our web server.  Then we are going to integrate in PHP to handle the required server side logic.  We will also use a MySQL database to store the temperature measurements so that we can display historical information.  To gather the temperature measurements, we will use C to read a BeagleBone GPIO port.  Finally, we will use Javascript to give the user a nice interface to work with.


The technologies that we are going to us in this tutorial are very powerful and this is just meant as a starting point to demonstrate how the technologies can be used together on a BeagleBone.  Trust me, this is just the tip of the iceberg.


Install Lighttpd

Now before we install any new software, it is a good idea to update opkg:


opkg update


To install Lighttpd, type:


opkg install lighttpd lighttpd-module-fastcgi


Note, this will display a message about the job failing.  This is because port 80 is already in use.


Disable Preloaded Services

The BeagleBone comes with a bunch of preloaded services.  This this makes it really easy to get started, but the preloaded services use port 80, and that is exactly the one that we want to use.  So, we need to disable them, so that we can run on that port. Also, we disable a few extras in order to free up some memory on the BeagleBone.  Here’s how to disable the services (and a link to what the services that you are disabling do, in case you are interested):


For BeagleBone:

systemctl disable cloud9.service

systemctl disable gateone.service

systemctl disable bone101.service

systemctl disable avahi-daemon.service

systemctl disable gdm.service


For BeagleBone Black:

systemctl disable cloud9.service

systemctl disable gateone.service

systemctl disable bonescript.service

systemctl disable bonescript.socket

systemctl disable bonescript-autorun.service

systemctl disable avahi-daemon.service

systemctl disable gdm.service

systemctl disable mpd.service


BeagleBone - disable.png

Excellent, now that the services are disabled, we need to reboot and the services will be no longer started:


shutdown -r now



It may seem more logical to disable the services first, and then install Lighttpd.  However, this didn’t seem to work for me.  It would hang on the “configuring lighttpd…” step. Doing the installation first seemed to work much better.


Now, let’s test to make sure that Lighttpd installed correctly.  To do this we need to figure out the IP Address of the BeagleBone:


ifconfig -a

BeagleBone - IP Address.png

Now on another computer on your network (anything but the BeagleBone), point a web browser to that IP Address, and you should see a very reassuring message:

BeagleBone - lighttpd test.png


Install PHP

Next, we need to install PHP.  To do that type:


opkg install php php-cgi php-cli


Now we need to configure Lighttpd to use PHP.  To do this, we need to edit the lighttpd.conf config file.  However, before we do this, we need to gather a little bit of information. We need to find out where php-cgi was installed:


which php-cgi


Then we need to edit the Lighttpd config file:


vi /etc/lighttpd.conf


And we need to do two things.  First, we need to uncomment “mod_fastcgi”, which was at line 24 for me:

BeagleBone - server modules.png

Then we need to uncomment the fastcgi configuration.  Here we will also need to configure the “bin-path” to point to the location of php-cgi that we found earlier.

BeagleBone - fastcgi.png

To complete the configuration, we need to restart Lighttpd, so that the configuration file will be read in:


/etc/init.d/lighttpd restart

BeagleBone - lighttpd restart.png

Finally, to test that the web server is working correctly, we are going to create a simple web page:


vi /www/pages/test.php


And type in the following code:







<?php print(“PHP is working on the BeagleBone!”); ?>




To view the web page, go back to the web browser that you used earlier and type in:


<IP Address>/test.php

BeagleBone - php test.png




Next Article

In the next article, we are going to use the web server to display a web page that lets you turn the LEDs on the BeagleBone on and off.  Once we have accomplished that, then we will move on to incorporating a MySQL database and a temperature sensor.