Raspberry Pi

Raspberry Pi (RPi) Single Board Computer

Installing Apache Web Server on a RPI

This is how you install the Apache Server. Apache is a popular web server application you can install on the Raspberry Pi to allow it to serve web pages. On its own, Apache can serve HTML files over HTTP, and with additional modules can serve dynamic web pages using scripting languages such as PHP.

Install Apache

First install the apache2 package by typing the following command in to the Terminal:

sudo apt-get install apache2 -y

Test the web server

By default, Apache puts a test HTML file in the web folder. This default web page is served when you browse to http://localhost/ on the Pi itself, or (whatever the Pi’s IP address is) from another computer on the network. To find the Pi’s IP address, type hostname -I at the command line (or read more about finding your IP address).

Browse to the default web page either on the Pi or from another computer on the network and you should see the following:

Apache success message

This means you have Apache working!

Changing the default web page

This default web page is just a HTML file on the filesystem. It is located at /var/www/html/index.html.

Note: The directory was /var/www in Raspbian Wheezy but is now /var/www/html in Raspbian Jessie

Navigate to this directory in the Terminal and have a look at what’s inside:
cd /var/www/html
ls -al

This will show you:
total 12
drwxr-xr-x 2 root root 4096 Jan 8 01:29 .
drwxr-xr-x 12 root root 4096 Jan 8 01:28 ..
-rw-r–r– 1 root root 177 Jan 8 01:29 index.html

This shows that there is one file in /var/www/html/ called index.html. The . refers to the directory itself /var/www/html and the .. refers to the parent directory /www/.

What the columns mean
1.The permissions of the file or directory
2.The number of files in the directory (or 1 if it’s a file).
3.The user which owns the file or directory
4.The group which owns the file or directory
5.The file size
6.The last modification date & time

By default the html directory and index.html file are both owned by the root user. In order to edit the file, you must gain root permissions. Change the owner to your own user with sudo chown pi: index.html before editing.

Try editing this file and refreshing the browser to see the web page change.

Your own website

If you know HTML you can put your own HTML files and other assets in this directory and serve them as a website on your local network.

Additional – install PHP

To allow your Apache server to process PHP files, you’ll need to install PHP5 and the PHP5 module for Apache. Type the following command to install these:
sudo apt-get install php5 libapache2-mod-php5 -y

Now remove the index.html file:
sudo rm index.html

and create the file index.php:
sudo leafpad index.php

Note: Leafpad is a graphical editor. Alternatively, use nano if you’re restricted to the command line

Put some PHP content in it:
<?php echo “hello world”; ?>

Now save and refresh your browser. You should see “hello world”. This is not dynamic but still served by PHP. Try something dynamic:
<?php echo date(‘Y-m-d H:i:s’); ?>

