Skip to content

Install In linux (arch apache)

Chemi edited this page Apr 22, 2022 · 4 revisions

phpmediaserver install on linux (arch)

Full example install on arch linux in default folders:

Apache Conf Folder:

/etc/httpd

HTTP Folder for phpmediaserver:

/srv/httpd/ms

PHP conf folder:

/etc/php

Downloads folder (where videos are downloaded by yours apps, needed access from http user)

/Downloads

Your external domain (is a example)

https://mydomain.mooo.com

Your internal server lan IP (is a example)

192.168.1.100

Install needed

pacman -S ffmpeg

Install Recommended (at least one of them needed to detect video files info)

pymediaident (recommended)

Install needed by pymediaident

pacman -S python python-pip 
yay/yaourt/pacaur -S ddgr ducker
pip install googler IMDBpy python_filmaffinity omdb tvdb_api

Then install pymediaident

wget https://raw.githubusercontent.com/EsTass/pymediaident/master/pymediaident.py
chmod +x pymediaident
cp ./pymediaident.py /usr/bin

Test all ok:

pymediaident.py -h

filebot

Using aur helpers install it:

yay -S filebot
yaourt -S filebot
pacaur -S filebot

omdbapi and thetvdb

For both is needed and api key and can be added in config.php

$G_SCRAPPERS_KEY = array( 
        'omdb' => 'APIKEY',
        'thetvdb' => 'APIKEY',
    );

Download and copy class file (imdb.class.php) to core/ folder.


Download last master

Download last version on ~/Downloads/phpmediaserver

cd ~/Downloads
git clone https://github.com/EsTass/phpmediaserver.git

Install needed APACHE+PHP

Install apache, php

pacman -Syu
pacman -S apache php php-apache php-sqlite 

Configure APACHE

Add new vhost file and load in apache conf

nano /etc/httpd/conf/extra/phpmediaserver.conf

And paste (remember comment http redirect if not configured ssl certs or apache redirect to http to https):

<Directory /srv/httpd/ms>
    Options FollowSymlinks
    AllowOverride all
    Require all granted
    #Edit Paths
    php_admin_value open_basedir "/srv/httpd/ms:/Downloads"
    #block all except my IP
    #Order deny,allow
    #Deny from all
    #Allow from MYIP
    #all
    Allow from all
    DirectoryIndex index.php
</Directory>

NameVirtualHost *:80
<VirtualHost *:80>
   ServerName mydomain.mooo.com
   #Redirect to http to https, uncomment if https configured
   #Redirect permanent /ms https://mydomain.mooo.com/ms
   ServerAdmin [email protected]
   DocumentRoot /srv/httpd/ms
   ErrorLog /var/log/httpd/errors-phpmediaserver.log
   CustomLog /var/log/httpd/access-phpmediaserver.log common
</VirtualHost>
<VirtualHost *:443>
   ServerName mydomain.mooo.com
   ServerAdmin [email protected]
   DocumentRoot /srv/httpd/ms
   ErrorLog /var/log/httpd/errors-phpmediaserver.log
   CustomLog /var/log/httpd/access-phpmediaserver.log common
   <IfModule mod_headers.c>
      Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
   </IfModule>

</VirtualHost>

Now include our conf file to apache config

nano /etc/httpd/conf/httpd.conf

And add to the end our new config and video headers mime (sometimes needed)

#phpmediaserver
Include conf/extra/phpmediaserver.conf
AddType application/x-mpegURL .m3u8
AddType video/MP2T .ts

Access to apache to downloads folder

Only if needed:

chgrp http -R /Downloads
chmod 0770 -R /Downloads

PHP Config

Edit php.ini and add downloads folder (only if outside of apache server, better security if outside because cant be direct access from urls):

edit /etc/php/php.ini

And change this:

open_basedir = /srv/http/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/:

To this (added to the end our downloads folder):

open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/share/webapps/:/etc/webapps/:/Downloads:

Now uncomment needed extras (remove ; at the start):

