This article will describe installing PLEX which provides media server like youtube. Please see here for PLEX configuration.
Table of Contents
1 Install PLEX
Install PLEX rpm package for CentOS 7.
> PLEX=https://downloads.plex.tv/plex-media-server/0.9.16.3.1840-cece46d > wget -q ${PLEX}/plexmediaserver-0.9.16.3.1840-cece46d.x86_64.rpm > sudo zypper --no-gpg-checks -n in \ plexmediaserver-0.9.16.3.1840-cece46d.x86_64.rpm > sudo systemctl enable plexmediaserver > sudo systemctl start plexmediaserver > sudo systemctl start plexmediaserver
2 Open port
Open 32400/tcp.
> firewall_open_tcp() { for t in FW_SERVICES_EXT_TCP FW_SERVICES_DMZ_TCP FW_SERVICES_INT_TCP; do sudo sed -e "s/^${t}=\"\(.*\)\"/${t}=\"\1 $1\"/g" \ -i /etc/sysconfig/SuSEfirewall2 done sudo systemctl restart SuSEfirewall2 } > firewall_open_tcp 32400
3 Apache2 digest authentication (Optional)
Accessinig PLEX via Apache2 provides digest authentication for access control.
Install Apache2 and enable modules for rewriting URL.
> sudo zypper -n in apache2 > for mod in proxy proxy_http rewrite auth_digest; do sudo a2enmod ${mod} done
Add config file for PLEX.
> sudo su -c 'cat <<EOF > /etc/apache2/conf.d/plexmediaserver.conf ProxyPass / http://127.0.0.1:32400/ ProxyPassReverse / http://127.0.0.1:32400/ ProxyRequests Off ProxyPreserveHost On RewriteEngine on RewriteCond %{REQUEST_URI} !^/web RewriteCond %{HTTP:X-Plex-Device} ^$ RewriteRule ^/$ /web/$1 [R,L] <Proxy http://127.0.0.1:32400> AuthType Digest AuthName "plexmediaserver" AuthUserFile /etc/apache2/.plexmediaserver Require valid-user </Proxy> EOF '
Create digest authentication file for PLEX.
> sudo htdigest2 -c /etc/apache2/.plexmediaserver \ "plexmediaserver" user
Restart Apache2.
> sudo systemctl enable apache2 > sudo systemctl restart apache2
Open Apache2 port. Close 32400/tcp if it is opened.
> firewall_open_service() { for t in FW_CONFIGURATIONS_EXT FW_CONFIGURATIONS_DMZ FW_CONFIGURATIONS_INT; do sudo sed -e "s/^${t}=\"\(.*\)\"/${t}=\"\1 $1\"/g" \ -i /etc/sysconfig/SuSEfirewall2 done sudo systemctl restart SuSEfirewall2 } > firewall_open_service apache2
4 Script for installing PLEX
The following script will installing PLEX and Apache2.
#!/bin/sh # Password and username for digest authentication. DIGEST_PASSWD=plexmediaserver DIGEST_USER=user firewall_open_tcp() { for t in FW_SERVICES_EXT_TCP FW_SERVICES_DMZ_TCP FW_SERVICES_INT_TCP; do sudo sed -e "s/^${t}=\"\(.*\)\"/${t}=\"\1 $1\"/g" \ -i /etc/sysconfig/SuSEfirewall2 done sudo systemctl restart SuSEfirewall2 } firewall_open_service() { for t in FW_CONFIGURATIONS_EXT FW_CONFIGURATIONS_DMZ FW_CONFIGURATIONS_INT; do sudo sed -e "s/^${t}=\"\(.*\)\"/${t}=\"\1 $1\"/g" \ -i /etc/sysconfig/SuSEfirewall2 done sudo systemctl restart SuSEfirewall2 } # Install PLEX. PLEX=https://downloads.plex.tv/plex-media-server/0.9.16.3.1840-cece46d wget -q ${PLEX}/plexmediaserver-0.9.16.3.1840-cece46d.x86_64.rpm sudo zypper --no-gpg-checks -n in \ plexmediaserver-0.9.16.3.1840-cece46d.x86_64.rpm sudo systemctl enable plexmediaserver sudo systemctl start plexmediaserver # Comment out if you need. # firewall_open_tcp 32400 # Install apache2. sudo zypper -n in apache2 for mod in proxy proxy_http rewrite auth_digest; do sudo a2enmod ${mod} done sudo su -c 'cat <<EOF > /etc/apache2/conf.d/plexmediaserver.conf ProxyPass / http://127.0.0.1:32400/ ProxyPassReverse / http://127.0.0.1:32400/ ProxyRequests Off ProxyPreserveHost On RewriteEngine on RewriteCond %{REQUEST_URI} !^/web RewriteCond %{HTTP:X-Plex-Device} ^$ RewriteRule ^/$ /web/$1 [R,L] <Proxy http://127.0.0.1:32400> AuthType Digest AuthName "plexmediaserver" AuthUserFile /etc/apache2/.plexmediaserver Require valid-user </Proxy> EOF ' sudo zypper -n in expect expect -c " set timeout -1 spawn sudo htdigest2 -c /etc/apache2/.plexmediaserver \ \"plexmediaserver\" ${DIGEST_USER} expect \"New password: \" send \"${DIGEST_PASSWD}\n\" expect \"Re-type new password: \" send \"${DIGEST_PASSWD}\n\" expect eof " sudo systemctl enable apache2 sudo systemctl restart apache2 firewall_open_service apache2