Newznab on Ubuntu 18.04

This guide will help you install everything you need to get Newznab+ running on a fresh Ubuntu 18.04 server. At the end are optional sections for installing elastic search and to configure scripts to allow newznab to continually run.

Step 1: Install required packages

Enter the following:

sudo -s
apt update && apt upgrade
apt install ssh screen apache2 php mariadb-server libapache2-mod-php -y
apt install php-pear php-gd php-mysql php-memcache php-curl php-json php-mbstring unrar lame mediainfo subversion ffmpeg memcached -y

Step 2: Configure maria-mysql

Enter the following:

mysql_secure_installation

Note

You will be asked to create a password for the DB server root user.

Create a mysql user for the application:

mysql -u root -p
<enter password>
CREATE USER 'newznab'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON newznab.* TO 'newznab'@'localhost' WITH GRANT OPTION;
exit

Edit the mysql configuration file as follows:

pico /etc/mysql/conf.d/mysql.cnf

Add a new section as follows:

[mysqld]
group_concat_max_len=8192
innodb_flush_log_at_trx_commit = 2

Step 3: Create web directories

Enter the following:

mkdir /var/www/newznab
mkdir /var/www/newznab/htdocs
mkdir /var/www/newznab/logs

Step 4: Create a script for keeping newznab up to date

Enter the following:

pico /var/www/newznab/svn.sh

Paste the following into the file, entering the username and password provided after purchasing newznab inplace of the asterix:

svn export --no-auth-cache --force --username **** --password **** svn://svn.newznab.com/nn/branches/nnplus /var/www/newznab/htdocs/

#rm /var/www/newznab/htdocs/*.txt
#rm -rf /var/www/newznab/htdocs/www/install
#rm -rf /var/www/newznab/htdocs/www/lib/smarty/templates_c/*

cd /var/www/newznab/htdocs/misc/update_scripts
php update_database_version.php
cd /var/www/newznab/htdocs

service memcached restart
service apache2 restart

Make the file executable and run it:

chmod +x /var/www/newznab/svn.sh
/var/www/newznab/svn.sh 2> /dev/null

Step 5: Setup website

Ensure web directories are writeable by the update scripts and installer:

chmod 777 /var/www/newznab/htdocs/www/lib/smarty/templates_c
chmod 777 /var/www/newznab/htdocs/www/covers/movies
chmod 777 /var/www/newznab/htdocs/www/covers/anime
chmod 777 /var/www/newznab/htdocs/www/covers/music
chmod 777 /var/www/newznab/htdocs/www/covers/tv
chmod 777 /var/www/newznab/htdocs/www
chmod 777 /var/www/newznab/htdocs/www/install
chmod 777 /var/www/newznab/htdocs/db/cache
chmod -R 777 /var/www/newznab/htdocs/nzbfiles/

Replace the default apache conf to point to newznab directory:

pico /etc/apache2/sites-available/000-default.conf

Remove everything from the file and replace with:

<VirtualHost *:80>
    <Directory /var/www/newznab/htdocs/www/>
        Options FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    DocumentRoot /var/www/newznab/htdocs/www
    ErrorLog /var/www/newznab/logs/error.log
    CustomLog /var/www/newznab/logs/access.log combined
</VirtualHost>

Note

A more practical alternative to this is to create a vhost specifically for the newznab installation.

Update a few defaults in the php.ini files:

pico /etc/php/7.2/apache2/php.ini

Find and edit the following settings:

date.timezone = 'Europe/London'
max_execution_time = 120
memory_limit = -1

Enable apache mod_rewrite and restart services:

a2enmod rewrite
service apache2 restart
service mysql restart

Step 6: Install newznab

Open a browser pointing to the IP address of the server and follow the instructions. Use the newznab mysql user created earlier to connect to the database. Follow the installation wizard to the end.

After completing the installation open the svn update script, uncomment the commented out lines and re-run it. This will remove any installation files and be the mechanism you use to update newznab to the latest version:

pico /var/www/newznab/svn.sh
<uncomment commented out lines prefixed with #>

Save, close and run the file:

/var/www/newznab/svn.sh

Step 7: Configure newznab

Open a browser, go to the admin home page http://<your server IP>/admin/site-edit.php and set up some paths and config options:

default home page : /browse
newznabID : <provided in signup email>
unrar path : /usr/bin/unrar
mediainfo path : /usr/bin/mediainfo
ffmpeg path : /usr/bin/ffmpeg
lame path : /usr/bin/lame
integrated cleanup : yes
save audio preview : yes
check for password : deep
delete passworded releases : yes

Activate one group to use as a test such as alt.binaries.teevee http://<your server IP>/admin/group-list.php:

Filter for the group and press go
Click the Activate link

Step 8: Run update scripts

A couple of scripts are used to populate newznab - update_binaries and update_releases. Now newznab is installed and configured it needs to be populated:

cd /var/www/newznab/htdocs/misc/update_scripts
php update_binaries.php
php update_releases.php

Complete

newznab is now installed. Navigate to the home page to observe indexed content

Optional Step 1: Configure newznab to run continually unattended inside screen

Take a copy of the run script so it can be edited locally without having your local changes overwritten later:

cd /var/www/newznab/htdocs/misc/update_scripts/nix_scripts
cp newznab_screen.sh newznab_local.sh
pico newznab_local.sh

Ensure the following variables are set appropriately. Use of the threaded run script is significantly faster:

export NEWZNAB_PATH="/var/www/newznab/htdocs/misc/update_scripts"
export NEWZNAB_SLEEP_TIME="30" # in seconds
/usr/bin/php ${NEWZNAB_PATH}/update_binaries_threaded.php

Make the script executable:

chmod +x /var/www/newznab/htdocs/misc/update_scripts/nix_scripts/newznab_local.sh

The run script is best ran in a screen, so you can reattach later and monitor it. Screen launches a new bash shell that you can later reattach to. Name the screen so you know which one to re-attach to:

screen -S newznab
cd /var/www/newznab/htdocs/misc/update_scripts/nix_scripts
./newznab_local.sh
ctrl-a d

Optional Step 2: Configure newznab to use elasticsearch

Open a browse to the admin site-edit page http://<your server IP>/admin/site-edit.php Set the following values:

use elasticsearch : yes

Open a shell and enter the following:

sudo -s
apt install apt-transport-https
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
add-apt-repository "deb https://artifacts.elastic.co/packages/7.x/apt stable main"
apt update
apt install openjdk-8-jdk
apt install elasticsearch
service elasticsearch start

Browsing to http://<your server IP>/admin/ and dismissing the welcome message should show:

Connected to elasticsearch version 7.x.x

You now need to populate the index with initial data. Each iteration of update_releases, new data will be added to the index automatically. Every 24 hours its a good idea to totally rebuild the index manually:

cd /var/www/newznab/htdocs/misc/elastic/
php eindex.php index

Navigating to http://<your server IP>/browse will now show data from elasticsearch. To optionally entirely rebuild the index every 24 hours open your newznab_local.sh created in Optional Step 1, and inside the section ‘if [ “$DIFF” -gt 43200 ] || [ “$DIFF” -lt 1 ]’ add a line to rebuild:

if [ "$DIFF" -gt 43200 ] || [ "$DIFF" -lt 1 ]
then
        ...
        ...
        /usr/bin/php ${NEWZNAB_PATH}/../elastic/eindex.php index