
Set up a web server on the Raspberry Pi

You can download the files here:
​
http://www.signalfront.com/promptbox/lcd.zip
​
http://www.signalfront.com/promptbox/lcddriver.zip
http://www.signalfront.com/promptbox/i2c_lib.zip
​
http://www.signalfront.com/promptbox/ddclient-3.8.3.tar
​
This project creates a website that allows web users to send text over the internet to be displayed on a LCD connected to the Raspberry Pi.
-
Allow access to your RPi from the internet:
-
Connect the RPi to its router
-
On the router, record your current IP address and DNS server address
-
Reserve the RPi’s DHCP IP address, so it doesn’t change (usually 192.168...)
-
Use port forwarding to point to that IP address
-
Port 80 for standard web access
-
I used port 181 because my router already has its own web server at port 80
-
Also forward port 443 for ssl access
-
-
Setup a Dynamic IP domain because the IP number your ISP gives you may change:
-
Go to noip.com and setup an account. You will need to activate it by email.
-
Remember the new domain name, your account user name, and your noip.com password
-
Set it to the current IP address that you recorded in step A2
-
If you are not using port 80, set up ‘Web Redirect’ on noip.com
-
Enter a website name that is different from the domain name from step B2
-
For URL, enter your domain name from step B2, plus “:181”, where 181 is the port number you choose in step A4b. This will redirect port 80 (web) accesses to your website name (B4a) to port 181 of your domain name.
-
-
If you are using port 80, then the website name is the same as your domain name
-
Setup the Dynamic DNS client on the RPi:
-
‘sudo apt-get update’
-
‘sudo apt-get upgrade’ # makes sure you are on the latest Raspbian version
-
‘sudo apt-get install ddclient libjson-any-perl’
-
just skip through the install questions, we’ll be overwriting them later
-
-
Copy the file ‘ddclient-3.8.3.tar’ to the Raspberry Pi
-
‘tar -xvf ddclient-3.8.3.tar’
-
‘sudo cp -f ddclient-3.8.3/ddclient /usr/sbin/ddclient’
-
‘sudo mkdir /etc/ddclient’
-
‘sudo mv /etc/ddclient.conf /etc/ddclient’
-
‘sudo nano /etc/ddclient/ddclient.conf’
-
use=web, web=checkip.dyndns.com/, web-skip='IP Address'
-
ssl=yes
-
protocol=dyndns2
-
server=dynupdate.no-ip.com
-
login=your_username [from B2]
-
password=your_password [from B2]
-
your.domain.com [from B2]
-
-
‘sudo /etc/init.d/ddclient restart’
-
Look for a IP address update every week:
-
‘sudo nano /etc/default/ddclient’
-
run_daemon="true"
-
run_dhclient="false"
-
run_ipup="false"
-
-
‘sudo service ddclient start’
-
‘sudo nano /etc/cron.weekly/ddclient’
-
#!/bin/sh
-
/usr/sbin/ddclient -force
-
-
‘sudo chmod +x /etc/cron.weekly/ddclient’
-
‘sudo service ddclient status’ # to check that it is working
-
To force a refresh of the IP address, ‘sudo ddclient -daemon=0 -debug -verbose -noquiet’
-
Install a web server on the RPi:
-
‘sudo apt-get install apache2’
-
If you are not using port 80 (A4a),
-
‘sudo nano /etc/apache2/port.conf’ and replace ‘Listen 80’ with your port number (A4b)
-
‘sudo nano /etc/apache2/sites-enabled/000-default.conf’ and replace ‘*:80’ in the first line with your port number (A4b)
-
-
‘sudo service apache2 restart’
-
Check if this works by using a browser to access your website address (step B4a). You may have to wait a few hours for the DNS information propagate through the internet.
-
You can replace the default website with your own website by going to /var/www/html and replacing index.html (as superuser) with your own html file
-
Enabling Python in Apache2 (the web server):
-
Create a place to store the python scripts
-
‘sudo mkdir /var/www/cgi-bin’ # you can choose a different directory
-
-
Add the following lines to the end of the apache2.conf file, ‘sudo nano /etc/apache2/apache2.conf’
-
‘ServerName localhost’
-
‘ScriptAlias /cgi-bin/ /var/www/cgi-bin/
-
‘Options +ExecCGI’
-
‘AddHandler cgi-script .cgi .pl .py’
-
The web server can now run cgi, perl, and python scripts
-
-
Modify the serve-cgi-bin.conf file, ‘sudo nano /etc/apache2/conf-available/serve-cgi-bin.conf’
-
Find ‘ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/’ and replace with the following:
-
‘ScriptAlias /cgi-bin/ /var/www/cgi-bin/’
-
‘<Directory “/var/www/cgi-bin/”>’
-
‘ AllowOverride None’
-
‘ Options +ExecCGI’
-
‘</Directory>’
-
-
sudo a2enmod cgi
-
‘sudo service apache2 restart’
-
You can put your python script in the /var/www/cgi-bin/ directory, but make sure they are executable with ‘sudo chmod 777 *.py’
-
Debug problems with your python script by looking at ‘var/log/apache2/error.log’
-
Add an LCD display to the Raspberry Pi:
-
You will need to connect a I2C LCD to the Raspberry Pi
-
The LCD uses 5V, not 3.3V
-
-
You will need to enable the I2C interface on the RPi
-
In terminal, “sudo raspi-config” then enable the I2C interface
-
In terminal, “sudo i2cdetect -y 0” to get the LCD’s address. Our code uses address 0x3F
-
‘sudo /etc/udev/rules.d/99-com.rules’, change the permission for i2c from 0660 to 0666
-
Reboot the RPi
-
-
There are three files you need to put in /var/www/cgi-bin/
-
i2c_lib.py – this teaches the RPi how to talk to the LCD Display
-
lcddriver.py – these contain the actual commands that the LCD understands
-
lcd.py – this is the code you run for displaying the text message to the LCD
-
Make sure they are all executable with ‘sudo chmod 777 *.py’
-
-
The html file goes in the /var/www/html directory
-
Index.html – called automatically by the web browser and will transfer to the python script when needed
-
-
There is a potentiometer behind the LCD. You may have to adjust it to get a good contrast to see the display.

