This tutorial, described how to set up a torrent server on the FreeBSD operating system. The torrent server is based on rtorrent net-p2p/rtorrent. The GUI is ruTorrent. GUI is written in php. The server with php was lighttpd. www/lighttpd.
Start by installing the server.
Then edit the configuration file.
Change the port to 8080 from 80
Disable ipv6.
Change the directory of the website to the directory where ruTorrent will be.
Bind socket, which is not required when ipv6 is disabled.
That's all on this file. Save change.
Adds an entry to /etc/rc.conf
Find and install highest version of php.
Edit configuration file of /usr/local/etc/php-fpm.d/www.conf
Change the line:
For the following entry
Also change the following to what is shown below.
By uncommenting ; and assigning permissions.
Save change
Copy the sample and put it in a proper folder.
Adds an entry to /etc/rc.conf
At the file /usr/local/etc/lighttpd/modules.conf
Add the modules.
Add the following entries:
In the same file find the following line and debind it (remove #)
Save changes
In the file /usr/local/etc/lighttpd/conf.d/fastcgi.conf
Adds the following entries.
In the same file add the following entries.
Save changes
Port 6000 is the scgi port for rtorrent. It may be configured freely
Adds an entry to /etc/rc.conf
Enable installed modules.
Installs wget
Wget the RuTorrent.
Unzip them. When ask pres A and enter.
It extracted, the folder that contains RuTorrent is called ruTorrent-master.
Renaming a directory to a shorter one.
Move ruTorrent to the previously defined root directory using the move command
Create missing the directory for cache/history added .torrent file.
In ruTorrent directory create info.php file.
And paste the content below.
Save changes
To complete the formalities, change the owner and group to www:www for all files, as shown below.
This is done with the chown command, with the -R option.
Ad permission.
Check if the php server is running.
Enter the address and port of the server,
For me: http://10.1.1.137:8080/info.php
There should be a php server prompt.
Remove info.php from directory.
Install the rtorrent program.
Install the screen program.
Add a dummy user to run the torrent on
Create working folders for the torrent
Once the program is properly installed, add the basic settings for the rtorrent daemon to /etc/rc.conf.
Don't set anything else in /etc/rc.conf because it will be a mess.
Configure it to work as a daemon. The program running as a daemon does not use rtorrent.rc Based on the link below, the rtorrent daemon as built, which is also the main configuration file. https://anton-pribora.ru/articles/os/freebsd/rotrrent-web-panel-freebsd/ This is done this way, ot that way, because there is no way to save the torrent.rc file from within ruTorrent running on the server. Also, setting the ruTorrent settings on the client, works until reboot. In the daemon it is permanent. All functions from the manual RTORRENT(1)() are rewrited and can be changed in this file, between entries:
and
Single letter options, should work by adding an entry to
Create a deamon
And paste the following entry.
https://pastebin.com/YTeVgWqR
Because it is not possible to add an post larger than 25000 characters,
The daemon is attached at the end of the post as a text file.
After saving the file, enter the daemon once again and set the base configuration by editing the following entries.
This command must be set.
Grant execution privileges to the torrent daemon.
Starting deamon.
As can bee seen. It works.
Configuring the ruTorrent client
And change follows.
Define scgi_port and scgi_host to what is specified earlier.
In this block, there are given paths to programs that use ruTorrent plugin.
Install missing programs for ruTorrent plugins.
In this file provide the path to the program. These programs are used by ruTorrent plugins. If there are problems with the plugin, make sure the path to the file is correct. It may happen that newer versions of programs are in a different folder than they are now. Or new plugin will be created. If this happens, use the find command, and find the path to the program.
Sample:
At this point
Have ruTorrent with rtorrent on FreeBSD ready to run.
Is only need to disable the problematic plugins.
For this we go to the server ruTorrent address. http://10.1.1.138:8080 or http://localhost:8080
In the plugins tab, right-click to disable the following:
Check port queries the external server for our IP address.
Support open source by offloading server load.
As can see, it works.
At this moment the server is not password protected.
Be sure to block port 8080 on your firewall from outside access.
Otherwise it is possible to connect to the ruTorrent client by giving the host IP (from ISP) address and port 8080.
============================================================================
Basic password protection.
To protect server resources from unauthorized access, add on the file /usr/local/etc/lighttpd/lighttpd.conf
Follow entry:
Where:
Create the file and add username:mypassword entry.
Restart lighttpd server.
============================================================================
The files, including the dependiences from /var/cache/pkg They are attached below.
If a program is missing from the pkg. It is possible to install them from this package.
The package also contains ruTorrent. Command must be run in the directory where the package was extracted.
This is installed by the command
For example:
External links.
https://github.com/Novik/ruTorrent
https://anton-pribora.ru/articles/os/freebsd/rotrrent-web-panel-freebsd
https://wiki.archlinux.org/title/RTorrent/RuTorrent
https://www.digitalocean.com/community/tutorials/how-to-install-lighttpd-with-mysql-and-php-on-freebsd-11-0
Own work.
Start by installing the server.
Code:
pkg install lighttpd
Then edit the configuration file.
Code:
ee /usr/local/etc/lighttpd/lighttpd.conf
Change the port to 8080 from 80
Code:
server.port = 8080
Disable ipv6.
Code:
server.use-ipv6 = "disable"
Change the directory of the website to the directory where ruTorrent will be.
Code:
server.document-root = "/usr/local/www/lighttpd/ruTorrent"
Bind socket, which is not required when ipv6 is disabled.
Code:
#$SERVER["socket"] == "0.0.0.0:80" { }
Adds an entry to /etc/rc.conf
Code:
sysrc lighttpd_enable="yes"
Find and install highest version of php.
Code:
root@1234:/var/cache/pkg # pkg search php
root@1234:/var/cache/pkg # pkg install php81
Edit configuration file of /usr/local/etc/php-fpm.d/www.conf
Code:
ee /usr/local/etc/php-fpm.d/www.conf
Change the line:
Code:
listen = 127.0.0.1:9000
For the following entry
Code:
listen = /var/run/php-fpm.sock
Also change the following to what is shown below.
By uncommenting ; and assigning permissions.
Code:
listen.owner = www
listen.group = www
listen.mode = 0660
Copy the sample and put it in a proper folder.
Code:
cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
Adds an entry to /etc/rc.conf
Code:
sysrc php_fpm_enable="yes"
At the file /usr/local/etc/lighttpd/modules.conf
Add the modules.
Code:
ee /usr/local/etc/lighttpd/modules.conf
Add the following entries:
Code:
server.modules = (
"mod_authn_file",
"mod_auth",
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
"mod_fastcgi",
)
In the same file find the following line and debind it (remove #)
Code:
conf_dir + "/conf.d/fastcgi.conf"
In the file /usr/local/etc/lighttpd/conf.d/fastcgi.conf
Code:
ee /usr/local/etc/lighttpd/conf.d/fastcgi.conf
Adds the following entries.
Code:
server.modules += ( "mod_fastcgi" )
server.modules += ( "mod_scgi" )
In the same file add the following entries.
Code:
fastcgi.server += ( ".php" =>
((
"socket" => "/var/run/php-fpm.sock",
"broken-scriptfilename" => "enable"
))
)
scgi.server = ( "/RPC2" =>
( "127.0.0.1" =>
(
"host" => "127.0.0.1",
"port" => 6000,
"check-local" => "disable"
)
)
)
Port 6000 is the scgi port for rtorrent. It may be configured freely
Adds an entry to /etc/rc.conf
Code:
sysrc lighttpd_enable=yes
Enable installed modules.
Code:
root@1234:/var/cache/pkg # service php-fpm start
Performing sanity check on php-fpm configuration:
[18-May-2022 23:21:50] NOTICE: configuration file /usr/local/etc/php-fpm.conf test is successful
Starting php_fpm.
root@1234:/var/cache/pkg # service lighttpd start
Starting lighttpd.
Installs wget
Code:
pkg install wget
Wget the RuTorrent.
Code:
wget https://github.com/Novik/ruTorrent/archive/refs/heads/master.zip
Unzip them. When ask pres A and enter.
Code:
unzip master.zip
Code:
root@1234:/var/cache # unzip master.zip
Archive: master.zip
creating: ruTorrent-master/
creating: ruTorrent-master/.github/
creating: ruTorrent-master/.github/ISSUE_TEMPLATE/
replace ruTorrent-master/.github/ISSUE_TEMPLATE/bug_report.yml? [y]es, [n]o, [A]ll, [N]one, [r]ename:
It extracted, the folder that contains RuTorrent is called ruTorrent-master.
Renaming a directory to a shorter one.
Code:
mv ruTorrent-master ruTorrent
Move ruTorrent to the previously defined root directory using the move command
Code:
mv ruTorrent /usr/local/www/lighttpd/ruTorrent
Create missing the directory for cache/history added .torrent file.
Code:
mkdir -p /usr/local/www/lighttpd/ruTorrent/php/share/torrents
In ruTorrent directory create info.php file.
Code:
ee /usr/local/www/lighttpd/ruTorrent/info.php
And paste the content below.
Code:
<?php phpinfo(); ?>
To complete the formalities, change the owner and group to www:www for all files, as shown below.
This is done with the chown command, with the -R option.
Code:
chown -R www:www /usr/local/www/lighttpd/ruTorrent
Ad permission.
Code:
chmod -R 0775 /usr/local/www/lighttpd/ruTorrent
Check if the php server is running.
Enter the address and port of the server,
For me: http://10.1.1.137:8080/info.php
There should be a php server prompt.
Remove info.php from directory.
Code:
rm /usr/local/www/lighttpd/ruTorrent/info.php
Install the rtorrent program.
Code:
pkg install rtorrent
Install the screen program.
Code:
pkg install screen
Add a dummy user to run the torrent on
Code:
pw useradd rtorrent -s /sbin/nologin
Create working folders for the torrent
Code:
mkdir -p /usr/local/rtorrent/downloads
mkdir -p /usr/local/rtorrent/sessions
chown -R rtorrent:rtorrent /usr/local/rtorrent/
Once the program is properly installed, add the basic settings for the rtorrent daemon to /etc/rc.conf.
Code:
sysrc rtorrent_enable="YES"
sysrc rtorrent_scgi_port="127.0.0.1:6000"
Don't set anything else in /etc/rc.conf because it will be a mess.
Configure it to work as a daemon. The program running as a daemon does not use rtorrent.rc Based on the link below, the rtorrent daemon as built, which is also the main configuration file. https://anton-pribora.ru/articles/os/freebsd/rotrrent-web-panel-freebsd/ This is done this way, ot that way, because there is no way to save the torrent.rc file from within ruTorrent running on the server. Also, setting the ruTorrent settings on the client, works until reboot. In the daemon it is permanent. All functions from the manual RTORRENT(1)() are rewrited and can be changed in this file, between entries:
#START USER CONFIGURATION
and
#END USER CONFIGURATION
Single letter options, should work by adding an entry to
: ${rtorrent_args=""}
Create a deamon
Code:
ee /usr/local/etc/rc.d/rtorrent
And paste the following entry.
https://pastebin.com/YTeVgWqR
Because it is not possible to add an post larger than 25000 characters,
The daemon is attached at the end of the post as a text file.
After saving the file, enter the daemon once again and set the base configuration by editing the following entries.
Code:
ee /usr/local/etc/rc.d/rtorrent
This command must be set.
: ${rtorrent_user="rtorrent"}
- Set user who running rtorrent : ${rtorrent_directory="/usr/local/rtorrent/downloads"}
- location of downloads directory : ${rtorrent_session="/usr/local/rtorrent/sessions"}
- lotation of session directoryGrant execution privileges to the torrent daemon.
Code:
chmod +x /usr/local/etc/rc.d/rtorrent
Starting deamon.
Code:
root@1234:/usr/local/www # service rtorrent start
[: missing ]
Starting rtorrent.
root@1234:/usr/local/www # service rtorrent status
[: missing ]
rtorrent is running as pid 53973.
root@1234:/usr/local/www #
Configuring the ruTorrent client
Code:
ee /usr/local/www/lighttpd/ruTorrent/conf/config.php
And change follows.
Define scgi_port and scgi_host to what is specified earlier.
Code:
$scgi_port = 6000;
$scgi_host = "127.0.0.1";
In this block, there are given paths to programs that use ruTorrent plugin.
Code:
$pathToExternals = array(
"php" => '/usr/local/bin/php', // Something like /usr/bin/php. If empty, will be found in PATH.
"curl" => '/usr/local/bin/curl', // Something like /usr/bin/curl. If empty, will be found in PATH.
"gzip" => '/usr/bin/gzip', // Something like /usr/bin/gzip. If empty, will be found in PATH.
"id" => '/usr/bin/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.
"pgrep" => '/usr/bin/pgrep',
"sox" => '/usr/local/bin/sox',
"python" => '/usr/local/bin/python',
"unrar" => '/usr/local/bin/unrar',
"mediainfo" => '/usr/local/bin/mediainfo',
"ffmpeg" => '/usr/local/bin/ffmpeg',
);
Install missing programs for ruTorrent plugins.
Code:
pkg install ffmpeg
pkg install mediainfo
pkg install unrar
pkg install python
pkg install sox
In this file provide the path to the program. These programs are used by ruTorrent plugins. If there are problems with the plugin, make sure the path to the file is correct. It may happen that newer versions of programs are in a different folder than they are now. Or new plugin will be created. If this happens, use the find command, and find the path to the program.
Sample:
Code:
root@1234:/usr/local/www # find / -name python
/usr/local/bin/python
At this point
Have ruTorrent with rtorrent on FreeBSD ready to run.
Is only need to disable the problematic plugins.
For this we go to the server ruTorrent address. http://10.1.1.138:8080 or http://localhost:8080
In the plugins tab, right-click to disable the following:
Code:
_cloudflare
_noty
_noty2
check_port
Check port queries the external server for our IP address.
Support open source by offloading server load.
As can see, it works.
At this moment the server is not password protected.
Be sure to block port 8080 on your firewall from outside access.
Otherwise it is possible to connect to the ruTorrent client by giving the host IP (from ISP) address and port 8080.
============================================================================
Basic password protection.
To protect server resources from unauthorized access, add on the file /usr/local/etc/lighttpd/lighttpd.conf
Code:
ee /usr/local/etc/lighttpd/lighttpd.conf
Follow entry:
Code:
$HTTP["url"] == "/" {
auth.backend = "plain"
auth.backend.plain.userfile = "/usr/local/www/lighttpd/.lighttpdpassword"
auth.require = (
"/" => (
"method" => "basic",
"realm" => "Password protected area",
"require" => "user=admin"
)
)
}
Where:
auth.backend.plain.userfile = "/usr/local/www/lighttpd/.lighttpdpassword"
- path to file were username:mypassword is stored. "require" => "user=admin"
- admin must be set as username admin:mypassword on the .lighttpdpassword file.Create the file and add username:mypassword entry.
Code:
echo "admin:mypassword" >> /usr/local/www/lighttpd/.lighttpdpassword
Restart lighttpd server.
Code:
service lighttpd restart
The files, including the dependiences from /var/cache/pkg They are attached below.
If a program is missing from the pkg. It is possible to install them from this package.
The package also contains ruTorrent. Command must be run in the directory where the package was extracted.
This is installed by the command
pkg add programname
For example:
Code:
root@1234:/home/vbox/pkg # pkg add gzip-1.11.pkg
Installing gzip-1.11...
the most recent version of gzip-1.11 is already installed
root@1234:/home/vbox/pkg #
pkg.zip
drive.google.com
External links.
https://github.com/Novik/ruTorrent
https://anton-pribora.ru/articles/os/freebsd/rotrrent-web-panel-freebsd
https://wiki.archlinux.org/title/RTorrent/RuTorrent
https://www.digitalocean.com/community/tutorials/how-to-install-lighttpd-with-mysql-and-php-on-freebsd-11-0
Own work.
Attachments
Last edited: