How to Install Plex Media Server on Debian 12, 11, or 10

Plex Media Server is a powerful platform for in-home media solutions. For Debian users, it offers a media management experience. This guide will explain how to install Plex Media Server on Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster, providing you with an all-in-one media hub for your entertainment needs.

Noteworthy Features of Plex Media Server:

  • Consolidated Media Library: Plex seamlessly amalgamates movies, TV shows, music, photos, and more, presenting them in a unified library, eliminating the need to hop between various platforms.
  • Smart Organization & Search: With its ability to automatically fetch metadata, Plex enriches your content with cover art, descriptions, and ratings, while its robust search functionality ensures you find what you’re looking for in no time.
  • Sleek User Interface: Plex boasts a visually captivating interface, which enhances the user experience and makes content discovery delightful.
  • Plex Pass Perks: The Plex Pass subscription elevates your media experience, offering features like Live TV & DVR, Mobile Sync, Parental Controls, and more.
  • Broad Device Support: Plex ensures you can enjoy your media on many devices, from smartphones and tablets to smart TVs and gaming consoles.
  • Anywhere Access: With Plex, your media library is always within reach, accessible from any location with internet connectivity.
  • Content Sharing: Plex allows you to share your media treasures with friends and family, fostering a shared entertainment experience.
  • Expandable with Plugins: The Plex community offers a plethora of plugins, enabling users to enhance the server’s capabilities further and integrate new features.

After highlighting the many advantages of Plex Media Server, the following sections of this guide will cover the installation process on Debian systems, setting you up for an unparalleled media experience.

Update the Debian System Before Plex Installation

Start by updating your Debian system to ensure a smooth installation process. This ensures all existing packages are up to date:

sudo apt update && sudo apt upgrade

Install Initial Required Packages For Plex

Plex installation requires some additional packages. Install them by running the following command:

sudo apt install dirmngr ca-certificates software-properties-common apt-transport-https curl -y

These packages will provide the tools for handling the Plex repository, including secure connections and GPG key management.

Import Plex APT Repository

Add the Plex repository to your Debian system to install Plex from the official source. This ensures you install and update the software directly from the official repository using the APT package manager.

First, open your terminal and import the Plex GPG key with the following command:

curl -fsSL https://downloads.plex.tv/plex-keys/PlexSign.key | gpg --dearmor | sudo tee /usr/share/keyrings/plex.gpg > /dev/null

This command downloads the Plex GPG key, which is used to verify the authenticity of the packages from the repository.

Next, add the Plex repository to your system:

echo "deb [signed-by=/usr/share/keyrings/plex.gpg] https://downloads.plex.tv/repo/deb public main" | sudo tee /etc/apt/sources.list.d/plexmediaserver.list

This command creates a new file in the sources.list.d directory with the necessary information about the Plex repository.

Install Plex Media Server via APT Command

Before installing Plex, update your package index to include the newly added Plex repository:

sudo apt update

Now you can install Plex Media Server on Debian using the following command:

sudo apt install plexmediaserver

During the installation, you may see a prompt asking if you want to replace the imported repository list with Plex. Type “N” to proceed with the installation. You don’t want to replace the imported repository list because the correct signed-by GPG key is already in place.

Verify Plex Media Server Installation

By default, the Plex Media service should start automatically. To verify this, use the following systemctl command to check the status:

systemctl status plexmediaserver

If the service is not active, use the following command to start Plex Media Server:

sudo systemctl start plexmediaserver

To ensure Plex Media Server starts automatically on system boot, enable the service with this command:

sudo systemctl enable plexmediaserver

If you need to restart the Plex Media Server service for any reason, use the following command:

sudo systemctl restart plexmediaserver

Configure UFW Firewall for Plex Media Server

Note: This section is optional, depending on your network setup. However, it is highly recommended to use basic UFW firewall rules with Plex Media Server if you are new to Linux or unsure about network security.

Securing your Plex Media Server is crucial, especially when you plan to access it remotely or allow others to access it. UFW (Uncomplicated Firewall) is a great way to protect your server.

Enable the UFW Firewall

First, check if UFW is installed on your system. If not, install it using the following command:

sudo apt install ufw -y

Next, enable UFW with this command:

sudo ufw enable

Add Plex Media Server Port Rules

Add the default Plex Media Server port (32400) to the UFW rules. You can customize the port later if you wish. If you change the Plex Media Server dashboard port, delete this rule and add a new one.

sudo ufw allow 32400

Additional UFW Rules for Plex

Plex Media Server uses several additional ports for different services and connections. To allow them through the UFW firewall, use the following commands:

sudo ufw allow 1900/udp
sudo ufw allow 3005/tcp
sudo ufw allow 5353/udp
sudo ufw allow 8324/tcp
sudo ufw allow 32410:32414/udp