extension=curl.so
extension=iconv.so
extension=pdo_sqlite.so
extension=sqlite3.so
extension=sockets.so
extension=xmlrpc.so
extension=zip.so
#for dlna server
extension=soap.so

With this apache and php are now configured.


Copy phpmediaserver to web folder

Copy needed folders and set apache user

mkdir /srv/httpd/ms
cp -r ~/Downloads/phpmediaserver /srv/httpd/ms
chown -R http:http /srv/httpd/ms

Config phpmediaserver

Now edit and config basics to phpmediaserver

nano /srv/httpd/ms/config.php

Config Changes

  • If want to always use HTTPS (forced HTTPS, if FALSE its autodetected):
//Force HTTPS connection
define( 'O_FORCE_HTTPS', FALSE );	
  • Languaje (def: english, es: spanish, help needed for more languajes, located in lang/LANGCODE.php):
//LANGUAJE
define( 'O_LANG', 'def' );	
  • Autoselect your languaje on audio tracks, for this need a list of words that can be detected on audiotrackname. If empty always select first audio track (example for eng-us):
//LANGUAJE AUDIO TRACK select channel on play
define( 'O_LANG_AUDIO_TRACK', array( 'english', 'eng', 'us' ) );	
  • IP Countrys allowed, if empty or FALSE all allowed (example for only spain IPs)(by default 192.168.*.* and 10.0.*.* lans are outside BAN system):
//Countrys allowed (http://www.geoplugin.net)
define( 'O_COUNTRYALLOWED', array( 'Spain' ) );
  • Genres on menu/filters and his generic translation to eng (if movie info detected in eng are added to filter results), Spanish example:
//Menu Genres: search title in lang => generic genre in eng (for generic scrapp data)
define( 'O_MENU_GENRES', 
        array( 
            'Comedia' => 'Comedy',
            'Acción' => 'Action',
            'Ciencia Ficción' => 'Fiction',
            'Misterio' => 'Mistery',
            'Terror' => 'Horror',
            'Familia' => 'Family',
            'Historia' => 'Hist',
            'Documental' => 'Docu',
            'Animación' => 'Anima',
            'TV' => 'TV',
        )
    );
  • Video Quality Configuration for SD and HD (for ffmpeg params, beware with formats):

	//MIN BITRATE SD
	define( 'O_VIDEO_SD_MINBRATE', '500k' );
	//MAX BITRATE SD
	define( 'O_VIDEO_SD_MAXBRATE', '1M' );
	//HEIGHT SD
	define( 'O_VIDEO_SD_HEIGHT', '480' );
	
	//MIN BITRATE HD
	define( 'O_VIDEO_HD_MINBRATE', '1M' );
	//MAX BITRATE HD
	define( 'O_VIDEO_HD_MAXBRATE', '2M' );
	//HEIGHT HD
	define( 'O_VIDEO_HD_HEIGHT', '720' );
  • Hardware transcoding support to all users or only admins

	
	//ADD AMDGPU HARDWARE ENCONDING
        //TESTED ON LINUX
	define( 'O_VIDEO_AMDGPU_ENCODE', FALSE );
	define( 'O_VIDEO_AMDGPU_ENCODE_ADMIN', FALSE );

	//ADD NVIDIA HARDWARE ENCONDING
        //TESTED ON LINUX
	define( 'O_VIDEO_NVIDIA_ENCODE', FALSE );
	define( 'O_VIDEO_NVIDIA_ENCODE_ADMIN', FALSE );

  • Config video file identfiers (what you have selected in Recomended or all). O_SCRAP_CRON is the scrapper used in cron autoidentify system, for now only pymi and filebot can be selected (more incoming)
	//function.[scrapper].php to include
	define( 'O_SCRAPPERS_INCLUDES', array( 'pymi', 'filebot', 'omdb', 'thetvdb' ) );
	//Scrapper List ( title => array( function_search, function_add ) ) filled in each scrapper
	$G_SCRAPPERS = array();
	//SCRAPPERS API KEY ( title => function )
	$G_SCRAPPERS_KEY = array( 
        'omdb' => 'APIKEY',
        'thetvdb' => 'APIKEY',
    );
	//SCRAPPER FOR CRON FILE SCRAPPER pymediaident recomended
	define( 'O_SCRAP_CRON', 'pymi' );
  • Folders for downloads and excluded folders inside downloads folder (where to search for new videos)(DS if the directory separator, for config with linux and windows):
