How to install multiple users on FreeBSD

simur612

Member
May 25, 2018
879
0
16
This guide is going to be mainly for FreeBSD but i'm sure a lot of the info will work on other systems.


This Also works from inside a FreeBSD jail.

First, install rtorrent-devel. You can use rtorrent but i find rtorrent-devel to have more features and some of the plugins do not work without it.

Code:
cd /usr/ports/net-p2p/rtorrent-devel
make install clean
the default setting for rtorrent-devel is required (compile with xmlrpc)

This will install all the requirements for rtorrent. Use the default settings for all of these. It's possible to install libtorrent without kqueue support but i don't recommend it because kqueue is much faster and runs with much lower load.

Next, we need to install a webserver. I personally use cherokee, but i'll use apache for this guide seeing as that is the easiest to get up and running. I'll post a guide for installing cherokee in a later guide.

Code:
cd /usr/ports/www/apache22
make install clean
The default settings are fine here but if you're on a multi-core system you may want to enable threads

next, we need to install mod_scgi now, you can skip this step if you would rather use the rpc plugin but honestly, it's a very easy install and will result in lower system load.

Code
cd /usr/ports/www/mod_scgi
make install clean
next, we need to install php. The only thing we need to do to the default settings is enable the apache module.
Code:
cd /usr/ports/lang/php5
make install clean
when php is done installing lets install the php extensions. Now, i'm not 100% sure on which extensions are needed and which aren't but i DO know that rutorrent works with these settings, so we'll just use them
so
Code:
cd /usr/ports/lang/php5-extensions
make install cleanmake sure the following are checked off:
CTYPE, CURL, DOM, FILTER, HASH, ICONV, JSON, MBSTRING, MBCRYPT, MHASH, PCRE, PDO, PDO_SQLITE, POSIX, SESSION, SIMPLEXML, SOCKETS, SPL, SQLITE, TOLKENIZER, XML, XMLREADER, XMLRPC, XMLWRITER

Like i said, many are default, some probably are NOT needed, but this is what i use and i know it works.

Anything else that pops up, just select the default.

when this is done, let's set a php.ini file
Code:
cp /usr/local/etc/php.ini-recommended /usr/local/etc/php.ini
and lets enable php and mod_scgi in the apache config. Your choice of editor may vary, i use vi but you can use anything you like. ee is probably a good choice for people who haven't mastered vi, as it's already installed by default, but if you are used to soemthing like nano, it's available in ports/editors/

anyways, the apache config file is located in /usr/local/etc/apache22/
Code:
vi /usr/local/etc/apache22/httpd.conf
find the module section (theres a lot of them) and add the following 2 lines:
Code:
LoadModule scgi_module libexec/apache22/mod_scgi.so
LoadModule php5_module libexec/apache22/libphp5.so

look for the mime-module section and add this:
Code: [
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Save the apache config and add add this line to your /etc/rc.conf
Code:
apache22_enable="YES"
apache SHOULD start now, if you're running in a jail, and it DOESNT start, this is likely due to a host name issue. Check /var/log/httpd-error.log
in any case, the way to fix these types of issues is to add a line to /etc/hosts with your hostname.

forinstance..if the output of hostname is wwwjail add the following line to /etc/hosts
Code:
127.0.0.1 wwwjailto start apache type
Code: ]
/usr/local/etc/rc.d/apache22 start
to test if php is working, let's make a file called test.php
Code:
echo '<?php phpinfo(); ?>' > /usr/local/www/apache22/data/test.phpnow, visit this page with your webbrowser at http://YOURSITE/test.php
substitute YOURSITE with the ip of your host or it's dns name. If all went as planned you should see a web page showing all the info about your php install...if you just see text or your browser tries to download a file then something went wrong.

hopefully, we have a working php installed web server at this point. Next, we'll need to install the rutorrent files. Theres 2 ways to do this. One, is to download the tar.gz files from the site, the other, is to use subversion. Personally, i like using the subversion method. this version is much newer (normally) and has cooler features. So, we'll use this. In order to do this, we need to install subversion, so let's do this now.

Code:
cd /usr/ports/devel/subversion
make install cleanthe defaults are fine here.

