1. Webserver

So the first thing I did was use this very helpful guide to help setup my pi as a LAMP server. I didn’t follow the whole thing, just the bits I needed.So following is the basics..firstly install apache

sudo apt-get install apache2

and then mysql

sudo apt-get install mysql-server

And finally PHP

sudo apt-get install php5
sudo apt-get install php5-mysql

Once this is done go to your pi’s IP address to make sure apache works

Because I didn’t get a static IP from my ISP, it changes all the time (which is annoying) so I decided to get a dynamic DNS name for myself. I used www.noip.com and just got a free one.

They also provide something called a DUC(dynamic update client) so your pi can talk to their servers and update the dns record if your ip address changesI found that on the pi it didn’t work with the apt-get install commands so follow the instructions half way down this webpage to manually install it, once set up it will run in the background and tell the noip.com servers if you public IP address has changed

Now for those who don’t want their pi to be linked to a url, I also wrote a small bash script that you can run with cron at whatever interval you want, that checks the current public IP to the previous IP and then emails you of it has changed. This is how I implemented it, with help from this website to set up mail on the pi and link it with your gmail account. I used the SSMTP setup on that page.

Once this is set up, create a file (doesn’t matter what it’s called, but i used ipaddy.sh), make sure to make it executable and open it with your favourite text editor

touch ipaddy
chmod +x ipaddy.sh
vim ipaddy.sh

and then paste in this script, entering your own email address

#!/bin/bash
ip=$(curl icanhazip.com)
line=$(head -n 1 ipaddress)
if [ $ip != $line ]
then
    echo "I have changed your home server ip to: $ip" | mail -s "Shoppinglist.no-ip.org" <your_email_address>
    echo $ip > /home/pi/ipaddress
fi

Close the text editor and create another file which will hold your public IP address

touch ipaddress
curl icanhazip.com > ipaddress

This is create a file and put your public IP address in it for use by the above script Then we need to set up old mate cron to run the script when you want it, I have mine set to run the script every 30 minutes, but you can change it to whatever you like

crontab -e

This will open up the crontab for you to edit, go down the page a little until there’s some blank lines and paste this in:

*/30 * * * * /home/pi/ipaddy.sh

Now you are all set up with a webserver and a way to always know your IP address for when you aren’t at home! The last thing you need to do is forward the right ports out of your home router so you can access your pi over the internet. I have a netgear so there’s plenty of online guides on how to do it, it’s pretty straightforward though

Hope this is useful!