Install routine
This tutorial shows how to set up a mobile server. It focuses mainly on the Raspberry Pi side.
In this example, I will use port 42000 and the subdomain mobileserver.dev.mur.at
1.) Install the OS on the Raspberry Pi
1.1.) How to setup OS
First, we need to set up a OS to run on our microSD card. Main steps are:
Insert your microSD card (if it not formatted, you can use SD card formatter): https://www.sdcard.org/downloads/formatter/
Download Raspberry Pi Imager and install it on your computer:
https://www.raspberrypi.org/software/
Run Raspberry Pi Imager and follow the instructions to install the OS on the card.
1.2.) Once you have put the SD card and the OS is running, you have to enable WiFi/LAN connection:
[Note: I assume you have an external screen, a keyboard and a mouse to be used with the Raspberry Pi. If that’s not the case, you can check a tutorial on how to activate ssh by default and use the Raspberry Pi headless:
https://www.tomshardware.com/reviews/raspberry-pi-headless-setup-how-to,6028.html ]
2.) Install Apache server
Before installing the Apache server, make sure the machine is up-to-date. To do this we must have administrator rights, we can use the sudo command:
sudo apt update
sudo apt upgrade
Once the Raspberry Pi is updated, we will install the Apache server:
sudo apt install apache2
To check that it is installed, we can open a browser and write the IP address of the Raspberry Pi. It should appear a screen like this:
[Note: if you don’t know your Raspberry’s IP address, you can use the nmap command:
nmap -sn 192.168.1.0/24
It will list all the IP addresses connected to the router, so you will be able to identify your Raspberry Pi]
3.) Set up proxy server: open port, for example, 42000; set subdomain; generate ssh key par and install public side on proxy server
4.) Copy website files to the public directory of the Apache server on the Raspberry Pi
This process depends on where your files are stored.
For instance, if it is a USB stick, you should use:
sudo cp -r /media/pi/yourusbstickname/websitefolder /var/www/html
[Note: if you don’t know your usb stick name, you can use the following command:
df -h
A list with all devices will appear]
5.) Copy SSH key (already generated) and set permissions
First, you need to create a folder inside root:
sudo mkdir /root/newfolder
Then, copy your SSH key file to this folder. For example, if it is stored within a USB stick:
sudo cd /media/pi/nameofUSBstick/sshfile.txt /root/newfolder
Change permissions of the file:
sudo chmod 500 /root/newfolder/key.txt
6.) Create a new script, which will be used to stablish a ssh connection
Open a new file with text editor and copy or type:
#!/bin/bash
killall ssh
ssh -i /root/newfolder/key.txt -N -R 43001:localhost:80 -l user -p 42000 mobileserver.dev.mur.at
Save the file and make sure to move it inside newfolder:
sudo mv /scriptfolder/script.sh /root/newfolder
Change permissions of the file:
sudo chmod 500 /root/newfolder/script.sh
7.) Cron job to keep tunnel working
sudo crontab -e
Add at the end of the file:
* * * * * /root/folder/script.sh
To save and exit: Ctrl+X and then Y
8.) Start a SSH connection to add the address to known hosts
ssh user@wmobileserver.dev.mur.at -p 42000
It uses our subdomain where we want the mobile server files to be shown and the port that we have opened on the forwarding server (step 5).
If something like this appears:
Are you sure you want to continue connecting (yes/no)?
Type yes
9.) Check that everything works
Open a browser and type the domain or subdomain address you are using, it will show your website files.