Now, we intend to install multiple users, so lets make a dir for our rutorrent users
Code: [
mkdir -p /usr/local/www/rutorrent-users
cd /usr/local/www/rutorrent-users
one thing i should mention, when you install new programs in freebsd (like subversion) the system doesn't seem to know they are there until you log back in, so log out and log back in root, or use the full path /usr/local/bin/svn for the next step or, use rehash

Code:
svn co http://rutorrent.googlecode.com/svn/trunk/rtorrent USERNAME
this should download the rutorrent files. Do this for each user you want.
if you want the plugins, i find it easier to download all of them and remove the ones i DONT want. The only problem with this method is that each time you update rutorrent, you'll have to remove these plugins...anyways, i still find it easier. to do this, go into your rutorrent user directory and type this:
Code:
rm -r plugins
svn co http://rutorrent.googlecode.com/svn/trunk/plugins
cd plugins
then remove the ones you don't need, for me, this tends to be rpc and darkpal (and right now chunks because it's broken)
Code:
rm -r rpc/ darkpal/ chunks/
You will also need to change a few dir's to 777 in order for rutorrent to work properly. you can do that with this one line command. First, go back to the rutorrent directory (/usr/local/www/rutorrent-users/USER/ then type
Code:
chmod 777 settings/ torrents/ plugins/trafic/stats/ plugin/trafic/stats/trackers/ plugins/rss/cache/and you will need to edit config.php and rs.js for each user.

Each user needs a unix account and an scgi mount. To make things easier to remember, i tend to make them similar. so, i'll make the scgi mount RPC1 and the port 5001 then for the next user, RPC2 and 5002, then for the next user RPC3 and 5003. The point is, it can be anything so long as it is different for each user. You'll need to edit config.php for the port and rs.js for the SCGI mount This will also be used in the users .rtorrent.rc later, and will also need to be added to the apache config, so having a system helps. anyways, let's add our unix users now.

the most simple way, is to use the adduser command and fill it out all the way. so just do that for each user.

We will also need to install "screen", so let's do that now
Code:
cd /usr/ports/sysutils/screendefaults are fine here as well
now, for each user, you'll need a download dir. I like to make them in the user's home dir like this
Code:
cd /home/USER
mkdir -p rtorrent/download
mkdir -p rtorrent/.session
chown -R USER:USER rtorrent/sub USER with the user or UID
you may have to do something different, what is important is that it is reflected correctly in the .rtorrent.rc you CAN use relative paths in rtorrent.rc so if you DO need to use another location for the downloads, it's probably not a bad idea to use a symbolic link in the home directory of the user pointing to the real location.
next, we need a .rtorrent.rc file. Luckily, there is a default file we can use.
Code:
cp /usr/local/share/example/rtorrent-devel/rtorrent.rc /home/USER/.rtorrent.rc
chmod 644 /home/USER/.rtorrent.rcthis file will need to be editted in order to work properly. First, find the directory = section and change it to
Code:
directory = ~/rtorrent/download/and change the session dir to
Code:
session = ~/rtorrent/.session/change the following lines to look like this:
Code:
hash_read_ahead = 10
hash_interval = 10
hash_max_tries = 5

at the very end of the file, add these lines:
Code:
port_range = 10001-10001
dht_port = 25001
scgi_port = 127.0.0.1:5001
copy this file to each user's home directory, then edit the last 3 lines changing each port up by one number like so:
Code:
port_range = 10002-10002
dht_port = 25002
scgi_port = 127.0.0.1:5002

now, rtorrent SHOULD start. log in with a user and test it. type screen rtorrent
you should see something like this:
Code:
( 2:11:07) Using 'kqueue' based polling.
( 2:11:07) XMLRPC initialized with 517 functions.
if so, we're almost there.
next, let's make an alias file for each user for apache to load. This way it's easier to remove users later and we're not always editing the apache config.
but first, we'll probably want to have some kind of authentication for our users...the easiest method is to use basic authentication. luckily apache comes with just what we need for this.
Code:
mkdir -p /usr/local/www/private/
htpasswd -c /usr/local/www/private/.htpasswd USERNAME
enter your user's password, now for each aditional user, do the same thing except without -c
Code:
htpasswd /usr/local/www/private/.htpasswd USERNAME2now, you will likely want access to your users rutorrent, so we'll use htgroups for that. This is simple, just create a file called .htgroups with the following info. We will name a group after the user who's rutorrent we're trying to have authentication on, and we will add ourselves, and that user to the group. If it were me, and my user's name was Jeff it would look like this:
Code:
vi /usr/local/www/private/.htgroups
jeff: jeff wonslungnow, let's create alias files for each user letting apache know where our rutorrent files are.
Code:
vi /usr/local/etc/apache22/Includes/USER.confsubstitue the actual username for USER
put the following infomation in the file
Code:
Alias /USER /usr/local/www/rtorrent-users/USER/
<Directory /usr/local/www/rtorrent-users/USER>
Options Indexes FollowSymLinks
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>

SCGIMount /RPC1 127.0.0.1:5001
<Location /RPC1>
AuthName "Private"
AuthType Basic
AuthBasicProvider file
AuthUserFile /usr/local/www/private/.htpasswd
AuthGroupFile /usr/local/www/private/.htgroups
Require group USER
</Location>
you will need to sub USER for the USERNAME that you've been using so far, also, for each user you'll need to change the port to match the one you used in the .rtorrent.rc
restart apache
Code
/usr/local/etc/rc.d/apache22 restart
now double check the rutorrent settings in /usr/local/www/rutorrent-users/USER/config.php and /usr/local/www/rutorrent-users/USER/rs.js and make sure they match the settings we've set (the port should match the one we've set in .rtorrent.rc and the RPC mount should match the one we've set in the INCLUDE in /usr/local/etc/apache22/Includes/USER.conf

