Raspberry Pi 2b Step by step guide

PART 2

Table of Contents 7. Torrent (0:05) ...... 2

Installing the qBittorrent server ...... 2

Increase download speeds by port forwarding qBittorrent ...... 4

Configuring a blocklist for qBittorrent ...... 6

Creating a startup script for qBittorrent ...... 7

Downloading a torrent file ...... 9

Adding torrents automatically to the qBittorent WebUI (Chrome) ...... 10

External access to the qBittorrent WebUI by port forwarding ...... 12

Moving partially downloaded torrents to a new server ...... 14

Setting up access to qBittorrent on your android phone ...... 15

Script to start & stop qbittorrent service ...... 16

Restarting the qbittorrent service automatically with cron ...... 17

How to uninstall qBittorrent ...... 18

8. Installing Apache web server (10:50) ...... 19

Allowing the internet access to your Apache web server ...... 20

9. Installing MySQL database server, and utilities (13:07) ...... 22

Installing MySQL server on the Raspberry Pi 2b ...... 22

Installing MySQL client on the Raspberry Pi 2b ...... 22

Install MySQL Workbench on the Raspberry Pi 2b ...... 23

Install MySQL Workbench on a windows desktop PC ...... 25

Connecting MySQL Workbench to the Raspberry Pi 2b ...... 26

Installing PhpMyAdmin on the Raspberry Pi 2b ...... 27

10. Installing (iceweasel) (17:00) ...... 30

Video DownloadHelper addon ...... 30

11. Using SFTP to transfer files (WinSCP) (17:27) ...... 31

12. Using Dropbox (18:16) ...... 32

MDTV3 PAGE 1 OF 35 Raspberry Pi 2b

7. Torrent software (0:05)

Installing the qBittorrent server http://www.htpcbeginner.com/install-qbittorrent-webui-ubuntu/

Downloading of software & media via torrent can have legitimate purposes as well as non-legitimate. For example, NOOBS is available as a torrent download.

Before we go too much further update & upgrade our system again by typing in the following command; sudo apt-get update && sudo apt-get upgrade

Download and install qBittorrent NO X server version, Web UI (User Interface) by typing in the following: sudo apt-get install qbittorrent-nox

To install the qBittorrent GUI (Graphical User Interface) version type: sudo apt-get install qbittorrent qbittorrent-nox

Start the GUI version of qBittorrent by selecting it from the menu (or type qbittorrent-nox into a terminal)

Click I agree

From the Tools menu select options

MDTV3 VERSION 1 PAGE 2 OF 35 Raspberry Pi 2b

Select Downloads on the left hand side.

Set the directory to save files to (and if preferred the location for incomplete torrents).

Select Web UI on the left hand side.

Place a tick in Enable web user interface, set the port to 8888 tick UPnP and HTTPS, set the username & password and tick to bypass for localhost.

I’ve set the username to qtorrent and the password to secret

Test that the web interface works by typing in the address to the server: 192.168.1.68:8888

Test from the Raspberry Pi 2B as well as another computer on your network.

MDTV3 VERSION 1 PAGE 3 OF 35 Raspberry Pi 2b

Increase download speeds by port forwarding qBittorrent

To enable better download speed, we should port forward all qBittorrent traffic from your internet router to the Raspberry Pi 2b.

From qBittorrent options page click on connection and see what port number qBittorrent is using (6881).

On my router I go to Toolbox, Game & Application sharing and select create a new game or application.

Type in an obvious name for the application, I chose to call it qBittorrent, click Manual entry of port maps, then clicked Next.

Put the port number (6881) in the port range boxes and the translate to box and click add.

MDTV3 VERSION 1 PAGE 4 OF 35 Raspberry Pi 2b

Click on Assign a game or application to a local network device.

Select the application name we created before, qBittorrent and then select the raspberrypi as the device and click add

Use an online port checking program Test the connection http://www.yougetsignal.com/tools/open-ports/

If the test states that the port is open all is well, I have blocked out my real network address for privacy.

MDTV3 VERSION 1 PAGE 5 OF 35 Raspberry Pi 2b

Configuring a blocklist for qBittorrent

