How to install Plex Media Server on CentOS 8

How to install Plex Media Server on CentOS 8

Plex is a free, open-source and full-featured media server that lets you stream photos, videos, and audio files from anywhere in the world to your PC, tablet, and phone. Plex supports most operating systems, including Linux, Windows, Mac and FreeBSD. Plex also supports multiple plugins, allowing you to watch content from Comedy Central and MTV.

Plex is a client-server media player system. You just need to install the Plex server on the server that holds the media, and then install the Plex app for your phone, tablet or other device to access the media over the Internet.

Features support multiple users. Show movie / TV show recommendations. Create playlists of your favorite music and movies. Sync and access media files for offline use. Parental controls allow you to install the Plex app on children’s devices and restrict them to watching only specific content. Ability to stream local TV channels to devices and watch live TV.

In this tutorial, we will show you how to install Plex Media Server on a CentOS 8 system using Nginx as a reverse proxy.

prerequisites

  • A server running CentOS 8 with at least 2 GB of RAM.
  • A valid domain name points to your server IP.
  • A root password is configured on your server.

Update system

First, it is recommended to update the server with the latest version. You can update it with:

dnf update -y

After updating the server, restart the server to implement the changes.

Install Plex Media Server

By default, the Plex Media Server package is not available in the CentOS 8 default repository. So you will need to create a repository for Plex Media Server. You can create it using:

nano /etc/yum.repos.d/plex.repo

Add the following lines:

[Plex]
name=Plex
baseurl=https://downloads.plex.tv/repo/rpm/$basearch/
enabled=1
gpgkey=https://downloads.plex.tv/plex-keys/PlexSign.key
gpgcheck=1

Save and close the file when you are finished. Then install the Plex Media Server using the following command:

dnf install plexmediaserver -y

After installation is complete, start Plex Media Services and use the following command to start it after the system reboots:

systemctl enable plexmediaserver systemctl start plexmediaserver

You can also use the following command to verify the status of the Plex media server:

systemctl status plexmediaserver

You should see the following output:

