Host your own website on a Raspberry Pi 3
A comprehensive step by step guide, covering everything you need to know to , host and maintain a Website running on a Raspberry Pi shared across the internet.
- Raspberry Pi 3
- Raspberry Pi power adapter
- 8 GB (or greater) micro SD Card class 10 (or faster) (and a card reader, duh)
- Router with internet & Ethernet port
- Network cable
- Monitor with an HDMI connection, USB Keyboard and USB mouse (temporarily for the initial setup)
- Can-do attitude!
b. Preparing your Raspberry Pi
c. Installing your Apache server
d. Getting It Online with Static IP
e. SSH-ing the Pi
Preparing your Pi
To start we need to prepare the OS on the SD Card, setup the hardware and connect everything for initial setup.
- Download New Out Of Box Software (NOOBS - an easy operating system installer which contains Raspbian) image here ( Use Offline installer).
- Format the micro SD Card (use FAT32 file system).
- Install Raspbian image on the SD Card using NOOBS installer. Follow the official guide: https://www.raspberrypi.org/help/noobs-setup/
- Insert the micro SD card into the slot and attach the keyboard, mouse, HDMI monitor and network cables. Finally attach the power cable and turn on the power to start your RPi.
- When your RPi boots up, go to Menu > Preferences > Raspberry Pi Configuration.
- Use the
downarrow keys to move the highlighted selection between the options available and select
Advanced Options, and
updateto upgrade all your installed packages to their latest versions.
Installing your Apache server
Next run the following command. This will install Apache server, which is a web server that responds to HTTP requests:
sudo apt-get install apache2 php5 libapache2-mod-php5
now execute the below command to restart Apache with your new settings.
Technically, this is all we need to do to run a very basic web server from our RPi. Give it a go, pop the IP address of your Raspberry Pi in your web browser. You should see a default web page like this:
This means you have Apache working! 👍
This default web page is just a HTML file on the file system. It is located at
/var/www/html/index.html . Now go ahead and paste your webpages after enabling permissions.
Getting It Online with Static IP
You can access and edit your website, but it’s only visible to you on your local network. So how do you get your Web server on the actual Web, not just your local network? You need to set port triggers and register your RPi.
Here are some port forwarding tutorials for major router manufacturers:
Now you’ve got a human-readable domain name that forwards to the Pi’s IP address.
SSH-ing the Pi
We don’t need to have the RPi always attached to the keyboard, mouse and monitor. We can login remotely from a system and continue setting up everything hassle-free.Go to Menu > Preferences > Raspberry Pi Configuration and Enable SSH and reboot you RPi.
Now you will be able to SSH into your Pi, so you can work on it from another computer if you’d like to, with the below default credentials.
username : pi
password : raspberry
Huzzah! That’s it ! 😎