Getting ready

Ensure you have completed the previous recipe so that the sensor data has been collected and stored in the SQLite database. We need to install a web server (Apache2) and enable PHP support to allow SQLite access.

Use these commands to install a web server and PHP:

sudo apt-get update
sudo aptitude install apache2 php5 php5-sqlite  

The /var/www/ directory is used by the web server; by default, it will load index.html (or index.php) – otherwise, it will just display a list of the links to the files within the directory.

To test whether the web server is running, create a default index.html page. To do this, you will need to create the file using sudo permissions (the /var/www/ directory is protected from changes made by normal users). Use the following command:

sudo nano /var/www/index.html  

Create index.html with the following content:

<h1>It works!</h1> 

Close and save the file (using Ctrl + X, Y and Enter).

If you are using the Raspberry Pi with a screen, you can check whether it is working by loading the desktop:

startx  

Then, open the web browser (epiphany-browser) and enter http://localhost as the address. You should see the following test page, indicating that the web server is active:

Raspberry Pi browser displaying the test page, located at http://localhost

If you are using the Raspberry Pi remotely or it is connected to your network, you should also be able to view the page on another computer on your network. First, identify the IP address of the Raspberry Pi (using sudo hostname -I) and then use this as the address in your web browser. You may even find you can use the actual hostname of the Raspberry Pi (by default, this is http://raspberrypi/).

If you are unable to see the web page from another computer, ensure that you do not have a firewall enabled (on the computer itself, or on your router) that could be blocking it.

Next, we can test that PHP is operating correctly. We can create a web page called test.php, and ensure that it is located in the /var/www/ directory:

<?php 
  phpinfo(); 
?>; 

The PHP web page to view the data in the SQLite database has the following details:

Viewing the test.php page at http://localhost/test.php

We are now ready to write our own PHP web page to view the data in the SQLite database.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.123.106