Rutorrent with lighttpd

From ArchWiki
Revision as of 23:02, 9 September 2012 by Dioltas (Talk | contribs)

Jump to: navigation, search


Rutorrent is a php frontend to the rtorrent bitorrent client.

It communicates with rtorrent using XML-RPC. It requires a web server such as lighttpd or apache to serve it's pages.

To set up rutorrent, we will need to have rtorrent and lighttpd set up.


rtorrent

Install rtorrent and configure to your liking.

   # pacman -S rtorrent

Information on configuring rtorrent can be found on it's wiki page: https://wiki.archlinux.org/index.php/Rtorrent.

rtorrent in the repos should be compiled with XML-RPC support.

Add the following line to your rtorrent config file, usually ~/.rtorrent.rc.

   scgi_port = localhost:5050

Instead of using a tcp port, it is also possible to use a socket using the scgi_local option instead. This did not work for me, as lighttpd complained about permissions regardless of permissions / location of socket file.

You can choose a port other than 5050 if you like.

lighttpd

Install lighthttp and php.

    # pacman -S lighttpd php

Information on setting up lighthttp can be found on it's wiki page: https://wiki.archlinux.org/index.php/Lighttpd

After starting lighthttp as per the wiki, you should be able to access the test page at http://localhost:80.

By default the pages are served from /srv/http, this is where we will be putting rutorrent.

lighttpd.conf

Edit lighthttpd's config file, /etc/lighttpd/lighttpd.conf.

The following lines tell lighttpd to load the fastcgi and simple-cgi modules. Fast cgi is needed for rutorrent itself, and scgi for rutorrent to communicate with rtorrent.

   server.modules += ( "mod_fastcgi" )
   server.modules += ( "mod_scgi" )

We need to tell lighttpd how to treat files like css, images (jpg etc.), js. Otherwise it will not know what to do with them, and you may get a dialog to download the file or rutorrent will just not work properly.

Here is a long list of filetypes, it is probably overkill as most of them are not needed, but easier to cover them all.

Add this to /etc/lighttpd/lighttpd.conf also.

   mimetype.assign             = (
     ".rpm"          =>      "application/x-rpm",
     ".pdf"          =>      "application/pdf",
     ".sig"          =>      "application/pgp-signature",
     ".spl"          =>      "application/futuresplash",
     ".class"        =>      "application/octet-stream",
     ".ps"           =>      "application/postscript",
     ".torrent"      =>      "application/x-bittorrent",
     ".dvi"          =>      "application/x-dvi",
     ".gz"           =>      "application/x-gzip",
     ".pac"          =>      "application/x-ns-proxy-autoconfig",
     ".swf"          =>      "application/x-shockwave-flash",
     ".tar.gz"       =>      "application/x-tgz",
     ".tgz"          =>      "application/x-tgz",
     ".tar"          =>      "application/x-tar",
     ".zip"          =>      "application/zip",
     ".mp3"          =>      "audio/mpeg",
     ".m3u"          =>      "audio/x-mpegurl",
     ".wma"          =>      "audio/x-ms-wma",
     ".wax"          =>      "audio/x-ms-wax",
     ".ogg"          =>      "application/ogg",
     ".wav"          =>      "audio/x-wav",
     ".gif"          =>      "image/gif",
     ".jar"          =>      "application/x-java-archive",
     ".jpg"          =>      "image/jpeg",
     ".jpeg"         =>      "image/jpeg",
     ".png"          =>      "image/png",
     ".xbm"          =>      "image/x-xbitmap",
     ".xpm"          =>      "image/x-xpixmap",
     ".xwd"          =>      "image/x-xwindowdump",
     ".css"          =>      "text/css",
     ".html"         =>      "text/html",
     ".htm"          =>      "text/html",
     ".js"           =>      "text/javascript",
     ".asc"          =>      "text/plain",
     ".c"            =>      "text/plain",
     ".cpp"          =>      "text/plain",
     ".log"          =>      "text/plain",
     ".conf"         =>      "text/plain",
     ".text"         =>      "text/plain",
     ".txt"          =>      "text/plain",
     ".dtd"          =>      "text/xml",
     ".xml"          =>      "text/xml",
     ".mpeg"         =>      "video/mpeg",
     ".mpg"          =>      "video/mpeg",
     ".mov"          =>      "video/quicktime",
     ".qt"           =>      "video/quicktime",
     ".avi"          =>      "video/x-msvideo",
     ".asf"          =>      "video/x-ms-asf",
     ".asx"          =>      "video/x-ms-asf",
     ".wmv"          =>      "video/x-ms-wmv",
     ".bz2"          =>      "application/x-bzip",
     ".tbz"          =>      "application/x-bzip-compressed-tar",
     ".tar.bz2"      =>      "application/x-bzip-compressed-tar",
     # default mime type
     ""              =>      "application/octet-stream",
    )  

Next we add the configuration for scgi to connect to rtorrent. Make sure to use the same port as when configuring rtorrent.

   scgi.server = (
       "/RPC2" =>
           ( "127.0.0.1" =>
               (
                   "host" => "127.0.0.1",
                   "port" => 5050,
                   "check-local" => "disable"
               )
           )
       )


And finally the fastcgi settings so lighthttpd knows how to deal with php.

   fastcgi.server = ( ".php" => ((
                        "bin-path" => "/usr/bin/php-cgi",
                        "socket" => "/tmp/php.socket"
                    )))


Test

At this point, you should be able to test if rtorrent and lighttpd's scgi are working properly using the xmlrpc command to ask rtorrent for a list of functions. ( See http://libtorrent.rakshasa.no/wiki/RTorrentXMLRPCGuide#Usage ).

   $ xmlrpc localhost system.listMethods

This should output a log list of methods that can be accessed through rtorrent's scgi interface. If it doesn't then something may be wrong.

php.ini

We need to make a small change to the open_basedir line in /etc/php/php.ini, to allow rutorrent to access the binaries it needs to run.

   open_basedir = /srv/http/:/home/:/tmp/:/usr/share/pear/:/usr/bin/

The binaries are stat, id, php, curl, gzip. If these are installed somewhere other than /usr/bin, then you may need to append that line also.


rutorrent

We will download rutorrent to lighttpd http directory.

   # cd /srv/http
   # wget http://rutorrent.googlecode.com/files/rutorrent-3.4.tar.gz
   # tar xvfx rutorrent-3.4.tar.gz
   # rm rutorrent-3.4.tar.gz

These should download and extract rutorrent to /srv/http. You may need to change rutorrent-3.4 to the desired version from the rutorrent website.

rutorrent's config files are in /srv/http/rutorrent/conf/.

We need to edit /srv/http/rutorrent/conf/config.php, and change the port to the one we used in rtorrent and lighttpd.

    $scgi_port = 5050;
    $scgi_host = "127.0.0.1";

Change the owner of the rutorrent to http (the user that lighttpd runs as by default).

   # chown -R http rutorrent


Testing

rutorrent should now be set up.

Start rtorrent, and restart lighttpd if you have not done so since changing the configuration.

You should now be able to access the rutorrent interface on localhost or 127.0.0.1 on port 80 (assuming you did not change the default port for lighttpd).

http://localhost

Troubleshooting

For problems with rutorrent or lighttpd, the best place to check first is probably the lighttpd log files, in /var/log/lighttpd/. Particularly error.log.

   $ tail /var/log/lighttpd/error.log