Plex Media Server on Ubuntu 22.04
Install Plex Media Server on Ubuntu 22.04 or Raspberry Pi with Apache2 reverse proxy to replace the plex URL with a SSL secure https domain access.

This project is for someone who wants to have a media server that can be accessed by anyone within a household. You can also set it up to be accessed outside your local network.

Plex is a client server setup where the client simply streams data from the plex media server. This means you can have all your movies, music and photos located on the one device, the server. In this case we will be using the Raspberry Pi. You can then have multiple clients connect to the same server. This is great as you don’t need have multiple copies of the same media across several devices.

The plex client is supported on a ton of devices including Windows, Apple, Android, Amazon FireTV, Chromecast, Xbox, PlayStation, Linux and so many more. It really is an amazing home media solution.

Install Plex Media Server

Download Plex Media Server from the plex media server download page or if you are running headless run the following command from your ubuntu prompt

cd /tmp
wget https://downloads.plex.tv/plex-media-server-new/1.29.1.6260-420892357/debian/plexmediaserver_1.29.1.6260-420892357_amd64.deb

Run the following command to install the Plex deb package

sudo dpkg -i plexmediaserver_1.29.1.6260-420892357_amd64.deb

Once Installed, check the plex media server status

sudo systemctl status plexmediaserver

If not running start the plex media server

sudo systemctl start plexmediaserver

Enable Plex Repository

By enabling the official Plex repo, you can update Plex on Ubuntu with apt package manager. The Plex deb package ships with a source list file.

Open the file

sudo vi /etc/apt/sources.list.d/plexmediaserver.list

By default, its content is commented out. Uncomment the last line, save and close the file.

Run the following command to import Plex public key to apt package manager

wget -q https://downloads.plex.tv/plex-keys/PlexSign.key -O - | sudo apt-key add -

Now update software repository index.

sudo apt update

Note that if Plex is installed on a remote Ubuntu 20.04 server, you need to set up a SSH tunnel by executing the following command on your local computer. Replace xx.xx.xx.xx with the IP address of the remote Ubuntu server

ssh xx.xx.xx.xx -L 8888:localhost:32400

Then you can access Plex web interface via the following URL

http://localhost:8888/web

Anytime you would like to restart your plex media server, execute the following command

sudo service plexmediaserver restart

Plex Media Server Initial Setup

The web-based management interface is available at port 32400. The first time you configure Plex, you must visit Plex via 127.0.0.1:32400/web or localhost:32400/web. If you installed Plex on your Ubuntu 20.04 desktop, then you can search Plex Media Manager in your application menu. It will take you to Plex web interface, which in turn will take you to https://app.plex.tv because you need to sign in with a plex.tv account

This HTTP request will be redirected to http://localhost:32400/web on the remote server through SSH tunnel. This SSH tunnel is only needed for the initial setup. After the initial setup, you can access Plex web interface via server-ip-address:32400. Replace server-ip-address with your real server IP address.

Once signed in, you will be redirected to localhost:32400 to do the initial setup. If you don’t see the setup wizard, you can enter localhost:32400/web/index.html#!/setup in the address bar to launch it.

  • On the next screen, enter a name for your Plex server. Make sure Allow me to access my media outside my home is checked. Then click Next.
  • Now you can add libraries. Click Add Library button.v
  • Select a library type, then click browse for media folder button to add your media folders
  • Note that the plex user needs to have read and execute permission on your media directories
    • Follow the procedure mentioned in connecting clients to plex media server to provide read and execute permissions for the media folders/ drive.

Connecting Clients to Plex Media Server

If you’re using an app on your phone, computer, Xbox, PlayStation or any other device then the Plex client should be able to pick up on the server automatically. You will unfortunately find the official mobile Plex applications are behind a paywall. For example, you will need to pay money to get full access to all the features. However all other apps including the web app should be free with only a small set of features requiring a subscription.

To connect in the browser simply enter the IP followed by the port 32400 and /web/. For example, mine is.

http://server-ip-address:32400/web/

To access it from outside the network, port forward external port xxxxx, and internal port 32400 traffic to your server ip

Service NameExternal Starting PortExternal Ending PortInternal Starting PortInternal Ending PortInternal IP address
Plexxxxxxxxxxx3240032400server-ip-address

Mount an external hard drive and ensure read permissions are granted to user ‘plex’ to be able to browse the media located in the usb drive. find plex user uid and gid with the following command

id -u plex
id -g plex
blkid

Ensure the drive mount line in fstab looks like this

UUID=enter-your-drive-uuid /media/plexdrive auto nofail,uid=uid,gid=gid,umask=0027,dmask=0027,noatime 0 0

Replace UUID, UID and GID value with value returned by running the command id and blkid.

Redo the Initial Setup

If you made a mistake in the initial setup, you can delete the Preferences.xml file and start it over.

sudo \rm -rf /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Preferences.xml

sudo service plexmediserver restart

Create Apache Reverse Proxy

If you prefer to use a domain name https://yourdomain.com/web rather than typing http://localhost:32400/web to access your Plex media server, then you need to set up a reverse proxy we can use apache for this purpose.

Follow the article to install LAMP stack on your server, you can limit the procedure to Apache2 installation only, you can ignore Maria DB and PHP installation procedure in the below article, as it is not needed for plex reverse proxy.

Picture showing four layers of LAMP stack.

To Enable and Configure SSL for Plex on Ubuntu for Secure Access using LetsEncrypt Secure Cerificates, follow the below mentioned article

LetsEncrypt Logo - Letsencrypt is used for SSL secure access for Nextcloud

To use Apache as a reverse proxy, we need to enable the proxy modules and the header module.

sudo a2enmod proxy proxy_http headers proxy_wstunnel

Then create a virtual host file for Plex.

sudo vi /etc/apache2/sites-available/plex.conf

Put the following configurations into the file.

      <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>
        ProxyRequests Off
        ProxyPass               /web   http://localhost:32400/web
        ProxyPassReverse        /web   http://localhost:32400/web
        <LocationMatch '^/web\/.*$'>
                RequestHeader set Front-End-Https "On"
                RewriteEngine On
                RewriteCond     %{REQUEST_URI}          !^/web
                RewriteCond     %{HTTP:X-Plex-Device}   ^$
                RewriteCond %{REQUEST_METHOD}   !^(OPTIONS)$
                RewriteRule ^/$ /web/$1 [R,L]
        </LocationMatch>

Save and close the file. Then enable this virtual host

sudo a2ensite plex.conf

Restart Apache

sudo systemctl restart apache2

And you can access Plex web interface via HTTPS.

https://yourdomain.com/web

Login with your user name and password and you are good to go!

Similar Posts

  • All
  • apache2
  • letsencrypt
  • nextcloud
  • ssl
  • ubuntu
  • fail2ban
  • raspberrypi
  • ssh
  • deluge
  • torrent
LetsEncrypt Logo - Letsencrypt is used for SSL secure access for Nextcloud

Mobeen Syed on December 8, 2020

Enable and Configure SSL Secure access (https) for NextCloud or any domain you own using LetsEncrypt Free SSL Certificates which are renewable

Mobeen Syed on October 3, 2022

This article will help you setup Secure File Transfer Protocol (SFTP) server on Ubuntu 22.04 using VSFTPD protocol and SSHD Secure service.

Mobeen Syed on September 9, 2021

Network Wide Block Advertistment, Pornography and Adult Content with AdGuard Home Installed on Raspberry Pi or Ubuntu Server

Leave a Reply

Your email address will not be published. Required fields are marked *