Here’s a brief explanation of the ports and their purposes:

  • 1900/udp: Used to discover Plex Media Server by clients over the network.
  • 3005/tcp: Required for Plex Companion, a feature that allows you to control Plex playback from a mobile device.
  • 5353/udp: Used for mDNS (Multicast Domain Name System) to help Plex discover devices on the local network.
  • 8324/tcp: Required for the Plex DLNA server.
  • 32410:32414/udp: Used for media streaming to clients.

Adjust your UFW rules if you customize any of the ports mentioned above. Configuring the UFW firewall for your Plex Media Server can ensure a more secure and protected media hub experience on your Debian system if it faces public connections.

Configure SSH For Plex Media Server

Note: This section is optional and only helpful if you use SSH to log in to a remote Debian desktop or server.

If you’ve installed Plex Media Server on a remote headless server or another Debian desktop you don’t always have local access to, you’ll need to set up an SSH tunnel on your local computer for the initial setup. This allows outside connections to access the Plex server.

Set up the SSH Tunnel

Replace {server-ip-address} with the actual IP address of your server, for example, 192.168.50.1.

Example:

ssh {server-ip-address} -L 8888:localhost:32400

If you’re new to SSH and haven’t installed it yet, you can do so with the following commands:

sudo apt install openssh-server -y
sudo systemctl enable ssh --now

Access Plex Media Server via SSH Tunnel

Now you can access the Plex Media Server by opening the following address in your web browser:

http://localhost:8888/web

Or use the alternative address if the above one does not work:

https://localhost:8888/web/index.html#!/setup

The HTTP request will be redirected to http://localhost:32400/web on the remote server through the SSH tunnel.

Access Plex Media Server Remotely

Once you’ve completed the initial setup, you can access your Plex Media Server using your remote server’s IP address:

http://{server-ip-address}:32400

Configuring Plex Media Server in WebUI

Now that Plex is installed on your system, you must configure and complete the setup through the WebUI. The WebUI enables you to manage your media library and customize your server settings. Follow the steps below to access and configure the Plex Media Server in WebUI:

Step 1: Access the WebUI

To access the WebUI, open your preferred internet browser and navigate to one of the following addresses:

http://127.0.0.1:32400/web

or

http://localhost:32400/web

If these two do not work, try using the following address:

http://localhost:32400/web/index.html#!/setup

Now, you can log in using an existing social media account listed above or with your email to register a new account if you are new to Plex. Once logged in, you will begin the initial configuration setup.

Step 2: Understanding Plex

The first configuration page briefly explains Plex and how it works. Depending on their internet browser, Firefox users may see a message prompting them to enable DRM. This choice is necessary; without it, Plex WebUI may not work correctly.

Click GOT IT! to proceed.

Step 3: Optional Plex Pass

Next, you will be prompted to upgrade to Plex Pass, which is optional. Plex Pass offers benefits like HDR options and access to beta builds.

If you want to skip this, click the X in the top right-hand corner. You can always set this up later.

Step 4: Server Setup

Configure your server name, which can be anything you desire. You also have the option to disable Allow me to access my media outside my home. By default, access to outside media is enabled; untick the feature if you don’t plan to do so.

Once configured, click the NEXT button.

Step 5: Media Library

The Media Library page gives you the option to pre-add your media directories.

If you have a media drive or folder ready, click the ADD LIBRARY button.

Now select the type of media you want your folders to be organized into, such as TV shows, movies, music, etc. Click the NEXT button to proceed to add folders.

Click the BROWSE FOR MEDIA FOLDER button and select the media directory. Once the folder is added, the Advanced options will appear, where you can further customize Plex to your liking.

When you’re done, click ADD LIBRARY to continue to the Finish tab.

Step 6: Finishing up

Next, hit the NEXT button to finish the initial setup, with or without adding a Media Library. The next screen informs you that you’re all set.

Click the DONE button to proceed to the Plex Dashboard.

Configure Files & Folders Permissions

You may have noticed that your media did not appear during the initial setup. You may have problems adding content that will not be picked up, with Plex refusing to find the content on your existing internal and external secondary hard drives. This is partly due to Plex creating a dedicated user account named plex, which needs read and execute permission on your media directories.

Debian permissions can be set using chown or setfacl; both are effective. Below are some examples of how to apply these commands to ensure proper access.

Option 1: Set permissions using setfacl

To set permissions using setfacl, execute the following commands, replacing /media/yourfolder/ with the path to your media directory:

sudo setfacl -R -m u:plex:rx /media/yourfolder/
sudo setfacl -R -m u:plex:rx /media/yourfolder/tv
sudo setfacl -R -m u:plex:rx /media/yourfolder/movies

If the commands above are not working, you may need to reinstall the ACL package if it is missing from your system:

