Post

Shiny New Plex

Shiny New Plex

Do it yourself

Self-hosted home media solutions have been a thing for well over a decade. Plex was first released in 2009. Hell, with the rapid growth of the world wide web and the multimedia content of the day you could’ve started self hosting music and movies with Windows XP Media Center Edition as early as 2005 (BOOMER ALERT). Because consumer electronics are so cheap and capable these days, and because your average home router and modern wifi technology provide more than enough performance, streaming your own media is a real solution for most people. And because paying for subscriptions, or not paying for subscriptions and suffering through advertisements, are the absolute fucking worst. You can and you should. What we’re doing here is setting up a Plex server on a new Orange Pi Zero 2 W with Armbian.

New hardware(?)

If you already have a device you will be using and don’t care about setting up a new server (and by extension me as a person), you can skip to the Software section. Also you’re mean.

You can run Plex on a lot of things. To prove that, I’m showing you how to set up an Orange Pi Zero 2 W 2 GB and run Plex in a container. The Orange Pi Zero 2 W is only $28 on the Amazons. Let’s be honest though, you don’t even need a dedicated device. I used to run Plex from the family desktop PC - it was super annoying when someone else in the house used it and shut it down when they were finished, not knowing that I was watching something. Or you could use your laptop. I just love the idea of deploying a tiny computer. Is that surprising? All told, everything you will need (a 512 GB micro SD card, a power supply, and a modest case) costs about $85 USD.

I can see why you might balk at the price compared to $30 for a brand new Roku that works out of the box with no assembly required. I ask you to consider this: what you’re actually purchasing is a tiny computer that has more than a single purpose, unlike the Roku. If you decide to give up on streaming, use it for something else! But obviously the overall cost decreases if you do have an old SD card lying around (it doesn’t have to be 512 GB, that’s just a suggestion), and/or a USB-C power supply capable of providing 5V, 3A power (like a modern smartphone charger). If you have those things already, congrats - this solution is actually cheaper than the Roku. And you don’t really need the case, you can literally plug in the Orange Pi and leave it running on a shelf somewhere. This is what it looks like assembled, isn’t it cute?

Orange Pi Zero 2 W in case

Operating system

  1. Install the Orange Pi Armbian minimal/IOT image to the SD card using Balena Etcher. When you download the image, extract the .img file within the compressed download file. Plug the SD card into a computer, open Etcher and select the extracted image file, select the SD card plugged in, then flash. Etcher will write and verify the image and then eject the media. Unplug the SD card from your computer and plug it back in for the next step.

  2. Configure the Armbian headless setup. This part isn’t mandatory but unless you also have a mini HDMI to HDMI cable, a monitor to plug it into, and a USB-C keyboard, you won’t have an easy way to access the Orange Pi in order to continue. This step puts the thing on your network automatically and all you have to do is log into it.

    Windows users, you can’t use MS Notepad for this because Windows handles new line values differently than Unix-based operating systems. Use Notepad++ to get around this by converting the document EOL to Unix (LF). If you don’t do this, Armbian won’t know what tf to do with that file.

    First, write an Armbian configuration file on the SD card. Create a file in the /root directory of your SD card named .not_logged_in_yet. Armbian will look for this file at the first boot to automatically configure networking and other settings during the initial boot routine. This is the template, edit it so it works on your network and locale:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    
     # Network Settings
     PRESET_NET_CHANGE_DEFAULTS="1"
    
     # WiFi
     PRESET_NET_WIFI_ENABLED="1"
     PRESET_NET_WIFI_SSID="CLEVER-WIFI-NAME"
     PRESET_NET_WIFI_KEY="SuperSecretPassword!"
     PRESET_NET_WIFI_COUNTRYCODE="US"
     PRESET_CONNECT_WIRELESS="y"
    
     # Static IP
     # Only set USE_STATIC to 1 if you want to specify the IP address on the network
     # Otherwise set this to 0 and remove all NET_STATIC options
     PRESET_NET_USE_STATIC="1"
     PRESET_NET_STATIC_IP="10.0.0.205"
     PRESET_NET_STATIC_MASK="255.255.255.0"
     PRESET_NET_STATIC_GATEWAY="10.0.0.1"
     PRESET_NET_STATIC_DNS="1.1.1.1 1.0.0.1"
    
     # System
     SET_LANG_BASED_ON_LOCATION="y"
     PRESET_LOCALE="en_US.UTF-8"
     PRESET_TIMEZONE="Etc/UTC"
    
     # Root (optional)
     PRESET_ROOT_PASSWORD="newRootPw"
     PRESET_ROOT_KEY=""
    
     # User (optional)
     PRESET_USER_NAME="pimp"
     PRESET_USER_PASSWORD="SuperSecretPassword1"
     PRESET_USER_KEY=""
     PRESET_DEFAULT_REALNAME="pimp"
     PRESET_USER_SHELL="bash"
    

    I prefer to set a static IP address because then I know how to connect to it when it powers on. If you don’t set a static IP, there are things you can do to figure it out once it comes online but let’s keep it simple. Before you pick an IP, perform a ping on it to see if anything else on the network is using it.

    Second, edit the hostname by editing /etc/hostname on the SD card. Again, this is optional but it does make the deployment easier. The default hostname is orangepizero2w.

  3. Log in for the first time to configure the system. If everything went well, the Pi Zero came up on the network and is ready for login. From a computer, open an SSH console to it. Using a BASH terminal or Powershell 7, run:

    1
    
     ssh root@[Pi IP]
    

    If you don’t know the IP, you can try using the hostname like this:

    If you didn’t set a password in the headless config file, the default password should be 1234. If you didn’t set up an alternate user, you will land at the Orange Pi Armbian login banner as the root user:

    Armbian login

    If you did set up a user, Armbian will run through a user creation process before dumping you to the login banner. It sets the password to whatever you entered in your config. You can ignore the warning about the developers build, just tell them the admin said it was okay:

    new Armbian user

    Open another SSH session to the Pi using the new user credentials and you will land at the same login banner. To disable the root account from being able to log in, as the new user, enter sudo usermod -L root. Lastly, run updates: sudo apt update && sudo apt upgrade -y.

    Setting up the Orange Pi is a little more hands on than, say, a Raspberry Pi. If they made a Raspberry Pi Zero with more than 0.5 GB of memory, I would probably jump on it because they have really mastered the onboarding process with their Raspberry Pi Imager - this tiny Pi Zero form factor is just so damned convenient. While we’re on the subject of Raspberry Pi, a Pi 4 or 5 are also fine choices for running a Plex server. The instructions from this point forward should be valid for all Debian-based Linux servers so use whatever is cheapest/easiest for you. I also ran Plex on Windows for many years, you can find instructions for that online elsewhere. You basically just run the Plex installer and open the web interface on the local machine and configure it. And now maybe you don’t need to go looking for instructions after all.