if everything was done correctly, when you visit http://YOURSITE/USER you'll see a working rutorrent. If you have any issues, post them here.

I might have made a mistake or two, because i'm doing this from memory, if you have problems i'll address them, and later i'll double check this for accuracy. I'm mainly doing this now because we need to get this forum going
 

randac56

Member
May 25, 2018
915
0
16
Wow, thanks for posting this nice toturial

I have some questions :

When I start manually rtorrent using scgi_port instead of scgi_local and I start manually rtorrent to see my config, I get the message
Quote
The SCGI socket is bound to a specific network device yet may still pose a security risk, consider using 'scgi_local'.​

What would be the way to setup an install with scgi_local and update the httpd.conf file accordingly (SCGIMount /RPC1 127.0.0.1:5001) ?

EDIT: just read this one http://forums.rutorrent.org/index.php?topic=11.msg25#msg25
Im going to try this right away


Another thing, the rutorrent interface as a (very) nice rss downloader. When I use it, the browse button gets us to the web installation directory. See from the next pic, 'settings' and 'torrents' are folder inside the rutorrent web installation.


Same when creating a favorite from the rss feeds:



Would it be a way to let the user choose a directory from the directory variable from the .rtorrent.rc file instead (kind of jail inside the user's directory) ?

Thanks mate, your help is very much appreciated
 

peshua19

Member
May 25, 2018
897
0
16
yah, you can manually type in your download directory, but what might be easier is putting a symbolic link for your download directory in the directory it defaults to.


for example, if your download directory is /home/wonslung/rtorrent/downloads/

and the default directory that it goes to is /usr/local/www/rtorrent/

then do this:
Code:
cd /usr/local/www/rtorrent
ln -s /home/wonslung/rtorrent/download download
this will put a link to the download directory there so you can easily browser to it.
 

saroos1

Member
May 25, 2018
718
0
16
Excellent guide and I am really impressed with rutorrent - tried a webgui for rtorrent few years ago and didn't like it.
Just want to request a small typo correction - I think ;-)

The apache alias config file here: /usr/local/etc/apache22/Includes/USER.conf

is actually pointing to rtorrent-users, which should be rutorrent-users, else apache displays a forbidden page.

Quote
Alias /USER /usr/local/www/rtorrent-users/USER​


Thanks and keep up the good work :)
 

simur612

Member
May 25, 2018
879
0
16
Having trouble following this guide in a FreeBSD jail. A LOT has changed since its writing.

To even get these ports to install, I had to update quite a bit, otherwise most would just plain fail outright.

Code:
portsnap fetch
portsnap extract
pkg update
pkg upgrade
cd /usr/ports/ports-mgmt/portmaster
make install clean
echo 'WITH_PKGNG=yes' >> /etc/make.conf
pkg2ng
portmaster -avB
<accept defaults>

At this point, at least I could install a few ports.

Code:
cd /usr/ports/net-p2p/rtorrent-devel
make install clean

This would fail. rtorrent-devel would try to install depend libtorrent-devel-0.13.3.2, which would then fail with "Unknown autotool: libtool." Installing libtool from ports or pkg doesn't help and I could find no way around this, so I pressed forward with...

Code:
cd /usr/ports/net-p2p/rtorrent
make install clean
<accept defaults>

cd /usr/ports/www/apache22
make install clean
<accept defaults>

cd /usr/ports/www/mod_scgi
make install clean
<accept defaults>

cd /usr/ports/lang/php5
make config
<look for Apache module... isn't listed... screw it, proceed anyway>


Then I'd make the edits in the OP to /usr/local/etc/apache22/httpd.conf and start the apache22 service.

Code:
httpd: Syntax error on line 108 of /usr/local/etc/apache22/httpd.conf: Cannot load /usr/local/libexec/apache22/libphp5.so into server: Cannot open "/usr/local/libexec/apache22/libphp5.so"
/usr/local/etc/rc.d/apache22: WARNING: failed to start apache22

No dice. Not having the Apache module screws me.

Tried php56; no Apache module.
Tried php55; no Apache module.
Tried php53; has an Apache module! Woohoo!

Except php53 requires apache24 instead of the apache22 I just installed. Remove php5, install php53, confirm the edits to httpd.conf.

Followed the rest of the guide. apache22 will start. rtorrent will start and I've got it running in screen. But I can't get a connection between rtorrent and rutorrent. And I've re-ran the latter half of this guide at least 6x to confirm everything is good, including making the edit phisean pointed out.

This is what I get:


Any advice? :\ This is the only thing holding me back from migrating all of my hardware and storage onto FreeNAS.