Open the terminal and make sure you are at your home directory, type in cd

Download a blocklist from where ever you like, I’m downloading this from bitsurge, type: sudo http://john.bitsurge.net/public/biglist.p2p.gz

Unzip the blocklist by typing sudo gzip -d biglist.p2p.gz

From qBittornet options click on Connections on the left and tick IP Filtering, click the icon with 3 dots to browse to the blocklist file.

Click the icon with the green rotating arrow to load the blocklist

Click OK https://giuliomac.wordpress.com/2014/02/19/best-blocklist-for-transmission/

MDTV3 VERSION 1 PAGE 6 OF 35 Raspberry Pi 2b

Creating a startup script for qBittorrent

Create a file by typing; sudo nano /etc/init.d/qbittorrent-nox-daemon

Copy the contents of this script into it; http://www.htpcbeginner.com/resources/codes/qbittorrent-startup-script.txt

Change DAEMON_ARGS="--webui-port=XXXX" to the port number to which you want qBittorrent to listen and Change USER=MyUserName to the name of the user whom you want to run qBittorrent daemon as.

#! /bin/sh ### BEGIN INIT INFO # Provides: qbittorrent-nox # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Starts QBittorrent # Description: Start qbittorrent-nox on start. Change USER= before running ### END INIT INFO

# Author: Jesper Smith #

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="QBittorrent" NAME=qbittorrent-nox DAEMON=/usr/bin/$NAME DAEMON_ARGS="--webui-port=8888" PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/qbittorrent USER=pi

# Exit if the package is not installed [ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present [ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh

# Define LSB log_* functions. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. . /lib/lsb/init-functions

# # Function that starts the daemon/service # do_start() { # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started start-stop-daemon -c $USER -b -t --start --quiet --exec $DAEMON \ || return 1

start-stop-daemon -c $USER -b --start --quiet --exec $DAEMON -- \ $DAEMON_ARGS \ || return 2 sleep 1 }

# # Function that stops the daemon/service # do_stop() { start-stop-daemon -c $USER --quiet --stop --exec $DAEMON sleep 2 return "$?" }