Software

  1. Install Docker:
    1
    
    curl -sSL https://get.docker.com | sh
    

    Add your user to the Docker group, then log out and log back in to take effect:

    1
    
    sudo usermod -aG docker $USER
    
  2. Set up necessary the Plex bits, starting with a new Plex user:
    1
    
     sudo adduser plex
    

    Get the user UID/GID:

    1
    
     id plex
    

    Make a new directory and Docker Compose file for the Plex container:

    1
    2
    3
    
     mkdir ~/docker
     mkdir ~/docker/plex
     nano ~/docker/plex/compose.yaml
    

    Enter this, save and exit:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    
     services:
     plex:
         image: lscr.io/linuxserver/plex:latest
         container_name: plex
         network_mode: host
         environment:
         - PUID=PLEX-USER-UID
         - PGID=PLEX-USER-GID
         - VERSION=latest
         volumes:
         - /dev/shm:/transcode
         - /etc/localtime:/etc/localtime:ro
         - ./config:/config
         - ./multimedia:/multimedia
         restart: unless-stopped
    

    Make two additional directories that the Plex container expects, one will be used to store Plex’s configuration database and the other is where you will put your Movies and TV shows:

    1
    2
    
     mkdir ~/docker/plex/config
     mkdir ~/docker/plex/multimedia
    

    You can add your media by shutting the server down and plugging the SD card back into your computer, then copying your files to the multimedia directory. If you have both movies and TV shows, you should create separate sub-directories for each - this will make it easier for Plex to know how to treat your media. Plex has file and folder conventions for movies and TV shows that you should definitely check out before you get too far along, especially with TV shows.

  3. Deploy the Plex container: docker compose -f ~/docker/plex/compose.yaml up -d

Configure Plex

  1. Start the Plex configuration by opening a web browser to [Pi IP]:32400/web from a computer. I have tried this from a phone browser and had a bunch of problems, save yourself the trouble and do this from a computer or laptop if you can. You’ll be met with the login splash screen: Plex splash screen

    Sign in if you already have an account, or click Continue with Email, then click sign up with email to create an account. After signing in, click past the offer to subscribe to Plex - it’s not necessary to self-host. Honestly, I don’t even know what the subscription includes because I’ve never used it. Is that awful?

    In the server setup, confirm the Plex instance name and uncheck the box to Allow access to your media outside your home (again, not necessary for what we’re doing here), then click Next:

    Plex server config

    On the following screen click Next, you can add the media libraries after the initial config:

    library

    Finish the configuration by unchecking all the proposed shortcuts to reduce the clutter, and clicking Finish Setup:

    finish Plex setup

  2. If you haven’t copied your media to the multimedia folder on the SD card yet, shut down the Pi Zero and do it now: sudo shutdown now. There are more server admin-y ways to copy files like using SCP or setting up a SAMBA share but that’s another post for another day by another author.
  3. Create the libraries from the Plex interface. On the left side of the home screen, click the More button and you’ll see your Plex server name. Click the + next to it to add a library. For this example, select a movie library type and click Next:

    add movies library

    Click Browse For Media Folder, then scroll down the folder list and click multimedia, then click Add:

    multimedia folder

    All the movies in that folder will now be processed by Plex and added to the library:

    Plex movies!

  4. Fix incorrect matches using the web browser and following their documentation. Plex gets things mostly right.
  5. Every time you add new media to an existing library, click the Menu button next to the library on the Plex interface and click Scan Library Files. It will immediately scan and add new media with matching title information.
  6. Watch Plex, it’s ready to go! You can watch from any web browser on your home network using the earlier URL [PI IP]:32400/web, or from a smart TV or Roku or other such device using the Plex app. Your TV should find the device on the network automatically. Yes, you can have the best of both worlds and stream your own self-hosted media alongside your paid or free (ads) streaming content. Or even better still, your paid streaming content that still has ads for some reason hahaha haha fuck you Hulu.
This post is licensed under CC BY 4.0 by the author.