//Downloads Folder
define( 'PPATH_DOWNLOADS', '/Downloads' );
//Exclude folder in downloads
define( 'O_DOWNLOADS_FOLDERS_EXCLUDE', array(
       '/Downloads/old',
       '/Downloads/.temp',
       '/Downloads/adds',
      )
);
  • Cron config (disable for testing, when all configured can reenable it):
define( 'O_CRON', FALSE );
  • Cron CMD, this cmd run wget url to force reload of cron actions without user interaction, adapt to your system:
//CRON job: web petition to login shortcron + 10 secs
define( 'O_CRON_JOB', 'sleep ' . ( ( O_CRON_SHORT_TIME * 60 ) + 10 ) . ' && wget --no-check-certificate -O - http://127.0.0.1/ms/?cronlaunch=1' );
  • Set time zone and local (spanish example):
//TIMEZONE
@date_default_timezone_set( 'Europe/Madrid' );
@setlocale( LC_ALL, 'es_ES.utf8' );
//setlocale( LC_ALL, 'en_US.utf8' );
  • Basic strings for clean filenames (sometimes files have a lot of garbage added to filetitle, this strings are removed in filename before file ident):
//CLEAN DOWNLOADED FILENAMES
$G_CLEAN_FILENAME = array(
        //Languaje
        'English',
        'Spanish',
        'Latino',
        //Video Format
        'x264',
        'x265',
        'aac',
        'ac3',
        'divx',
        //...
    );

There are a lot of more configs but this are the basic for start the server.


Start Apache and access

systemctl restart httpd
systemctl status httpd

Check for errors in status.


Check Access to server

Open your web browser from LAN or External with domain.

IMPORTANT: if show error 404 in text mode its because your IP is banned. Need to remove from bans table and added to whitelist table, and check your country is added to O_COUNTRYALLOWED config var (only if using domain). For table actions its recommended https://www.phpliteadmin.org/ to access database. IPs from 192.168.*.* and 10.0.*.* are excluded for ban system.

firefox "https://mydomain.mooo.com/ms"

or

firefox "https://192.168.1.100/ms"

and login with default user/pass:

user: admin
pass: admin01020304

** REMEMBER CHANGE PASSWORD FOR ADMIN USER IN MENU->USERS **


START ADDING FILES AND CRON

If all are ok now you have a empty list (no files detected) and its time to reenable cron to detect files, go to MENU->CONFIG and change:

define( 'O_CRON', TRUE );

If downloads folder is very populated need to wait but first cron action is launched (2 * O_CRON_SHORT_TIME) by default 2 * 1 hours after first access by default (if O_CRON_JOB is well configured).

Cron start can be forced by URL:

https://mydomain.mooo.com/ms/?cronlaunch=1

or

https://192.168.1.100/ms/?cronlaunch=1

Then you can check if cron started in MENU->CRON, check for errors in configs params and show detected titles. Sometimes titles are bad detected and need to be manual detected in MENU->IDENTIFY (not detected (IDMEDIAINFO=-1) or waiting for cron to detect (IDMEDIAINFO=0)).

After first cron launch cant be forced relaunch after 1 hour (O_CRON_SHORT_TIME), to force its needed to delete entrys in logs table with action=cron_hour (short cron) and action=cron (long cron).

Short cron detect new files, clean deleted files and identify new files. Long cron download missing posters, check duplicates and clean, extract compressed files and find new downloads (if webscrapp system is configured).


Basic Admin Actions

  • Create/delete/update users: MENU->USERS
  • Check actions user logs: MENU->LOGS
  • Check cron logs: MENU->CRON
  • Change config options: MENU->CONFIG
  • Change bad identified video files: MENU->LOGMEDIA
  • Identify file: MENU->IDENTIFY