sudo apt install acl -y

Option 2: Set permissions using chown

To set permissions using chown, execute the following commands, replacing /media/yourfolder/ with the path to your media directory:

sudo chown -R plex:plex /media/yourfolder/

Or set permissions for individual files in the hard drive if other folders are present that you do not want Plex to access:

sudo chown -R plex:plex /media/yourfolder/tv
sudo chown -R plex:plex /media/yourfolder/movies

Setup Nginx Reverse Proxy for Plex Media Server

Note: This section can be skipped if you do not plan to use Plex through a reverse proxy setup.

Setting up a reverse proxy allows you to access Plex Media Server from a remote computer or network. In this example, we will set up an Nginx proxy server.

Install Nginx For Reverse Proxy Setup

First, install Nginx with the following command:

sudo apt install nginx -y

By default, Nginx should be enabled. If it is not activated, use the following command:

sudo systemctl start nginx

Now check to make sure Nginx is activated and has no errors:

sudo systemctl enable nginx

Now check to make sure Nginx is activated and has no errors:

systemctl status nginx

Create a Plex Nginx Server Block

Create a new server block as follows:

sudo nano /etc/nginx/conf.d/plex.conf

You will need an active domain name and need to create a sub-domain. Once done, add the following to the server block file:

server {
      listen 80;
      server_name plex.example.com;

      location / {
          proxy_pass http://127.0.0.1:32400;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

          #upgrade to WebSocket protocol when requested
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "Upgrade";
      }
}

Save the file (CTRL+O), then exit (CTRL+X).

Test Nginx Configuration

Perform a dry run to ensure there are no errors in the Nginx configuration or your server block:

sudo nginx -t

If everything is working correctly, the example output should be:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Reload Nginx for the change to take effect:

sudo systemctl reload nginx

If you have set up your domain and DNS records to point to your server IP, you can now access your Plex Media Server at plex.example.com.

Secure Nginx Reverse Proxy with Let’s Encrypt SSL Free Certificate

It is recommended to run your Nginx on HTTPS using an SSL certificate. You can use Let’s Encrypt, a free, automated, open certificate authority run by the nonprofit Internet Security Research Group (ISRG).

First, install the certbot package as follows:

sudo apt install python3-certbot-nginx -y

Once installed, run the following command to start creating your certificate:

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d www.example.com

This setup includes force HTTPS 301 redirects, a Strict-Transport-Security header, and OCSP Stapling. Make sure to adjust the email and domain name to your requirements.

Now your URL will be https://plex.example.com instead of http://plex.example.com. If you use the old HTTP URL, it will automatically redirect to HTTPS.

Set Up Nginx Automatic SSL Certificate Renewal

Optionally, you can set a cron job to renew the certificates automatically. Certbot offers a script that does this automatically. First, test to make sure everything is working by performing a dry run:

sudo certbot renew --dry-run

If everything is working, open your crontab window using the following terminal command:

sudo crontab -e

Next, specify the time when the certificate should auto-renew. This should be checked at least daily, and if it needs to be renewed, the script will update the certificate.

Add the following line to your crontab:

00 00 */1 * * /usr/sbin/certbot-auto renew

This command will check for certificate renewal at midnight daily. If a certificate is due for renewal, it will automatically update it. This ensures that your SSL certificate stays up to date and your reverse proxy remains secure.

Additional Commands For Plex Media Server

Update Plex Media Server

Keep your Plex Media Server current to ensure you have the latest features, bug fixes, and security patches.

To check for updates, run the following command:

sudo apt update

If an update is available, use the upgrade command to update Plex Media Server:

sudo apt upgrade plexmediaserver

Or update all packages at once along with Plex Media Server:

sudo apt upgrade

Removing Plex Media Server

If you no longer wish to use Plex and want to remove it from your Debian system, follow these steps.

Uninstall Plex Media Server

Execute the following command to remove Plex Media Server from your system:

sudo apt remove plexmediaserver

Disable Nginx reverse proxy (if applicable)

If you installed the Nginx reverse proxy, remember to disable it and, if necessary, delete the configuration file associated with your domain.

To disable the Nginx reverse proxy, run the following command:

sudo systemctl disable nginx --now

To remove the configuration file, use the following:

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

Finally, reload Nginx to apply the changes:

sudo rm usr/share/keyrings/plex.gpg

Conclusion

In conclusion, installing Plex Media Server on Debian 12, 11, or 10 Linux is straightforward. This allows you to create a powerful and flexible media server for your home or organization. Following the steps in this guide, you can quickly have a fully functioning Plex Media Server up and running. Remember to keep your server updated and maintained for optimal performance and security.

1 thought on “How to Install Plex Media Server on Debian 12, 11, or 10”

Leave a Comment