Install Seafile on Raspian, Raspberry Pi

Prerequisites: Install LAMP (optional: Installing No-IP client on Raspian)

More info at: Deploying Seafile under Linux

Login as root:

sudo su

Create directory for Seafile: (example*)

mkdir /media/usbhdd/seafile

Move to created directory:

cd /media/usbhdd/seafile

Download latest Seafile server for Raspberry Pi:

wget https://bitbucket.org/haiwen/seafile/downloads/seafile-server_4.0.6_pi.tar.gz

Extract archive:

tar xvf seafile-server_4.0.6_pi.tar.gz

Create directory:

mkdir installed

Move your archive to newly created directory:

mv seafile-server_4.0.6_pi.tar.gz installed

Check prerequisites:

dpkg-query -l python2.7 python-setuptools python-imaging python-mysqldb

and install missing packages:

apt-get install python-setuptools python-mysqldb

Move to directory:

cd seafile-server-4.0.6/

Run the script:

./setup-seafile-mysql.sh
What is the name of the server? It will be displayed on the client.
3 - 15 letters or digits
[ server name ] <hostname/servername>

What is the ip or domain of the server?
For example: www.mycompany.com, 192.168.1.101
[ This server's ip or domain ] <your-dynamic-dns-address> OR <hostname>.local OR <local-IP-address>

Which port do you want to use for the ccnet server?
[ default "10001" ]

Where do you want to put your seafile data?
Please use a volume with enough free space
[ default "/media/usbhdd/seafile/seafile-data" ]

Which port do you want to use for the seafile server?
[ default "12001" ]

Which port do you want to use for the seafile fileserver?
[ default "8082" ]

-------------------------------------------------------
Please choose a way to initialize seafile databases:
-------------------------------------------------------

[1] Create new ccnet/seafile/seahub databases
[2] Use existing ccnet/seafile/seahub databases

[ 1 or 2 ] 1 *recomended by seafile

What is the host of mysql server?
[ default "localhost" ]

What is the port of mysql server?
[ default "3306" ]

What is the password of the mysql root user?
[ root password ] <your-mysql-root-password>

verifying password of user root ... done

Enter the name for mysql user of seafile. It would be created if not exists.
[ default "root" ] seafile OR <any-other-username-for-seafile-mysql-user>

Enter the password for mysql user "seafile":
[ password for seafile ] <password>

Enter the database name for ccnet-server:
[ default "ccnet-db" ]

Enter the database name for seafile-server:
[ default "seafile-db" ]

Enter the database name for seahub:
[ default "seahub-db" ]

---------------------------------
This is your configuration
---------------------------------

server name: <hostname/servername-you-used>
 server ip/domain: <ip-adress/domain-you-used>
 ccnet port: 10001
seafile data dir: /media/usbhdd/seafile/seafile-data
 seafile port: 12001
 fileserver port: 8082

database: create new
 ccnet database: ccnet-db
 seafile database: seafile-db
 seahub database: seahub-db
 database user: seafile

---------------------------------
Press ENTER to continue, or Ctrl-C to abort
---------------------------------

While in /media/usbhdd/seafile/seafile-server-4.0.6:

Start seafile:

./seafile.sh start # Start seafile service

Start seahub

./seahub.sh start # Start seahub website, port defaults to 8000
Starting seahub at port 8000 ...

----------------------------------------
It's the first time you start the seafile server. Now let's create the admin account
----------------------------------------

What is the email for the admin account?
[ admin email ] <your-mail>

What is the password for the admin account?
[ admin password ] <password>

Enter the password again:
[ admin password again ] <repeat-password>

----------------------------------------
Successfully created seafile admin
----------------------------------------

Type in your browser, and check if setup is successful:

http://<localIP>:8000

SSL / HTTPS

(http://kmnns.spdns.eu/machine/cubie/seafile_with_ssl/)
(http://techiezone.rottigni.net/2013/03/seafile-configuring-with-apache-in-https/)
(http://manual.seafile.com/deploy/https_with_apache.html)

Generate and apply your ssl keys (logged in as user):

sudo openssl genrsa -out seafile-key.pem 2048
sudo openssl req -new -x509 -key seafile-key.pem -out seafile-cacert.pem -days 1095
sudo mkdir /etc/apache2/ssl
sudo mv *.pem /etc/apache2/ssl
sudo mkdir /var/www/seafile
sudo a2enmod ssl

Edit file:

sudo nano /media/usbhdd/seafile/ccnet/ccnet.conf

Add this line:

SERVICE_URL = https://<your-dynamic-dns-address>:8001

or:

SERVICE_URL = https://<hostname>.local:8001

or:

SERVICE_URL = https://<local-IP-address>:8001

Edit file:

sudo nano /media/usbhdd/seafile/seahub_settings.py

Add this line:

FILE_SERVER_ROOT = 'https://<your-dynamic-dns-address>:8001/seafhttp'

or:

FILE_SERVER_ROOT = 'https://<hostname>.local:8001/seafhttp'

or:

FILE_SERVER_ROOT = 'https://<local-IP-address>:8001/seafhttp'

Enable modes on Apache:

sudo a2enmod rewrite
sudo a2enmod fastcgi
sudo a2enmod proxy_http

Edit file:

sudo nano /etc/apache2/ports.conf

Add these lines:

<IfModule ssl_module>
[...]
Listen 8001
</IfModule>

<IfModule mod_gnutls.c>
[...]
Listen 8001
</IfModule>

Edit file:

sudo nano /etc/apache2/sites-available/seafile-ssl.conf:
FastCGIExternalServer /var/www/seafile/seahub.fcgi -host 127.0.0.1:8000 -idle-timeout 600

<Directory /data/opt/seafile/seafile-server-latest/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

<VirtualHost *:8001>
ServerAdmin <your-mail>

Servername <hostname/servername-you-used>
ServerAlias <hostname/servername-you-used>

DocumentRoot /var/www/seafile
Alias /media /media/usbhdd/seafile/seafile-server-latest/seahub/media

SSLEngine On
SSLCertificateFile /etc/apache2/ssl/<cert-name-you-used>.pem (*seafile-cacert.pem previously as an example)
SSLCertificateKeyFile /etc/apache2/ssl/<key-name-you-used>.pem (seafile-key.pem previously as an example)

RewriteEngine On

#
# seafile httpserver
#
ProxyPass /seafhttp http://127.0.0.1:8082
ProxyPassReverse /seafhttp http://127.0.0.1:8082
RewriteRule ^/seafhttp - [QSA,L]

#
# seahub
#
RewriteRule ^/(media.*)$ /$1 [QSA,L,PT]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /seahub.fcgi/$1 [QSA,L,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</VirtualHost>

Enable site:

sudo a2ensite seafile-ssl.conf

Restart Apache:

/etc/init.d/apache2 restart

Log in as root:

sudo su

Move to folder:

cd /media/usbhdd/seafile/seafile-server-latest

Stop:

./seahub.sh stop
./seafile.sh stop

Start:

./seafile.sh start
./seahub.sh start-fastcgi

Forward ports on your router if you are using dynamic dns:

  • 8001
  • 10001
  • 12001

to local IP address.

Test your setup in browser:

https://<your-seafile-address>:8001

Install client on your computer or smartphone and test. (Download client here.)

AUTOSTART

Create a script /etc/init.d/seafile-server (*logged in as user)

sudo nano /etc/init.d/seafile-server

The content of this script is: (You need to modify the value of user and script_path accordingly)

#!/bin/sh

### BEGIN INIT INFO
# Provides: seafile-server
# Required-Start: $local_fs $remote_fs $network mysql
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts Seafile Server
# Description: starts Seafile Server
### END INIT INFO

# Change the value of "user" to your linux user name
user=root

# Change the value of "script_path" to your path of seafile installation
seafile_dir=/media/usbhdd/seafile
script_path=${seafile_dir}/seafile-server-latest
seafile_init_log=${seafile_dir}/logs/seafile.init.log
seahub_init_log=${seafile_dir}/logs/seahub.init.log

# Change the value of fastcgi to true if fastcgi is to be used
fastcgi=true
# Set the port of fastcgi, default is 8000. Change it if you need different.
fastcgi_port=8000

case "$1" in
start)
sudo -u ${user} ${script_path}/seafile.sh start >> ${seafile_init_log}
if [ $fastcgi = true ];
then
sudo -u ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log}
else
sudo -u ${user} ${script_path}/seahub.sh start >> ${seahub_init_log}
fi
;;
restart)
sudo -u ${user} ${script_path}/seafile.sh restart >> ${seafile_init_log}
if [ $fastcgi = true ];
then
sudo -u ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log}
else
sudo -u ${user} ${script_path}/seahub.sh restart >> ${seahub_init_log}
fi
;;
stop)
sudo -u ${user} ${script_path}/seafile.sh $1 >> ${seafile_init_log}
sudo -u ${user} ${script_path}/seahub.sh $1 >> ${seahub_init_log}
;;
*)
echo "Usage: /etc/init.d/seafile {start|stop|restart}"
exit 1
;;
esac

Note: If you want to start seahub in fastcgi, just change the fastcgi variable to true.

Note: If you deployed Seafile with MySQL, append “mysql” to the Required-Start line: # Required-Start: $local_fs $remote_fs $network mysql

Add Directory for Logfiles:

sudo mkdir /media/usbhdd/seafile/logs

Make the seafile-sever script executable:

sudo chmod +x /etc/init.d/seafile-server

Add seafile-server to rc.d

sudo update-rc.d seafile-server defaults

Done.

PS:
https://raspberry-hosting.com/en/faq/how-install-apache2-php-fpm-raspberry-pi

Advertisements

One thought on “Install Seafile on Raspian, Raspberry Pi”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s