case "$1" in start) [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"

MDTV3 VERSION 1 PAGE 7 OF 35 Raspberry Pi 2b

do_start case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; stop) [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" do_stop case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; status) status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? ;; restart|force-reload) log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in 0|1) do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1 ;; esac ;; *) #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 exit 3 ;; esac

Press control X enter Y and enter to save changes.

Change the permissions on the file by typing sudo chmod 755 /etc/init.d/qbittorrent-nox-daemon Update the init scripts with sudo update-rc.d qbittorrent-nox-daemon defaults

Start the daemon manually by typing; sudo service qbittorrent-nox-daemon start

Other useful commands to know are: To stop the daemon sudo service qbittorrent-nox-daemon stop To Restart the daemon sudo service qbittorrent-nox-daemon restart http://www.htpcbeginner.com/install-qbittorrent-webui-ubuntu/

MDTV3 VERSION 1 PAGE 8 OF 35 Raspberry Pi 2b

Downloading a torrent file

Add a torrent to test that everything works OK, I am going to download NOOBS LITE from this link: https://www.raspberrypi.org/downloads/

Right click on the download torrent link and select Copy Link Location

Point your browser to the Raspberry Pi 192.168.1.68:8888

Click on the icon of a chain link with a green plus sign and paste the link into the box that pops up.

Click Download

We can see that the NOOBs zip file is being downloaded.

MDTV3 VERSION 1 PAGE 9 OF 35 Raspberry Pi 2b

Adding torrents automatically to the qBittorent WebUI (Chrome)

I have found that Chrome works the best for me, you can try other browsers though if you like.

Do a search for Remote Torrent Adder in Chrome, install the extension.

From Chromes settings, extensions remove any server that maybe there by default then click Add Server.

Enter in the server name (call it anything, I just entered RaspberryPi)

Select qBittorrent WebUI from the drop down list

MDTV3 VERSION 1 PAGE 10 OF 35 Raspberry Pi 2b

Enter the following: The Name of the server, RaspberryPi Host 192.168.1.68 Port number 8888 Username qtorrent Password secret

If you left, click on the torrent download link and it will automatically be added to the qBittorrent WebUI.

https://www.raspberrypi.org/downloads/

Check the qBittorrent WebUI and the NOOBs zip file has been added.

If we have a peek over the network to the shared folder, we can see the file being downloaded

MDTV3 VERSION 1 PAGE 11 OF 35 Raspberry Pi 2b

External access to the qBittorrent WebUI by port forwarding

If you need to access the qBittorrent interface remotely over the internet you will need to open up the port 8888 on your router and port forward it to the Raspberry Pi 2b.

On my router I go to Toolbox, Game & Application sharing and select create a new game or application.

Type in an obvious name for the application, I choose to call it qBittorrentWebUI, click Manual entry of port maps, then clicked Next.

Put the port number 8888 in the port range boxes and the translate to box and click add

MDTV3 VERSION 1 PAGE 12 OF 35 Raspberry Pi 2b

Click on Assign a game or application to a local network device

.

Select the application name we created before, qBittorrenTwEBui and then select the raspberrypi as the device and click add`

Use an online port checking program Test the connection http://www.yougetsignal.com/tools/open-ports/

If the test states that the port is open all is well, I have blocked out my real network address for privacy.

MDTV3 VERSION 1 PAGE 13 OF 35 Raspberry Pi 2b

Moving partially downloaded torrents to a new server

Stop the qBittorrent service, then copy the incoming torrent folder from the Raspberry Pi 2b to your desktop PC or new server.

Copy the .torrent files to the usb hard disk drive by typing; cp -r ~/.local/share/data/qBittorrent/BT_backup/ /media/usbhdd/

Allow the NAS user full access to the files by typing; sudo chown -R nasuser /media/usbhdd/BT_backup/

Now copy the BT_backup folder from the Raspberry Pi 2b to your desktop PC or new server.

To move the files to a new server copy them to the shared folder on the network sudo cp /media/usbhdd/incoming/BT_backup/* ~/.local/share/data/qBittorrent/BT_backup/

Change the ownership of all the files to the user pi sudo chown pi:pi ~/.local/share/data/qBittorrent/BT_backup/*

Modify the access permissions chmod 755 –R ~/.local/share/data/qBittorrent/BT_backup

Restart qBittorrent and check downloading continues.

MDTV3 VERSION 1 PAGE 14 OF 35 Raspberry Pi 2b

Setting up access to qBittorrent on your android phone

Go to google playstore on your computer or phone and search for qBittorrent Controller and install the app.

Click on the 3 horizontal bars at the top right of the app or swipe from left to right.

Click on the Settings icon

Click on Connection host and enter 192.168.1.68

Click on Username and enter qtorrent

Click on password and enter secret

Click on Advanced

Click on Connection Port and enter 8888

MDTV3 VERSION 1 PAGE 15 OF 35 Raspberry Pi 2b

Script to start & stop qbittorrent service

Create scripts to make it easier to start & stop the qbittorrent server.

Type in sudo nano /usr/bin/qstart

Paste the following commands into the file then press Control X and Y to save the file

#!/bin/sh sudo service qbittorrent-nox-daemon start

Type in sudo nano /usr/bin/qstop

Paste the following commands into the file then press Control X and Y to save the file

#!/bin/sh sudo service qbittorrent-nox-daemon stop

MDTV3 VERSION 1 PAGE 16 OF 35 Raspberry Pi 2b

Restarting the qbittorrent service automatically with cron

I noticed my version of qbittorrent crashed on a somewhat regular basis, after doing some research it was recommended that I upgrade to the latest version. Due to the difficulty of making the binary files for my version of unix I decided just to restart the service every hour using cron

Type in crontab –e to edit the cron table

Type in the following command at the bottom of the file to run the qstart script every hour 0 * * * * /usr/bin/qstart

Press control X enter Y and enter to save changes. https://www.raspberrypi.org/documentation/linux/usage/cron.md

MDTV3 VERSION 1 PAGE 17 OF 35 Raspberry Pi 2b

How to uninstall qBittorrent

If you have any partially downloaded files backup the .torrent files as shown previously

Uninstall qbittorrent by typing in the following commands

sudo apt-get remove --purge qbittorrent-nox sudo apt-get remove --purge qbittorrent qbittorrent-nox sudo apt-get autoremove

MDTV3 VERSION 1 PAGE 18 OF 35 Raspberry Pi 2b

8. Installing Apache web server (10:50)

You can run your own website from Raspberry Pi 2b by installing Apache web server.

Type the following command in: sudo apt-get install apache2 –y

Open up a and point it to: 192.168.1.68

If you get the above message, then everything is up & running.

To start making changes is easy, the main page is located in /var/www/

Make a simple change to the main page by typing; sudo nano /var/www/index.html

You can see the changes I made to the index.html above file.

https://www.raspberrypi.org/documentation/remote-access/web-server/apache.md

MDTV3 VERSION 1 PAGE 19 OF 35 Raspberry Pi 2b

Allowing the internet access to your Apache web server

If you want to have your webpages available over the internet you will need to open up the port 9999 on your router and port forward it to the Raspberry Pi 2b.

On my router I go to Toolbox, Game & Application sharing and select create a new game or application.

Type in an obvious name for the application, I choose to call it WWWpi, click Manual entry of port maps, then clicked Next.

Put the port number 9999 in the port range boxes and port number 80 in the translate to box and click add

MDTV3 VERSION 1 PAGE 20 OF 35 Raspberry Pi 2b

Click on Assign a game or application to a local network device

Select the application name we created before, WWWpi and then select the raspberrypi as the device and click add

Use an online port checking program Test the connection

http://www.yougetsignal.com/tools/open-ports/

Point your browser from the remote location to your internet IP address with the port :9999

MDTV3 VERSION 1 PAGE 21 OF 35 Raspberry Pi 2b

9. Installing MySQL database server, client and utilities (13:07)

Installing MySQL server on the Raspberry Pi 2b

Update & upgrade our system again by typing in the following command; sudo apt-get update && sudo apt-get upgrade

Install MySQL by typing the following; sudo apt-get install mysql-server --fix-missing

Enter secret for the password

Confirm the password by typing in secret

Installing MySQL client on the Raspberry Pi 2b

Install the MySQL client by typing; sudo apt-get install mysql-client php5-mysql http://www.raspipress.com/2014/06/tutorial-install-mysql-server-on-raspbian/

MDTV3 VERSION 1 PAGE 22 OF 35 Raspberry Pi 2b

Install MySQL Workbench on the Raspberry Pi 2b

Type in the following command sudo apt-get install mysql-workbench

Once the program is installed you can run it from the menu, under Programming and then MySQL Workbench

This is a screenshot of the program running on the Raspberry Pi 2b

MDTV3 VERSION 1 PAGE 23 OF 35 Raspberry Pi 2b

Click on New Connection

Enter in any name for the connection, RaspberryPi

Click on the password Store in Keychain button

Type in secret then click OK

Click on the Test Connection button and you should receive a message saying everything is OK

http://www.instructables.com/id/How-to-make-an-alarm-system-with-Arduino/step2/Install-the-MySQL-DB/

MDTV3 VERSION 1 PAGE 24 OF 35 Raspberry Pi 2b

Install MySQL Workbench on a windows desktop PC

Download the MySQL Workbench software from the following website https://dev.mysql.com/downloads/workbench/

Install the software using the default options.

This is a screenshot of the program running on a windows 7 desktop PC

MDTV3 VERSION 1 PAGE 25 OF 35 Raspberry Pi 2b

Connecting MySQL Workbench to the Raspberry Pi 2b

Click on the “+” plus sign

Enter a connection name at the top of the pop-up window, I have used RaspberryPi. Select Standard TCP/IP over SSH from the drop down box

Enter in the IP address for the Raspberry Pi on port 22. 192.168.1.68:22

Enter in pi for the SSH username.

Click Store in Vault and enter secret as the password

For the bottom section leave everything as default and click Store in Vault and enter secret as the password

Click on Test Connection

If everything works you should see this message

MDTV3 VERSION 1 PAGE 26 OF 35 Raspberry Pi 2b

Installing PhpMyAdmin on the Raspberry Pi 2b

Install the program by typing the following into the terminal: sudo apt-get install phpmyadmin

Select apache2 by pressing the SPACE BAR, then press tab to move to the OK text and hit enter

Press enter

Type in secret for the password and press enter

MDTV3 VERSION 1 PAGE 27 OF 35 Raspberry Pi 2b

Type in secret for the password and press enter

Confirm the password by typing secret and press enter

Type in the following command sudo nano /etc/apache2/apache2.conf

Add this line to the bottom of the file Include /etc/phpmyadmin/apache.conf

MDTV3 VERSION 1 PAGE 28 OF 35 Raspberry Pi 2b

Restart Apache for the changes to take effect by typing sudo /etc/init.d/apache2 restart

Check that phpMyAdmin is working on the Raspberry Pi 2b by browsing to localhost/phpmyadmin

Login as root with the password of secret

Check that phpMyAdmin is working on your desktop PC by browsing to 192.168.1.68/phpmyadmin

http://www.raspipress.com/2012/09/tutorial-install-phpmyadmin-on-your-raspberry-pi/

MDTV3 VERSION 1 PAGE 29 OF 35 Raspberry Pi 2b

10. Installing Firefox (iceweasel) (17:00)

Type in sudo apt-get install iceweasel

Open iceweasel and do a search for video downloadhelper iceweasel

Video DownloadHelper addon

Open up the link with the add-on and click add to firefox

Once installed you will get the following message

https://www.youtube.com/watch?v=9cODs3ft8Xc https://www.raspberrypi.org/forums/viewtopic.php?t=12397&p=132751

MDTV3 VERSION 1 PAGE 30 OF 35 Raspberry Pi 2b

11. Using SFTP to transfer files (WinSCP) (17:27)

You can use SFTP to transfer large amounts of file between the server and your desktop PC. Download WinSCP from winscp.net and install it to your desktop PC

The first time you run the program setup the connection details.

Hostname: 192.168.1.68 Port Number: 22 (default) Username: pi Password: secret

Click Login

The local desktop PC files are on the left and the Raspberry Pi 2b files are on the right.

You can transfer files in either direction as long as you have the access rights to do so.

MDTV3 VERSION 1 PAGE 31 OF 35 Raspberry Pi 2b

12. Using Dropbox (18:16)

If you’ve got a slow internet connection like me, you will want the Raspberry Pi 2b to upload/download most of your large files to your Dropbox account (usually overnight when you’re not using the internet)

Copy the Dropbox script files from the internet by typing: git clone https://github.com/andreafabrizi/Dropbox-Uploader/

Once the files are downloaded change to the Dropbox-uploader directory by typing: cd Dropbox-Uploader

Make the script file executable by typing: chmod +x dropbox_uploader.sh

Run the script by typing: ./dropbox_uploader.sh

Copy the URL address and paste it into a web browser.

MDTV3 VERSION 1 PAGE 32 OF 35 Raspberry Pi 2b

Click on App Console on the left hand side

Then click the CREATE APP button on the right hand side

Click on Dropbox API app button

Click NO

Click All file types

Give the app a name, I called mine deansdropi

Click the I agree check box and press the Create App button

MDTV3 VERSION 1 PAGE 33 OF 35 Raspberry Pi 2b

Copy the app key

and paste it into the terminal script

Click SHOW text to reveal the app secret code

You can’t copy & paste this text so just type that into the terminal script

Type in f to allow access to all files in your Dropbox account

Copy the URL address and paste it into a web browser.

MDTV3 VERSION 1 PAGE 34 OF 35 Raspberry Pi 2b

Click the Allow button

You will get confirmation in the script that the setup is now complete.

A list of commands is shown to the right; more information can be found here: https://github.com/andreafabrizi/Dropbox-Uploader

Upload Download [LOCAL_FILE/DIR]

delete move

copy mkdir

list [REMOTE_DIR] share

saveurl info

unlink

See also: http://raspi.tv/2013/how-to-use-dropbox-with-raspberry-pi https://learn.adafruit.com/diy-wifi-raspberry-pi-touch-cam/dropbox-setup

MDTV3 VERSION 1 PAGE 35 OF 35