You are here: Home / Debian GNU/Linux / Web applications / BitTorrent download / Install wTorrent BitTorrent client on Debian

Install wTorrent BitTorrent client on Debian

by Pierre-Yves Landuré last modified Apr 29, 2015 10:30

wTorrent is a Web frontend for the BitTorrent rTorrent client.

This howto is tested on :

  • Debian 6.0 Squeeze

This howto is tested with these versions of wTorrent :

  • Clone git du 25 Juin 2012.

Prerequisites

This howto needs :

This howto needs one of these tools, according to the installed HTTP server :

This howto recommends the installation of PeerGuardian Peer 2 Peer privacy protection on Debian.

Parameters

Provide the domain name where will be available the software :

DOMAIN="bt.example-domain.com"

Installation

Compute the installation path :

INSTALL_PATH="/opt/wtorrent/${DOMAIN}"

Make sure that the parent folder exists :

PARENT_PATH="$(command dirname "${INSTALL_PATH}")"
if [ ! -e "${PARENT_PATH}" ]; then
command mkdir --parent "${PARENT_PATH}"
fi

Environment preparation

Install the needed software :

command apt-get install php5-sqlite git \
apache2-utils apg

Adjust PHP configuration to the application needs :

command php-tools --for="wtorrent" --set "suhosin.get.max_value_length" 4000

Reload PHP configuration :

test -x /etc/init.d/php5-fpm && /etc/init.d/php5-fpm force-reload
test -x /etc/init.d/apache2 && /etc/init.d/apache2 force-reload
test -x /etc/init.d/lighttpd && /etc/init.d/lighttpd force-reload
test -x /etc/init.d/nginx && /etc/init.d/nginx force-reload

Mise en place de l'application

Download the application sources :

command git clone "https://github.com/wtorrent/wtorrent" "${INSTALL_PATH}"

Create the folders storing files created by the software :

command mkdir --parent "/var/lib/wtorrent/${DOMAIN}/data"
command mkdir --parent "/var/lib/wtorrent/${DOMAIN}/db"
command mv "${INSTALL_PATH}/wtorrent/tpl_c" "/var/lib/wtorrent/${DOMAIN}/tpl_c"
command mv "${INSTALL_PATH}/wtorrent/torrents" "/var/lib/wtorrent/${DOMAIN}/torrents"
command chown -R www-data:www-data "/var/lib/wtorrent/${DOMAIN}"

Create symbolic links to these folders :

command ln -s "/var/lib/wtorrent/${DOMAIN}/tpl_c" "${INSTALL_PATH}/wtorrent/tpl_c"
command ln -s "/var/lib/wtorrent/${DOMAIN}/torrents" "${INSTALL_PATH}/wtorrent/torrents"

Allow the HTTP server user to add files in the configuration folder :

command chown www-data:www-data "${INSTALL_PATH}/wtorrent/conf/"

Setup the software :

command sed -i -e "/\$defaults/,/\$user_options/s|^\(.*db_file.*=>\).*$|\1 '../../../../var/lib/wtorrent/${DOMAIN}/db/database.db',|" \
            -e "/\$defaults/,/\$user_options/s|^\(.*dir_torrents.*=>\).*$|\1 'torrents/',|" \
            -e "/\$defaults/,/\$user_options/s|^\(.*dir_exec.*=>\).*$|\1 '${INSTALL_PATH}/wtorrent/',|" \
            -e "/\$defaults/,/\$user_options/s|^\(.*dir_download.*=>\).*$|\1 '/var/lib/wtorrent/${DOMAIN}/data/',|" \
    "${INSTALL_PATH}/wtorrent/cls/install.cls.php"

Create the configuration file :

command cp "${INSTALL_PATH}/wtorrent/conf/sample.user.conf.php" "${INSTALL_PATH}/wtorrent/conf/user.conf.php"
command chown www-data:www-data "${INSTALL_PATH}/wtorrent/conf/user.conf.php"

Setup the HTTP server for the application :

if [ -x "/usr/bin/a2tools" ]; then
  command a2tools --overrides="All" "${DOMAIN}" "${INSTALL_PATH}/wtorrent/"
fi
if [ -x "/usr/bin/lighty-tools" ]; then
  command lighty-tools add-vhost "${DOMAIN}" "${INSTALL_PATH}/wtorrent/"
fi

SCGI server configuration

Create a random username and password for the SCGI server :

SCGI_LOGIN="$(command apg -q -a 0 -n 1 -M NCL)"
SCGI_PASSWORD="$(command apg -q -a 0 -n 1 -M NCL)"

Create the htpasswd file :

command htpasswd -cb "/var/lib/wtorrent/scgi.pwd" "${SCGI_LOGIN}" "${SCGI_PASSWORD}"

