Using a Raspberry Pi as a web server on your AREDN node

The Apache server is installed on /var/www/html.This is the default root directory of apache. When you type the IP address of your Raspberry Pi, whatever index.html file in the /var/www/html folder will be displayed in your browser.

To make html files on a USB stick show up:
Either change the root directory of Apache or move the project to /var/www/html. I put an entry in /etc/fstab to mount the USB drive on /var/www/html. An index.html file in the root directory of the USB stick will then show up as it was located in the /var/www/html folder.

To make this happen:

If you have a bare bones Raspberry Pi without an SD card, you need to get an SD csrd with a Raspberry Pi OS. Go to this page of Raspberry Pi operating system images. I used the Raspberry Pi OS Lite version, as my SD card was rather small, 2GB. You'll need a USB PC keyboard and an HDMI display to do stuff in the Pi. But first, download the OS (it's a zip file). unzip it, and you'll have an image file (img). Okay, now you need the program here to use your PC to convert the image file and write it to your SD card. I assume you have an SD card read/write port on your PC. The video link shows details.

Now you should be able to take the SD card and insert it into the Raspberry Pi. Also have the HDMI display and an USB PC keyboard connected to the Raspberry Pi. And connect an ethernet cable to teh Pi and your network that has internet access. Power up the Pi and it should boot. You'll first see a multicolor display, then you'll see lines of booting statememts. The default login details for the Raspberry Pi are “pi” as the username and “raspberry” as the password.

We will use "Apache" to make the web server happen. There's other programs for this if you want.

Install Apache

Installing Apache Web Server

Step 1

First of all, make sure to update the package list on your Raspberry Pi by entering the following commands.

sudo apt-get update
sudo apt-get upgrade

Step 2

Then install Apache2 package by entering the following command

sudo apt install apache2 -y

That's it! Just two steps and you have an Apache Web Server up and running on your Raspberry Pi!

To confirm whether this web server is running or not, enter the following command.

sudo service apache2 status

Now, in order to check that Apache is running, you can enter the IP address of your Raspberry Pi on a web browser and you will be presented with a simple test web page as follows.

However, if you don't know the IP address of your Raspberry Pi, you can find it by entering the command below in the terminal of your Raspberry Pi.

hostname -I

The server you just set up is only accessible via your home network and its not accessible through the internet. In order to make this server accessible from anywhere, you need to set up port forwarding on your router. However, we don't plan to discuss this here.

I did not install PHP

I tried it, but I couldn't mount the USB files into the /var/www/html folder. I redid the Raspberry Pi image on the SD card, and installed Apache2 only. And edited /etc/fstab as below.