or show your PHP info:
<?php phpinfo(); ?>
Install PHP-GD (graphics support:
sudo apt-get install php5-gd

Further – WordPress

Now you have Apache and PHP installed you can progress to setting up a WordPress site on your Pi. Continue to WordPress usage.

Installing WEEWX Server on a RPI

Download the DEB package from weewx.com/downloads. It will have a name similar to weewx_X.Y.Z-R_all.deb.


Install with the command:
sudo dpkg -i weewx_X.Y.Z-R_all.deb

The installer will prompt for a location, latitude/longitude, altitude, station type, and parameters specific to your station hardware.

If dpkg complains about dependency problems, use apt-get to resolve the dependencies and complete the installation:
sudo apt-get update
sudo apt-get -f install

When you are done, weewx will be running in the background as a daemon.

Check Status

To make sure things are running properly look in the system log for messages from weewx.
sudo tail -f /var/log/syslog


After about 5 minutes, open the station web page in a web browser. You should see your station information and data.

If your hardware supports hardware archiving, then how long you wait will depend on the archive interval set in your hardware.


To enable uploads such as Weather Underground or to customize reports, modify the configuration file /etc/weewx/weewx.conf. See the User Guide and Customization Guide for details.


weewx must be restarted for configuration file changes to take effect.


To start/stop weewx:
sudo /etc/init.d/weewx start
sudo /etc/init.d/weewx stop


To uninstall weewx but retain configuration files and data:
sudo dpkg -r weewx

To uninstall weewx, removing configuration files but retaining data:
sudo dpkg –purge weewx

To remove data:
sudo rm -r /var/lib/weewx
sudo rm -r /var/www/html/weewx


The installation will result in the following layout:

executable: /usr/bin/weewxd
configuration file: /etc/weewx/weewx.conf
skins and templates: /etc/weewx/skins
sqlite databases: /var/lib/weewx/
generated web pages and images: /var/www/html/weewx/
documentation: /usr/share/doc/weewx/
utilities: /usr/bin/wee_*

Setting up Dynamic DNS forwarding of Rpi IP address to FreeDNS

Set up your Direct URL from the Free Dynamic DNS account that you need to create.

Log in to your account at afraid.freedns.org and click Dynamic dns on the left pane. Scroll down and you will see a Direct URL hyperlink. The link looks something like this http://freedns.afraid.org/dynamic/update.php?HTPCGuidesSecretKey.

Right click and copy the URL of the Direct Link. You can paste this somewhere safe now or you can leave the window open and switch back to it. You will need this Direct URL shortly.

We will create a cronjob to run every 5 minutes and update your free dynamic DNS with your current IP address

Paste the code below but replace the URL http://freedns.afraid.org/dynamic/update.php?HTPCGuides with your direct link URL you copied to the clipboard.
crontab -l | { cat; echo “*/20 * * * * curl http://freedns.afraid.org/dynamic/update.php?HTPCGuides”; } | crontab –

You will get a message that looks like an error but it isn’t so don’t worry.
no crontab for pi/code

To verify that the command before added the cronjob you can list the cron jobs to make sure the freedns job is there
crontab -l

It should show

**/20 * * * * curl http://freedns.afraid.org/dynamic/update.php?HTPCGuides

Restart the cron service
sudo service cron restart

You can adjust the update interval by modifying the */20 to */60 for every 60 minutes or whatever interval you need.

FREEDNS has full instructions on this method too.

Installing an FTP Server

FTP (File Transfer Protocol) can be used to transfer files between a Raspberry Pi and another computer. Although with default program sftp-server of Raspbian the users with sufficient privilege can transfer files or directories, access to the filesystem of the limited users is also required often. Follow the steps below to set up an FTP server:

Install Pure-FTPd

First, install Pure-FTPd using the following command line in Terminal:
sudo apt-get install pure-ftpd

Basic Configurations

We need to create a new user group named ftpgroup and a new user named ftpuser for FTP users, and make sure this “user” has NO log in privilge and NO home directory:
groupadd ftpgroup
useradd ftpuser -g ftpgroup -s /sbin/nologin -d /dev/null

FTP Home Directory, Virtual User, and User Group

For instance, make a new directory named FTP for the first user:
sudo mkdir /home/pi/FTP

Make sure the directory is accessible for ftpuser:
sudo chown -R ftpuser:ftpgroup /home/pi/FTP

Create a virtual user named upload, mapping the virtual user to ftpuser and ftpgroup, setting home directory /home/pi/FTP, and record password of the user in database:
sudo pure-pw useradd upload -u ftpuser -g ftpgroup -d /home/pi/FTP -m

A password of that virtual user will be required after this command line is entered. And next, set up a virtual user database by typing:
sudo pure-pw mkdb

Last but not least, define an authentication method by making a link of file /etc/pure-ftpd/conf/PureDB, the number 60 is only for demonstration, make it as small as necessary:
ln -s /etc/pure-ftpd/conf/PureDB /etc/pure-ftpd/auth/60puredb

Restart the program:
sudo service pure-ftpd restart

Test it with an FTP client, like FileZilla.

More Detailed Configurations:

The configuration of Pure-FTPd is simple and intuitive. The administrator only needs to define the necessary settings by making files with option names, like ChrootEveryone, and typing yes, then storing in the directory /etc/pure-ftpd/conf, if all FTP users are to be locked in their FTP home directory (/home/pi/FTP). Here are some recommended settings:
sudo nano /etc/pure-ftpd/conf/ChrootEveryone

Type yes, and press Ctrl + X, Y, and Enter.


Make a file named NoAnonymous and type yes;

Make a file named AnonymousCantUpload and type yes;

Make a file named AnonymousCanCreateDirs and type no;

Make a file named DisplayDotFiles and typeno;

Make a file named DontResolve and type yes;

Make a file named ProhibitDotFilesRead and type yes;

Make a file named ProhibitDotFilesWrite and type yes;

Make a file named FSCharset and typeUTF-8;

Restart pure-ftpd again and apply the above settings.
sudo service pure-ftpd restart

For more information of Pure-FTPd and documentation, go to the official website of Pure-FTPd.

Adding Image Uploads to Weather Underground

  1. Create a script to upload the images, create a new file called ‘wunder.sh’ and enter the following in the file:
    1. #!/bin/bashfilename=””http://g6ejd.dynu.com:8082/html/cam.jpg”
      lftp ftp://$username:$password@$hostname -e “put $filename ; quit”
  2. Save and exit
  3. Make the script file executable:
    1. sudo chmod +x wunder.sh
    2. Copy the file to /home/pi with cp wunder.sh   /home/pi/
  4. Create a PYTHON script file:
    1. sudo nano wunder.py
    2. Add to the file the following:
      1. #!/usr/bin/env pythonimport shutil
        import os
        os.system(“bash -c /home/pi/wunder.sh”)
  5. Make the PYTHON script executable:
    1. sudo chmod -x wunder.py
  6. Add to the CRONTAB  an updating call to the script:
    1. sudo crontab -u pi -e    (-u for User that is pi and -e for Edit)
    2. Add the following for 15-min updates intervals:
      */15 * * * * python /home/pi/wunder.py >> /home/pi/script.log &
  7. FInished

Weewx General Topics

Corrupt station memory

If you have a Vantage station, the problem might be because the data on board your console has gotten garbled. The way the Davis Vantage series works is that the software (weewx in this case) asks the console for all archive data “since” some time. The console then downloads the records one at a time. After it gets to the very last one, the memory wraps around, and the timestamp will suddenly jump backwards in time a couple weeks — this how the software knows it has downloaded the last record and so it stops. However, if the internal memory gets garbled, the console will immediately return archives in the past, and so it looks like the timestamps have decreased in value and so weewx figures that is it: there is no more data. I have received reports from a couple of users who have had this problem. There seems to be two fixes: Unplug the console, take out the batteries, and wait a minute or two. This will cause the console software to internally reboot. In one case this has fixed the problem without data loss. If all else fails, clear the memory of the console using the utility wee_device. This may cause loss of data, but usually works.

adjust paths as necessary: wee_device –clear-memory

Weewx and running a report on-demand

sudo wee_reports /etc/weewx/weewx.conf