Install rTorrent & ruTorrent with nginx on Debian 8

Get some drink of choice and some snacks. This will take a while. We’ll be taking a minimal Debian 8 system and set up a seedbox all from scratch, using rTorrent/libTorrent, ruTorrent and Nginx.

Install dependencies

without some packages we can’t start here….

apt-get update
apt-get upgrade

apt-get install nginx php5-fpm apache2-utils subversion git screen build-essential automake libtool libcppunit-dev libcurl3-dev libsigc++-2.0-dev libcppunit-dev unzip unrar curl libncurses-dev  libfuse-dev libcurl4-openssl-dev libxml++2.6-dev libssl-dev php5-cli mediainfo

Create User

We need a user to run rTorrent. You can name it whatever you want, but if you chose something different, remember to adjust the configs in the rest of this article.

useradd rutorrent
usermod -a -G rutorrent www-data
usermod -a -G www-data rutorrent

 

Install XMLRPC-C

These is needed for the communication between nginx and rTorrent.

svn checkout https://svn.code.sf.net/p/xmlrpc-c/code/stable/ xmlrpc-c
cd xmlrpc-c
./configure --disable-cplusplus
make
make install

 

Install libtorrent

git clone https://github.com/rakshasa/libtorrent.git
cd libtorrent
./autogen.sh
./configure --disable-instrumentation
make
make install

 

Install rTorrent

Clone and compile. We need to make sure we configure –with-xmlrpc-c.

git clone https://github.com/rakshasa/rtorrent.git
cd rtorrent
./autogen.sh
./configure --with-xmlrpc-c
make
make install
ldconfig

 

Install and configure ruTorrent

This one is easy. We just need to clone the git repo into /var/www

mkdir -p /var/www
cd /var/www
git clone https://github.com/Novik/ruTorrent.git

now edit the conf/config.php

$topDirectory = "/home/rutorrent"
$scgi_port = 5000;
$scgi_host = "127.0.0.1"


$pathToExternals = array(
                "php"   => '',                  // Something like /usr/bin/php. If empty, will be found in PATH.
                "curl"  => '/usr/bin/curl',     // Something like /usr/bin/curl. If empty, will be found in PATH.
                "gzip"  => '',                  // Something like /usr/bin/gzip. If empty, will be found in PATH.
                "id"    => '',                  // Something like /usr/bin/id. If empty, will be found in PATH.
                "stat"  => '/usr/bin/stat',     // Something like /usr/bin/stat. If empty, will be found in PATH.
        );

the curl and the stat settings are need to set otherwise RSS wouldn’t work.

 

Configure Nginx

now we create a Site configuration for ruTorrent.
just create and edit this file: /etc/nginx/sites-enabled/rutorrent

server {
  listen 80;
  server_name localhost;

  root /var/www/ruTorrent;
  index index.html index.htm index.php;

  auth_basic "Restricted";
  auth_basic_user_file /etc/nginx/.htpasswd;

  location / {
    try_files $uri $uri/ =404;
  }

  location /RPC2 {
    include /etc/nginx/scgi_params;
    scgi_pass 127.0.0.1:5000;
  }

  location ~ .php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
  }
}

We also want it password-protected or you want the world to see all your “linux iso’s”?

htpasswd -c /etc/nginx/.htpasswd rutorrent

now delete the default settings and restart nginx and php5-fpm

rm -f /etc/nginx/sites-enabled/default
service nginx restart && service php5-fpm restart

 

Configure rTorrent

now we need to configure rTorrent here is a sample ~/.rtorrent.rc you can modify it but don’t delete the SCGI Socket line.

# ----------------------------------------------------------------------
# BitTorrent
# ----------------------------------------------------------------------

throttle.global_down.max_rate.set = 0
throttle.global_up.max_rate.set   = 0
throttle.max_peers.normal.set     = 200
throttle.max_peers.seed.set       = -1
throttle.max_uploads.global.set   = 200
throttle.min_peers.normal.set     = 1
throttle.min_peers.seed.set       = -1

# ----------------------------------------------------------------------
# Directories
# ----------------------------------------------------------------------

directory                        = /home/rutorrent/
session                          = /home/rutorrent/.session
#schedule                        = watch_directory,5,5,load_start=/root/rtorrent/watch/*.torrent
encoding.add                     = UTF-8

# ----------------------------------------------------------------------
# Network
# ----------------------------------------------------------------------

network.port_range.set           = 10001-11000
network.scgi.open_port           = 127.0.0.1:5000
network.port_random.set          = yes
network.tos.set                  = throughput
protocol.pex.set                 = no
trackers.use_udp.set             = yes

encryption                       = allow_incoming,try_outgoing,enable_retry

# ----------------------------------------------------------------------
# Hash
# ----------------------------------------------------------------------

pieces.hash.on_completion.set    = no
check_hash                       = no

After that we need to create the .session directory.

mkdir -p /home/rutorrent/.session

 

Configure rTorrent autostart

Many people will tell you to write an init script for this, but IMHO that’s overkill. I prefer to use /etc/rc.local

start-stop-daemon --start --chuid rutorrent --name rtorrent --exec /usr/bin/screen -- -fa -d -m /usr/local/bin/rtorrent

 

NOTE: In this setup is no ffmpeg installed so ruTorrent always complaining about it i don’t need it if you want it you can install it with the DebianMultimedia Repo.