I've not done any work with PHP, just plain vanilla html code (text and presenting images) with some copied CSS and JavaScript here and there. So you'll have to do your own research on PHP. What distinguishes PHP from something like html, CSS and client-side JavaScript (ie, the user's computer does the executing of the html, CSS and JavaScript) is that the code is executed on the server (the Raspberry Pi), generating HTML which is then sent to the client. The client would receive the results of running that PHP script, but would not know what the underlying code was. Imagine what eBay, Amazon or Google does. But all this means that the server (the Raspberry Pi) would need to know how to execute the PHP code, thus the need to install PHP. But if your html files don't have PHP, then this isn't necessary.

External storage configuration

pirated from

You can connect your external hard disk, SSD, or USB stick to any of the USB ports on the Raspberry Pi, and mount the file system to access the data stored on it.

By default, your Raspberry Pi automatically mounts some of the popular file systems such as FAT, NTFS, and HFS+ at the /media/pi/<HARD-DRIVE-LABEL> location.

To set up your storage device so that it always mounts to a specific location of your choice, you must mount it manually.

Mounting a storage device

You can mount your storage device at a specific folder location. It is conventional to do this within the /mnt folder, for example /mnt/mydisk. Note that the folder must be empty.

  1. Plug the storage device into a USB port on the Raspberry Pi.
  2. List all the disk partitions on the Pi using the following command:


    The Raspberry Pi uses mount points / and /boot. Your storage device will show up in this list, along with any other connected storage.

  3. Use the SIZE, LABEL, and MODEL columns to identify the name of the disk partition that points to your storage device. For example, sda1.
  4. The FSTYPE column contains the filesystem type. If your storage device uses an exFAT file system, install the exFAT driver:

    sudo apt update
    sudo apt install exfat-fuse
  5. If your storage device uses an NTFS file system, you will have read-only access to it. If you want to write to the device, you can install the ntfs-3g driver:

    sudo apt update
    sudo apt install ntfs-3g

    for FAT32 you might need

    sudo apt-get install dosfstools

    (I didn't do this for vfat)

  6. Run the following command to get the location of the disk partition:

    sudo blkid

    For example, /dev/sda1.

  7. Create a target folder to be the mount point of the storage device. The mount point name used in this case is mydisk. You can specify a name of your choice:

    sudo mkdir /mnt/mydisk
  8. Mount the storage device at the mount point you created:

    sudo mount /dev/sda1 /mnt/mydisk
  9. Verify that the storage device is mounted successfully by listing the contents:

    ls /mnt/mydisk

Setting up automatic mounting

You can modify the fstab file to define the location where the storage device will be automatically mounted when the Raspberry Pi starts up. In the fstab file, the disk partition is identified by the universally unique identifier (UUID).

  1. Get the UUID of the disk partition:

    sudo blkid
  2. Find the disk partition from the list and note the UUID. For example, 5C24-1453.

  3. Open the fstab file using a command line editor such as nano:

    sudo nano /etc/fstab
  4. Add the following line in the fstab file:

    UUID=5C24-1453 /mnt/mydisk fstype defaults,auto,users,rw,nofail 0 0
    I wrote
    UUID=5182-4F89 /var/www/html vfat defaults,auto,users,rw,nofail 0 0
    (This looks to put the root folder of the USB stick into the Pi's /var/www/html folder. PHP seemed to get in the way of this, so I reinstalled everything except PHP and it worked.)

    You have to use the specific USB stick associated with the UUID you obtained above.

    Replace fstype with the type of your file system, which you found in step 2 of 'Mounting a storage device' above, for example: ntfs.

  5. If the filesystem type is FAT or NTFS, add ,umask=000 immediately after nofail - this will allow all users full read/write access to every file on the storage device.

Now that you have set an entry in fstab, you can start up your Raspberry Pi with or without the storage device attached. Before you unplug the device you must either shut down the Pi, or manually unmount it using the steps in 'Unmounting a storage device' below.

Note: if you do not have the storage device attached when the Pi starts, the Pi will take an extra 90 seconds to start up. You can shorten this by adding ,x-systemd.device-timeout=30 immediately after nofail in step 4. This will change the timeout to 30 seconds, meaning the system will only wait 30 seconds before giving up trying to mount the disk.

For more information on each Linux command, refer to the specific manual page using the man command. For example, man fstab.

Unmounting a storage device

When the Raspberry Pi shuts down, the system takes care of unmounting the storage device so that it is safe to unplug it. If you want to manually unmount a device, you can use the following command:

sudo umount /mnt/mydisk

Enabling SSH

  1. start the raspi-config tool by typing:

    sudo raspi-config
  2. you should see

    Navigate to "Interfacing Options" using key up or key down and press Enter.

  3. Navigate to "SSH" and press Enter.

  4. You will be prompted whether you like to enable the SSH server. Select "Yes" and press Enter.

  5. The next window will inform you that the SSH server is enabled. Press Enter top go back to the main menu and select "Finish" to close the raspi-config dialog.

Alternatively, instead of using raspi-config tool, you can simply start and enable the ssh service with systemctl:

sudo systemctl 
enable sshsudo systemctl start ssh

Connecting Raspberry Pi via SSH

  1. To connect to Pi via SSH you will need to know your Raspberry Pi IP address. If you are running the Pi without a screen, you can find the IP address in your router’s DHCP lease table. Otherwise, if you have a monitor plugged into the Pi's HDMI, use the ip command to determine the board IP address:

    ip a


    hostname -I
  2. When you've found the IP address, you can connect to your Raspberry Pi from your computer. Windows users can use an SSH client like SmarTTY
  3. The default port is 22. The user name is "pi" and the password is the same you used in the HDMI terminal.

I write html files with my PC and save them and associated image files and such on the above USB stick (which is plugged into the PC for this). Then I'll plug the USB stick into the Pi, then I fire the Pi up.

Assuming you can get the web server to work, "advertise" it on your AREDN node. Leave off the /var/www/html part of the path.

You can "advertise" this web server on two separate AREDN networks, without one network connecting to the other. Use an USB ethernet adaptor, plugged into the other USB jack on the Raspberry Pi. And connect that adaptor to the LAN of the 2nd network's node. Turns out the Pi can make sense of the use of a USB ethernet adaptor. And the Pi gets a second IP address via DHCP. It should show up under "Setup" then "Port Forwarding, DHCP, and Services", in Current DHCP Leases. Then you can do the same procedure as you did on the first network's node.