Set up a home media server using a Raspberry Pi and Plex

Nitin Manju
12 min readJul 18, 2020

--

Have a lot of personal media laying around? A good amount of music collection? Definitely photos and music!. However, most of the media lays around unorganised :(

What if something would organise it for you in a simple and stylish Netflix like interface but with additional features like Music playback, Photo albums and Podcasts? Here is a simple project for you to organise your personal media and set up a Netflix like a personal streaming server which can be accessed across all the devices at your home.

Using a media streaming software called Plex, we will set up a personal, local, Netflix like, ‘always online’ server using a low powered Raspberry Pi!

Plex magically organizes your media libraries and streams them to any device

You need to have…

A little bit of knowledge of operating computers. An understanding of client-server architecture, some knowledge on using Linux terminal and SSH, and last but not the least, love for technology and media!

It's ok to not have all the skills and knowledge from above, we can still try and complete this project and you will be learning something new on the way!

Dont get it wrong, Plex server can very well be set up on your working PC Depktop/Laptop. However this article is not about setting up Plex itself but is more about how you can set up your own ‘always online’ local streaming service using a tiny low powered SBC like the Raspberry Pi.

Raspberry Pi 3B+ Single Board Computer

Hardware requirements:

  1. A Raspberry Pi. Henceforth will be referred to as simply Pi. I am using the 3B+ model which has built-in WiFi (Read more about the specs here). However, you could use a lower-end model without wifi as well. You need to connect it directly to your home router using the ethernet cable.
  2. A compatible power adapter for the Pi.
  3. An SD card. I am using a Sandisk 16 GB card, however, I recommend at least a minimum of 8 GB card.
  4. An external hard-disk drive where you have all the media stored (Movies, TV series, Music and Photos)
  5. A PC with an SD card writer. This tutorial will be completed using Windows 10 PC however this should work similarly on Linux and Mac with only some minor tweaks.
  6. A temporary HDMI monitor to configure the Pi for the first time. But is not mandatory!
  7. A good internet connection.

Software requirements:

  1. You will need a Debian based Linux distro running on the Pi: You could use the Ubuntu server 20.04 for ARM. However, I have found the Raspberry Pi OS to be quite simple to use if you are a newbie.
  2. The Plex media server package: More information on how to download this will be explained later.
  3. Raspberry Pi imager tool: You can download the version for windows from here and for other platforms visit the main downloads page.
  4. PuTTY an SSH client for Windows. Download here.
  5. A Plex account: Create one here

OK! Let's get started…

Set up the Raspberry Pi

Let's begin by getting the SD card ready for the Pi.

Install the Raspberry Pi imager tool on your PC. Start the program, it should look something like this:

Click on the ‘CHOOSE OS’ button, as shown above, a new popup should now present you with the available options. Select Raspberry Pi OS (other) as shown below.

Select the OS type

This should now give you more options and now select the Raspberry Pi OS Lite as shown below.

Insert the SD card into the SD card reader/writer slot and click on ‘CHOOSE SD CARD’ a new popup should now allow you to select the SD card

Select the SD card

Once the SD card is selected, you can click on ‘WRITE’ and the program should now download and write the SD card with a bootable image of the OS.

Enabling SSH

By default, SSH is disabled in the Raspberry Pi OS. To enable this, remove the SD card wait for a few seconds and reinsert it into the PC.

SSH can be enabled by placing a file named ssh, without any extension, onto the boot partition of the SD card (In the root of the SD card)from another computer. When the Pi boots, it looks for the ssh file. If it is found, SSH is enabled and the file is deleted. The content of the file does not matter; it could contain text or nothing at all.

If you have loaded Raspberry Pi OS onto a blank SD card, you will have two partitions. The first one, which is the smaller one, is the boot partition. Place the file into this one.

Booting the Pi for the first time

Insert the SD card into the Pi and boot it up. Once the device boots up, there are two ways to determine the IP address allocated to the Pi. Once the IP address is determined you could SSH into the Pi to perform any kind of administration.

Using an HDMI connectivity based desktop monitor:

If you have an HDMI monitor, connect it to the HDMI port of the Pi and reboot the Pi. Login into the Pi using the default credentials Username: pi and the Password: raspberry

Enable the Network Options and WiFi

To enable network options, type in the following command:

sudo raspi-config

Use the arrow buttons to highlight the Network Options (use the up and down arrow) and Select it (use the left and right arrow).

Next, select N2 Wireless LAN

Enter the name of the WiFi network (SSID) and on the next prompt enter the Password and select OK.

The WiFi should now be connected. You can reboot the device to make sure its connected to the internet using the command:

ping www.google.com

You should see a reply from google.com like the image above, press Ctrl + c to cancel the ping.

Headless servers — Using the ARP protocol

If a monitor display is not available also called headless server, connect the Pi directly to the router using an ethernet cable.

To determine the IP address, open command prompt (cmd) and type in the following command:

arp -a | findstr b8-27-eb

SSH-ing into the Pi

Download and install PuTTY on the local machine. Once completed, run the program and enter the IP address of the Pi into the Host Name textbox as below, the port should be 22 and click on Open

Once the connection is established, you should see a terminal prompt asking for login. enter login as pi and password as raspberry

You are now logged in into the Pi. This terminal can be used to perform administrative tasks.

Next, perform the same steps to configure the network as described in the section: Using a HDMI connectivity based desktop monitor

Assigning a static IP for the Pi within the LAN

Home routers are usually allocating dynamic IP addresses to the connected devices in the LAN/WiFi. Assigning a static address to a particular device will make it get the same IP address every time the router is restarted or the device reconnects to the router. Hence the IP address will not have to be determined every reboot.

You will need the MAC address of the Pi to map a static address. The router identifies the Pi using its MAC address on every bootup/connection and allocates the mapped IP address.

Getting the MAC address of the Pi is easy, type in the following command:

ifconfig

under eth0: read the value followed by ether … We will map the MAC address to the IP address 192.168.29.59

NOTE: Read your routers’s documentation on how to set the static reserved IP. See the below image for reference.

Downloading the Plex Media Server Package

Visit the official website and select the Plex Media Server tab as shown, select the platform on the left as Linux and click on Choose Distribution

Under the distributions, select the Ubuntu (16.04+) / Debian (8+) — ARMv7 the image should now be downloaded.

Note: based on the ARM CPU architecture of the Pi, you may have to click on the v8. Refer official Pi documentation for more information for the version of your Pi

Method 1: Using WinSCP tool on your Windows PC

Download WinSCP on to your local machine from here. Once the software is downloaded and installed, run the program.

  1. Click on: Session > New Site
  2. File Protocol: SFTP
  3. Hostname: enter the IP address of the Pi (eg. 192.168.29.59)
  4. User name: pi
  5. Password: raspberry
  6. Click on Login

Once the login is successful, the view should be pretty simple, on the left side view it should display the local PC file system and on the right it should display the file system on the Pi

Find the Plex Media Server package downloaded before and right-click on the file and click Upload and then click OK. The file should now be available on the Pi’s home folder.

Method 2: Using wget command on the Pi using SSH

You could SSH into the Pi and download it using the wget command. To download the package, we will need a direct link to the package file. Right-click on the package name and click on copy link address as shown below.

SSH into the Pi using puTTY as discussed before (refer section: SSH-ing into the Pi), and type the command wget followed by the link address to the package and press enter.

wget https://downloads.plex.tv/plex-media-server-new/1.19.5.3112-b23ab3896/debian/plexmediaserver_1.19.5.3112-b23ab3896_armhf.deb

The package should get downloaded in the current directory. Type the command ls to verify.

Plex Setup

Installing the Plex Server Package on the Pi

SSH into the Pi using puTTY as described before (refer section: SSH-ing into the Pi). It should now take you to the root folder. type the command ‘ls’ and the output will show the file copied in the earlier step.

Now we need to install this using the dpkg utility.

sudo dpkg -i plexmediaserver_1.19.4.2935-79e214ead_armhf.deb

NOTE: The name of the file should match the name displayed in the SSH terminal. The above name in the command is reference purpose only.

Press enter and the prompt should further ask you for confirmations. Accept them and it should be installed as expected. Once the server is installed, it will be accessible at:

http://<ip_address_of_pi>:32400/web/index.html

Replace <ip_address_of_pi> with the actual IP address of the Pi.

Example: http://192.168.29.59:32400/web/index.html

The server will ask you to login into your Plex account when opened for the first time. Enter your login credentials and it should redirect back to your local server.

Configuring the External Drive (HDD) for Plex

Since the OS is running as a headless server, mounting an HDD is a little trickier than usual. This guide should give you all the information you need to set this up.

  1. Create a new folder under the media folder using the command:
sudo mkdir /media/hdd

2. Create a backup of the /etc/fstab by issuing the command:

sudo cp /etc/fstab /etc/fstab.bak

3. Get the external HDD device identifier by typing the command:

df

What we are interested in is the /dev/sda2 but the name may vary.

4. Now lets get the Block ID of this partition by typing the command:

sudo blkid /dev/sda2
UUID and TYPE

You will also notice that it prints the LABEL to identify the drive and TYPE as NTFS. Based on the type of formatting, you may also receive a TYPE as ext4

5. Next we edit the /etc/fstab using the command:

sudo nano /etc/fstab

and add the following line in the file :

UUID=52F89C3FF89C2371 /media/hdd ntfs defaults,auto,rw,nofail 0 1

IMPORTANT NOTE : The UUID is the UUID received when we checked for the block id in step 4. Also make sure the TYPE is set as ntfs or ext4 depending on the drive connected. Refer the screenshot above in step 4 for reference.

Save the file by pressing ctrl + O and then exit using Ctrl + X the file should now be saved.

6. Restart the Pi with the HDD still connected and verify all is as expected by typing the df command again. The drive should still be connected and mounted to /media/hdd

Note: This is one of the important steps in setting up the server and has more chances of things going wrong. Refer this link for more troubleshooting steps.

Adding local media files to the Plex Server from the HDD

To add your local media files to Plex, visit the Plex web app in the browser by navigating to:http://192.168.29.59:32400/web/index.html

And then click on the settings icon/button as shown below.

scroll down to MANAGE on the left menu and click on Libraries. You should now see the libraries. Click on Add Library. A new popup should now appear allowing to select the media type:

Select your choice of media and click Next and click on Browse for Media Folder The hdd should be available on the left as shown below. Click on it to further select the media containing folder and then click on Add

The Server should now start scanning the folders for media files. This will take time-based on the type of the media and the number of files in the folder.

Streaming the media on TV, Mobile, Tablet, Web and more…

We have now set up the server-side of Plex and it is up and running. Now to consume the media, you have several options:

  1. TV — If you rock a Smart TV or a streaming dongle, the Plex client app should be available. I personally own an Amazon Fire TV Stick and the Plex app is available for free. Download, login, boom! The app will automatically detect the server in your local WiFi. You can start browsing the files and stream them.
  2. Mobile — Android OS: Download the app from the play store and login using your credentials. The app should automatically detect the server in your local WiFi. You can start browsing the files. However to play/stream the media file on to your android mobile device, you will need to buy either a plex pass or buy a one time unlock key. Its worth it if you are planning on streaming a lot on your mobile device. Also read: What is Free and what is not
  3. Cast — Google cast/Chromecast: You should be able to cast to a Google cast device from the mobile app or the web app using the cast button.
  4. Tablet — Amazon Fire Tab: Plex is available in the Amazon App Store.
  5. Web — The app is available in browser on a desktop/PC at http://<ip_address_of_pi>:32400/web/index.html
  6. More devices are supported! Get the entire list here
A list of supported client apps/devices - this list is incomplete.

Other than your local media, the client apps will also be supporting online content like Movies, Web shows, Podcasts, Live TV and more!

Conclusion

OK! that's it folks, we now have a very cool, lightweight media organizer and streaming solution. Let know in the comments if you end up implementing this. I have been using this set up for a couple of days now and works very well with my current WiFi. No Lags of any kind even with multiple streams at the same time on multiple devices.

Thanks for reading!

--

--

Nitin Manju
Nitin Manju

Written by Nitin Manju

Software Engineer. Azure and DevOps enthusiast

Responses (1)