Apache webserver on Raspberry Pi

1. Install Raspbian (45min)

2. Rapsbian settings

  • change password (default is raspberry)
  • enable interfaces (ssh, vnv, etc)
  • localisation (date, time and keyboard(US interantional)
  • wifi (country id)
  • don’t reboot just yet

3. Check RealVNC catchphrase

  • Wait for RealVNC to generate the signature and catchphrase.
  • Note it down: e.g. Goblin Libya distract, Yoga glacer buzzer

4. Find out your IP address

  • $ ifconfig
  • it will be the inet address

5. Reboot

  • Optional - On your Mac, delete any keys associated with your Raspberry Pi IP address.
  • $ sudo nano ~/.ssh/known_hosts

6. Connect via SSH

  • $ ssh pi@10.0.0.xxx
  • yes to add the new key to your computers known-hosts

7. Update Raspbian operating system

  • $ sudo apt-get update
  • $ sudo apt-get upgrade
  • $ sudo apt-get install unzip
  • $ sudo apt-get install cmake
  • $ reboot

8. Static IP address for SSH

  • $ sudo nano /etc/dhcpcd.conf
  • Paste this into the text area
    #Static IP
    interface wlan0
    static ip_address=
    static routers=
    static domain_name_servers=

9. Additional remote access via SSH

  • Mac OS Terminal ✓
  • iOS RealVNC / Remoter

10. Install git

  • $ sudo apt-get install git
  • Generate ssh keys
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  • Copy key and paste into Github account - new SSH
    cat ~/.ssh/id_rsa.pub

11. Setup remote access via VNC

  • Note: Assumes a RealVNC account has been created, and installed on your computer.
  • On your pi, update realVNC (it comes with Jessie)
    sudo systemctl start vncserver-x11-serviced.service
    sudo systemctl enable vncserver-x11-serviced.service
  • MacOS RealVNC or Terminal (vncserver)
  • iOS RealVNC / Remoter (only works with Tight)

12. Install No-IP DUC

  • Install noip
    cd /usr/local/src
    sudo wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
    sudo tar xzf noip-duc-linux.tar.gz
    cd noip-2.1.9-1
    sudo make
    sudo make install
  • Install the Client Service
    cd /usr/local/src
    sudo wget http://download.sizious.com/rpi/noip-duc-raspbian.tar.bz2
    sudo tar -xjvf noip-duc-raspbian.tar.bz2
    cd noip-2.1.9-1
    sudo chmod +x raspbian.noip2.sh service.install.sh service.uninstall.sh
    sudo ./service.install.sh raspbian
  • Check the No-IP service is working
    systemd-analyze blame
  • Check the No-IP DUC Client Service is running
    systemctl status noip2
  • Checking No-IP settings
    sudo noip2 -S

13. Webserver install Apache PHP mySQL

  • hostname = raspberrypi
  • $ sudo apt-get install apache2 apache2-doc apache2-utils
    sudo apt-get install php5 php5-mysql php5-mysql php5-xcache libapache2-mod-php5 php-pear
    sudo apt-get install mysql-server mysql-client
  • test installation by going to localhost
    cd /var/www/html
    sudo chown pi: index.html
    sudo mv “index.html” “_index.html”
    sudo nano index.php
    <?php echo "hello world"; ?>
    <?php echo date('Y-m-d H:i:s'); ?>
    <?php phpinfo(); ?>
    sudo chown pi: index.php

    sudo apt-get install phpmyadmin
    sudo nano /etc/apache2/apache2.conf
    Include /etc/phpmyadmin/apache.conf (last line)
    sudo /etc/init.d/apache2 restart

14. Router Settings

  • Telstra Gateway: Advanced, Gateway settings, DHCP, Add reserved Mac/IP address
  • Raspberry Pi, MAC address,
  • Advanced, Gateway settings, DynDNS Client, Enable, NOIP
  • Provider: NoIP, Username, Password, Hostname:YOU.hopto.org
  • Advanced, Access Control, Port Forwarding, Add Rule
  • Service: “Whatever Webserver”, Protocol: TCP, External Host: Any, Internal Host:, External Port: 8080, Internal Port: 80

15. Check all the IP addresses

  • Get device ip addresses
    $ ifconfig
    > inet addr: Bcast: Mask:
    $ netstat -nr
    > Destination: Gateway:
  • $ sudo nano /etc/network/interfaces
    > iface eth0 inet dhcp > iface eth0 inet static
    > address
    > netmask
    > network
    > broadcast
    > gateway
  • $ sudo rm /var/lib/dhcp/*
  • $ reboot

16. Check you are seeing your Raspi on the internet

  • Go to your noip address in a browser.

17. Make a backup

  • On your Mac
    ssh pi@ "sudo dd if=/dev/mmcblk0 bs=1M | gzip -" | dd of=~/Downloads/pibackup.gz