Use your Raspberry Pi as a local server

Use your Raspberry Pi as a local server

Yash Aryan's photo
Yash Aryan

Published on Jan 13, 2021

7 min read

Subscribe to my newsletter and never miss my upcoming articles

Raspberry Pi Logo Did you buy a new Raspberry Pi and want to set up a local home server on it, and don't know how to set it up? Well, you are viewing the correct blog post. When I got a Raspberry Pi, I had no idea what I would do with it apart from using it as a WiFi router. But as I kept experimenting, I realized that there was too much I could do with it. In this article, I will guide you through the process of setting up a home server on your Raspberry Pi.

My case

I live at my university's hostel. The WiFi reception in my block, and especially my room, is horrible, so we have an RJ45 port in our room. A restriction imposed on my campus network was that only three devices could be registered, and out of those, only one can be connected at a time. But the problem was that I had 4 devices that needed to be connected to the internet, sometimes, simultaneously. I know, it's a bit intricate. One more thing that makes it a pain is that there is a captive portal involved. So I have to login every time I switch devices.

Solutions I thought of

Before I thought of getting a Raspberry Pi, I thought of other methods. One way was to connect my PC to the ethernet port and then turn on the hotspot. Easy, right? But this would mean that I had to keep my PC turned on throughout the day, and laptop batteries aren't cheap. This also meant that I had to say goodbye to my laptop's portability.

Another solution was to buy a router and connect it to the port. I was almost going to buy this one, but I wanted more features, and I wanted a good enough signal for my room, but not for the person who lived across the hallway. A laptop hotspot was good for this, but you obviously know the limitations there. I also wanted a router with NAS support. Well, there goes my budget. Then I came across Raspberry Pi. A mini-computer that ran Linux and is fully programmable. I had found the perfect toy for myself.

Setup

I ended up purchasing a Raspberry Pi 4 Model B. It has 4 GB RAM, a Gigabit Ethernet Chip, 2 USB 2.0 ports, and 2 USB 3.0 ports. You can buy it here. I connected my Raspberry Pi to the ethernet port using an RJ45 cable, connected it to a power source, and connected my external HDD to one of the USB ports (for making a NAS). I could have used the Raspberry Pi OS, but I wanted something light. So I went ahead with Ubuntu Server.

Getting started

For this tutorial, I am assuming that your distro is up-to-date and the device is running the most recent stable version of Ubuntu. For the time, you either need to connect your Pi to an external display, or you can connect to it using VNC. You can also SSH into it if they are connected to the same network. So now, let's get started.

Setting up the server

Now that everything is understood, let us start with setting up the server.

Setting up the R-Pi hostname

You can reach your Raspberry Pi on your local network using the URL raspberrypi.local. But you can change this to anything, like myserver.local or mypi.local by editing the /etc/hosts file. More on that here. Once you do this, you are good to go.

Setting up your Pi as an AP

Connect your ethernet cable to the Pi and the Port. The next step would be installing software called raspap-webgui which helps set up your wireless AP.

RaspAP lets you quickly get a WiFi access point up and running to share the connectivity of many popular Debian-based devices, including the Raspberry Pi. Our popular Quick installer creates a known-good default configuration that "just works" on all current Raspberry Pis with onboard wireless. A responsive interface gives you control over the relevant services and networking options. Advanced DHCP settings, OpenVPN client support, SSL, security audits, themes, and multilingual options are included.

Head over to github to learn how to install it on your device.

After the installation is done, you can see raspi-webgui as a wireless AP on your wireless-enabled devices. You can also find the default password to the AP and the router settings here. Your router's default IP will be 10.3.141.1. You can access your router settings by going to http://10.3.141.1 and using the default password and username provided in the readme of the GitHub repository.

You have successfully created a wireless AP using your raspberry at this stage.

Hosting websites on your PI

Now that you are connected to your Pi's network let us make it more usable. I have my personal journal set up on my device. It can only be accessed if I am connected to the raspi-webgui AP. You can find it here. To set this up, I installed Nginx. Using this, I can set up multiple websites on my Pi. Since I already have raspberrypi.local as my Pi's hostname, I can set up multiple sub-domains to host different websites. If you do not know how to set up Nginx, you can take a look here.

To make sure your Nginx is installed correctly, browse to raspberry.local while connected to the newly created AP. You should see a page that looks like this.

Nginx home screen

Let's say that I set up Nginx to use the journal as the sub-domain to host my journal website, and I can enter journal.raspberrypi.local in my browser's address bar while connected to the raspi-webgui to view my website. I can set up more websites on this server by creating more Nginx configuration files and using up more sub-domains.

Setting up SMB on the Pi

I have a lot of study materials, movies, photos, and videos on my external HDD. Whenever I come to my room, I first have to turn on my laptop and then connect it to my hard drive to access those files. If I want to lie down and use my phone to watch some video, I first have to transfer those to my phone and then watch it. I know. It does not sound like too much work, but I am lazy. I like to do things with as few steps as possible. Maybe that's why I am bad at chess. Getting back to the discussion, I connected my hard drive to the Pi and installed Samba to access the files on the drive on any device whenever I am connected to my Pi AP. This guide provides a straightforward method to install Samba on your Pi. Do remember to mount your drive before you proceed. You can mount as many drives on your Pi and access it on any device connected to your AP.

What can you do next?

That was it for this tutorial. But that is not the end of possibilities. These are some other things you can add to your server.

  • Using the temperature and humidity sensor to get the weather report.
  • Control some IoT devices using your Pi connected on the same network.
  • Setting up a hostel room security service.
  • Installing Alexa on your Pi.
  • You can go ahead and contact your ISP to provide you with a static public IP address so that you can access your Pi from anywhere in the world. (This might be risky. If you do not have the skills to make your server secure, you might be putting every device in your local network at risk) The list of things you can do with this setup is endless. It's all based on how creative you get.

Thanks

Hope you found this article informative and intriguing. If it helped you, do give it a like 🧡 and share it with people who might find it useful. Also check out my Instagram and Facebook pages for more content. Buy Me A Coffee

 
Share this