Install Plex Media Server on Ubuntu

Install (for ubuntu)

It's Back! After a long abscence the repo has returned

echo deb https://downloads.plex.tv/repo/deb/ public main | sudo tee /etc/apt/sources.list.d/plexmediaserver.list
curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -

sudo apt-get update
sudo apt-get install plexmediaserver

You may wish to relocate the library database for space or security reasons

sudo service stop plexmediaserver
sudo mv 
/var/lib/plexmediaserver /mnt/crypt
sudo ln -s /mnt/crypt/plexmediaserver 
/var/lib/plexmediaserver
sudo chown plex:plex 
/var/lib/plexmediaserver

You may also need to adjust the range of IPs allowed in without Auth for initial setup

sudo vim "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Preferences.xml"

... allowedNetworks="192.168.1.0/24" ...

Allow Firewall Access

sudo vim /etc/ufw/applications.d/plexmediaserver

[plexmediaserver]
title=Plex Media Server
description=Plex Media Server is the back-end media server component of Plex
ports=32400/tcp

# Add custom rules as needed
sudo ufw allow from xxx.xxx.xx.0/23 to any app plexmediaserver
sudo ufw deny from xxx.xxx.0.0/16 to any app plexmediaserver
sudo ufw allow plexmediaserver

Setup Command Line Control

You can kick off scans via the command line, but you have to invoke the commands as the plex user.

#!/bin/bash

sudo su -c "export LD_LIBRARY_PATH=/usr/lib/plexmediaserver;/usr/lib/plexmediaserver/Plex\ Media\ Scanner --scan" plex

You can also just become the plex user, of course, if it's not too awkward


sudo -i -u plex
/usr/lib/plexmediaserver/Plex\ Media\ Scanner --list --section 1

Searching for mis-matches in the DB

When you have a large collection, it becomes almost impossible to find where some items land at. You can however, search the database

sudo apt install sqllite3

sqlite3 "/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db"

select media_item_id,file from media_parts where file like "%Doctor Who E07E01.mkv%";

select metadata_item_id,hints from media_items where id=1011881;

select title from metadata_items where id=173491;

Or for a complex join

SELECT
    metadata_items.title,media_parts.file
FROM
    metadata_items 

JOIN media_parts JOIN media_items

WHERE
    metadata_items.library_section_id=1
    AND
    metadata_items.id=media_items.metadata_item_id
    AND
    media_items.id=media_parts.media_item_id
    AND
    media_parts.file LIKE "%Doctor Who E07E01.mkv%";




Test

curl http://localhost:32400

Access
http://<server name>:32400/web

Moving

cd /var/lib
tar -czf ~/plexmediaserver.tgz plexmediaserver

Troubleshoot

sudo vim /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Preferences.xml 

tail -20 /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Logs/Plex\ Media\ Server.log

http://wiki.plexapp.com/index.php/Downloads#Linux_-_PMS

https://support.plex.tv/hc/en-us/articles/201105343
----

apt update gives the warning:


W: Conflicting distribution: https://downloads.plex.tv/repo/deb public InRelease (expected public but got )

From Plex

Yes, There is a warning. Ignore it.
There are two different requirements for the layout based on the distro itself (Debian vs Ubuntu).
We ended up with a compromise which works except for Ubuntu 17 and that warning.


Database info
https://forums.plex.tv/t/howto-query-data-from-plex-on-a-mac/11636
Comments