? plexmediaserver.service - Plex Media Server
   Loaded: loaded (/usr/lib/systemd/system/plexmediaserver.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-01-06 02:45:40 EST; 41s ago
 Main PID: 1009 (Plex Media Serv)
    Tasks: 113 (limit: 12552)
   Memory: 268.1M
   CGroup: /system.slice/plexmediaserver.service
           ??1009 /usr/lib/plexmediaserver/Plex Media Server
           ??1033 Plex Plug-in [com.plexapp.system] /usr/lib/plexmediaserver/Resources/Plug-ins-349e9837e/Framework.bundle/Contents/Resources/>
           ??1077 /usr/lib/plexmediaserver/Plex Tuner Service /usr/lib/plexmediaserver/Resources/Tuner/Private /usr/lib/plexmediaserver/Resour>
           ??1246 Plex Plug-in [org.musicbrainz.agents.music] /usr/lib/plexmediaserver/Resources/Plug-ins-349e9837e/Framework.bundle/Contents/>
           ??1356 Plex Plug-in [com.plexapp.agents.plexthememusic] /usr/lib/plexmediaserver/Resources/Plug-ins-349e9837e/Framework.bundle/Cont>
           ??1364 Plex Plug-in [com.plexapp.agents.themoviedb] /usr/lib/plexmediaserver/Resources/Plug-ins-349e9837e/Framework.bundle/Contents>
           ??1365 Plex Plug-in [tv.plex.agents.music] /usr/lib/plexmediaserver/Resources/Plug-ins-349e9837e/Framework.bundle/Contents/Resource>
           ??1389 Plex Plug-in [com.plexapp.agents.thetvdb] /usr/lib/plexmediaserver/Resources/Plug-ins-349e9837e/Framework.bundle/Contents/Re>
           ??1450 Plex Plug-in [com.plexapp.agents.imdb] /usr/lib/plexmediaserver/Resources/Plug-ins-349e9837e/Framework.bundle/Contents/Resou>

Jan 06 02:45:40 plex systemd[1]: Starting Plex Media Server...
Jan 06 02:45:40 plex systemd[1]: Started Plex Media Server.

At this point, the Plex Media Server is installed and running. You can now proceed to the next step.

Configure firewall and SELinux for Plex Media Server

Next, you will need to configure firewalld to allow Plex Media Server specific ports. You can do this by running:

firewall-cmd --zone=public --add-port=32400/tcp --permanent firewall-cmd --zone=public --add-port=32469/tcp --permanent firewall-cmd --zone=public --add-port=8324/tcp --permanent firewall-cmd --zone=public --add-port=3005/tcp --permanent firewall-cmd --zone=public --add-port=32412/udp --permanent firewall-cmd --zone=public --add-port=32413/udp --permanent firewall-cmd --zone=public --add-port=32414/udp --permanent firewall-cmd --zone=public --add-port=32410/udp --permanent firewall-cmd --zone=public --add-port=1900/udp --permanent firewall-cmd --zone=public --add-port=5353/udp --permanent firewall-cmd --zone=public --add-port=80/tcp --permanent

Next, reload the firewalld service to implement the changes:

firewall-cmd --reload

SELinux is enabled by default on CentOS 8 servers. Therefore, you will need to configure SELinux to access Plex Media Server over the Internet. You can configure SELinux with the following command:

setsebool httpd_can_network_connect on -P

At this point, you can access the Plex Media Server through the Internet. You can now proceed to the next step.

Accessing Plex Media Server

Now you can access the Plex Media Server using the URL http: // your server-ip: 32400. You should see the following page:

Next, you need to register with a valid email address to use the service. After successful registration. You will be redirected to the Plex Media Server dashboard as shown below:

Plex Media Server Dashboard

Set Nginx as a reverse proxy

Next, you need to set up Nginx as a reverse proxy so that you can access it using a domain name without having to provide an IP address and port number.

To do this, first install the Nginx web server using the following command:

dnf install nginx

After the installation is complete, start the Nginx service and use the following command to start it after the system restarts:

systemctl start nginx systemctl enable nginx

Next, create the Nginx virtual host profile for Plex using the following command:

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

Add the following lines:

upstream plex_backend {
        server 127.0.0.1:32400;
        keepalive 32;
}

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

        send_timeout 100m; #Some players don't reopen a socket and playback stops totally instead of resuming after an extended pause (e.g. Ch$

       	#Plex has A LOT of javascript, xml and html. This helps a lot, but if it causes playback issues with devices turn it off. (Haven't enc$
        gzip on;
        gzip_vary on;
        gzip_min_length 1000;
        gzip_proxied any;
        gzip_types text/plain text/css text/xml application/xml text/javascript application/x-javascript image/svg+xml;
        gzip_disable "MSIE [1-6].";

       	#Nginx default client_max_body_size is 1MB, which breaks Camera Upload feature from the phones.
       	#Increasing the limit fixes the issue. Anyhow, if 4K videos are expected to be uploaded, the size might need to be increased even more
        client_max_body_size 100M;

       	#Forward real ip and host to Plex
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Sec-WebSocket-Extensions $http_sec_websocket_extensions;
        proxy_set_header Sec-WebSocket-Key $http_sec_websocket_key;
        proxy_set_header Sec-WebSocket-Version $http_sec_websocket_version;
       	#Websockets
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";

       	#Buffering off send to the client as soon as the data is received from Plex.
        proxy_redirect off;
        proxy_buffering off;

        location / {
                proxy_pass http://plex_backend;
        }
}

Save and close the file when you are finished. Next, you will need to define the Nginx server hash bucket size. You can do this by editing the Nginx configuration file:

nano /etc/nginx/nginx.conf

Add the following line above the last line:

server_names_hash_bucket_size 64;

Save and close the file when you are finished. Then, check for Nginx syntax errors using:

nginx -t

You should see the following output:

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

Finally, restart the Nginx service to implement the changes.

systemctl restart nginx

To check the status of the Nginx service, run the following command:

systemctl status nginx

If everything works, you should get the following output:

? nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/nginx.service.d
           ??php-fpm.conf
   Active: active (running) since Thu 2020-01-09 05:17:27 EST; 48s ago
  Process: 1230 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 1229 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 1227 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 1232 (nginx)
    Tasks: 2 (limit: 5060)
   Memory: 13.1M
   CGroup: /system.slice/nginx.service
           ??1232 nginx: master process /usr/sbin/nginx
           ??1233 nginx: worker process

Jan 09 05:17:25 centos8 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jan 09 05:17:27 centos8 nginx[1229]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 09 05:17:27 centos8 nginx[1229]: nginx: configuration file /etc/nginx/nginx.conf test is successful

You can now access your Plex Media Server using the URL http://plex.example.com.

in conclusion

Congratulations! You have successfully installed Plex Media Server on CentOS 8 using Nginx as a reverse proxy. You can now browse the Plex Media Server for more options and set up your own media library. You can then install the Plex app from your phone’s Play Store and access the media. You can also allow your friends and family to access your photos, music and movies from a web browser or Plex app. If you have any questions, feel free to ask me.

Sidebar