Update the application configuration with the login data :

command sed -i -e "/\$defaults/,/\$user_options/s|^\(.*rt_user.*=>\).*$|\1 '${SCGI_LOGIN}',|" \
            -e "/\$defaults/,/\$user_options/s|^\(.*rt_passwd.*=>\).*$|\1 '${SCGI_PASSWORD}',|" \
            -e "/\$defaults/,/\$user_options/s|^\(.*rt_auth.*=>\).*$|\1 true,|" \
    "${INSTALL_PATH}/wtorrent/cls/install.cls.php"

Setup the Apache 2 server to act as SCGI server for rTorrent, if present :

if [ -x "/usr/bin/a2tools" ]; then
command apt-get -y install libapache2-mod-scgi
command a2enmod scgi rewrite
if [ -z "$(command grep 'NameVirtualHost 127.0.0.1:80' /etc/apache2/ports.conf)" ]; then
command sed -i -e '/Listen[\t ]*80/i\
NameVirtualHost 127.0.0.1:80' '/etc/apache2/ports.conf'
fi
command echo "<VirtualHost 127.0.0.1:80>
ServerName localhost

<IfModule mod_scgi.c>
SCGIMount /RPC2 127.0.0.1:5000
</IfModule>

<Location /RPC2>
Order deny,allow
Allow from all

# We enable password authentication
AuthType Basic
AuthName \"rTorrent SCGI\"
AuthUserFile /var/lib/wtorrent/scgi.pwd
Require valid-user
</Location>

<Location />
Order deny,allow
Allow from all
</Location>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} "\!"^/RPC2
RewriteCond %{REQUEST_URI} "\!"^/server-status
RewriteCond %{REQUEST_URI} "\!"^/php-fpm-status
RewriteCond %{REQUEST_URI} "\!"^(/php5.fastcgi)?/apc-info
RewriteRule ^/(.*) http://${DOMAIN}/\$1 [R=301,L]
</IfModule>
</VirtualHost>" \
> '/etc/apache2/sites-available/http-localhost-rtorrent'
command a2ensite http-localhost-rtorrent
/etc/init.d/apache2 force-reload
fi

Setup the Lighttpd server to act as SCGI server for rTorrent, if present :

if [ -x "/usr/bin/lighty-tools" ]; then
command echo '# rTorrent SCGI configuration. server.modules += ( "mod_scgi", "mod_auth" ) scgi.server = ( "/RPC2" => # RT_DIR ( "127.0.0.1" => ( "host" => "127.0.0.1", # Ip where rtorrent is listening "port" => 5000, # Port specified in .rtorrent.rc "check-local" => "disable" ) ) ) auth.backend = "htpasswd" auth.backend.htpasswd.userfile = "/var/lib/wtorrent/scgi.pwd" auth.require = ( "/RPC2" => ( "method" => "basic", "realm" => "XML-RPC", "require" => "valid-user" ) ) ' > '/etc/lighttpd/conf-available/10-rtorrent.conf'
  command lighty-enable-mod rtorrent
/etc/init.d/lighttpd force-reload
fi

wTorrent initialization

BEFORE EVERY THING ELSE, run the wTorrent install to create the administration account. Use the URL displayed by :

command echo "http://${DOMAIN}/install.php"

Ignore the configuration test. It does not work (it says that it is impossible to create the database).

Once the configuration done, delete the installation file and protect the configuration :

command rm "${INSTALL_PATH}/wtorrent/install.php"
command chown -R root:root "${INSTALL_PATH}/wtorrent/conf/"

wTorrent is now available ton the choosen domain.

Automatic upgrade

Install a daily upgrade script for the software :

echo "#"'!'"/bin/bash
# Update ${PROTOCOL}://${DOMAIN}/ source code from Git.
test -x '/usr/bin/git' -a -d '${INSTALL_PATH}' && {
pushd '${INSTALL_PATH}' > '/dev/null'
/usr/bin/git pull --quiet > '/dev/null'
popd > '/dev/null'
}" \
  > "/etc/cron.daily/${DOMAIN}-update"
command chmod +x "/etc/cron.daily/${DOMAIN}-update"

Backup

Backup the installation with Backup Manager (see Install and setup Backup Manager on Debian) :

command backup-manager-tools add "${INSTALL_PATH}"
command backup-manager-tools add "/var/lib/wtorrent"

Solving problems

If the installation process says that the database is already created, run this command and re-run the installation :

command rm "/var/lib/wtorrent/${DOMAIN}/db/database.db"

If the rTorrent daemon does not start, try to remove the lock file :

command rm '/var/lib/rtorrent/sessions/rtorrent.lock'

Thanks