Again, the precondition is a LEMP installation as described in this article: Installation of Nginx, MySQL and PHP
Seafile has a its own little web server, but it can not handle the HTTPS protocol. So, to get an encrypted transmission to the cloud, you have to run Seafile behind a "real" web server - in this case, nginx.

The installation is done in 4 steps:

  1. Seafile basic installation
  2. Setup Seafile with Https behind NginX
  3. Aktivate WebDAV
  4. Start Seafile at boot

But first create a certificate for the encryption, if that isn't done already!
For that create the folder /etc/ssl/nginx, change to that folder and create a self-signed certificate with:

mkdir /etc/ssl
mkdir /etc/ssl/nginx
cd /etc/ssl/nginx
openssl genrsa -out privkey.pem 2048
openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095

Step 1: Seafile basic installation
Seafile braucht Phython, daher werden jetzt die Notwendigen Pakete installiert.
Seafile needs Phython, so install the necessary packages.

apt-get install python2.7 python-setuptools python-simplejson python-imaging python-mysqldb

To run Seafile with NginX additionally install

apt-get install python-flup

To prevent Seafile running with root-privileges, the service gets its own user, such as the web server (www-data) or MySQL.
This is done with the command

adduser SEAFILE-USER --disabled-login 

The name SEAFILE-USER is freely selectable. By the --disabled-login option, the user gets no password and can not log in from outside the system. It is an internal system user.

After these preparations we can now begin to install Seafile. On the Seafile page is recommended that you install Seafile in the resulting folder under /home/. A different installation directory, such as /opt/seafile/ or /var/seafile/ is equally possible.
I assume that Seafile is to be installed in the folder /home/SEAFILE-USER.
So change to the directory with

cd /home/SEAFILE-USER

Now you should become SEAFILE-USER with

su - SEAFILE-USER

Now download the package for the Raspberry Pi from the Seafile-Server with

wget https://github.com/haiwen/seafile-rpi/releases/download/VERSION/seafile-server_VERSION_pi.tar.gz

Extract the downloaded file with

tar -zxvf seafile-server_VERSION_pi.tar.gz

To start the basic installation of Seafile, change to the Seafile-directory and start the setup script for MySQL with

cd seafile-server_VERSION
./setup-seafile-mysql.sh

Here, among other things, the database setup is done and the ports of the servers are defined. If possible, simply use the the default ports.

What is the name of the server? It will be displayed on the client.
3 – 15 letters or digits
[ server name ] 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 ] www.yourdomain.com

——————————————————-
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

What is the host of mysql server?
[ default “localhost” ] je nach Konfiguration

What is the port of mysql server?
[ default “3306” ] je nach Konfiguration

What is the password of the mysql root user?
[ root password ] je nach Konfiguration

verifying password of user root … done

Enter the name for mysql user of seafile. It would be created if not exists.
[ default “root” ] seafileusr (zum Beispiel)

Enter the password for mysql user “seafileusr”:
[ password for seafileusr ] Passwort für den neuen Benutzer “seafileusr”

———————————
This is your configuration
———————————
[…]
———————————
Press ENTER to continue, or Ctrl-C to abort
———————————
Enter
—————————————————————–
Your seafile server configuration has been finished successfully.

Now the basic installation is done. OK - almost ..

Start the server once with

/home/SEAFILE-USER/seafile-server-latest/seahub.sh start

At the first start an administrator account is created. For this purpose, enter in the following queries your email address and set a password.

----------------------------------------
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 ] email@example.org

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

Enter the password again:
[ admin password again ] 



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



Loading ccnet config from /home/SEAFILE-USER/ccnet
Loading seafile config from /home/SEAFILE-USER/seafile-data

Seahub is started

Done.

Thats important, because seafile won't start automatically later without that.

Step 2: Setup Seafile with Https behind NginX

For that first 2 files need to be adjusted

1. ccnet.conf
Adjust the parameter "SERVICE_URL" in the file ccnet/ccnet.conf:

nano /home/SEAFILE-USER/ccnet/ccnet.conf 
     .
     .
SERVICE_URL = https://www.yourdomain.com

2. seahub_settings.py
Adjust the parameter "FILE_SERVER_ROOT" in the file seahub_settings.py:

nano /home/SEAFILE-USER/seahub_settings.py
     .
     .
FILE_SERVER_ROOT = 'https://www.yourdomain.com/seafhttp'

Now, a new virtual host for the cloud is generated for nginx. For this, create a new file in the folder /etc/nginx/sites-available, eg myCloud

nano /etc/nginx/sites-available/myCloud


server {
   listen 443;
   ssl on;
   ssl_certificate /etc/ssl/nginx/cacert.pem;        # path to your cacert.pem
   ssl_certificate_key /etc/ssl/nginx/privkey.pem;   # path to your privkey.pem
   
   server_name www.yourdomain.com;    
   location / {
       fastcgi_pass    127.0.0.1:8000;
       fastcgi_param   SCRIPT_FILENAME     $document_root$fastcgi_script_name;
       fastcgi_param   PATH_INFO           $fastcgi_script_name;

       fastcgi_param   SERVER_PROTOCOL       $server_protocol;
       fastcgi_param   QUERY_STRING        $query_string;
       fastcgi_param   REQUEST_METHOD      $request_method;
       fastcgi_param   CONTENT_TYPE        $content_type;
       fastcgi_param   CONTENT_LENGTH      $content_length;
       fastcgi_param   SERVER_ADDR         $server_addr;
       fastcgi_param   SERVER_PORT         $server_port;
       fastcgi_param   SERVER_NAME         $server_name;
       fastcgi_param   HTTPS               on;
       fastcgi_param   HTTP_SCHEME         https;

       access_log      /var/log/nginx/seahub.access.log;
       error_log       /var/log/nginx/seahub.error.log;
   }       
   
   location /seafhttp {
       rewrite ^/seafhttp(.*)$ $1 break;
       proxy_pass http://127.0.0.1:8082;
       client_max_body_size 0;
   }
   
   location /media {
       root /home/SEAFILE-USER/seafile-server-latest/seahub;
   }
}

Here the server_name, the paths to the SSL-certificates and the path to location /media need to be adapted to your specific installation.
Activate this configuration with a symbilic link in the folder /etc/nginx/sites-enabled

ln -s /etc/nginx/sites-available/mycloud /etc/nginx/sites-enabled

Step 3: Activate WebDAV

By default, the WebDAV interface is disabled in Seafile. But in order to mount the files of the cloud on a local computer or tablet without synchronizing the files, you need the activated WebDAV interface.

To activate it, you have to make changes in the /home/SEAFILE-USER/conf/seafdav.conf file.

nano /home/SEAFILE-USER/conf/seafdav.conf

[WEBDAV]

# set this value to true
enabled = true

# The port is freely selectable, so choose any unused port
port = 9999

# Because Seafile is running behind NginX, fastcgi must be set to true
fastcgi = true

# Choose the Name for the cloud-folder
share_name = /myCloud

Add the following part to the NginX config-file for your cloud.
Be aware to set the fastcgi_pass to the port and the location to the share_name you selected in seafdav.conf

nano /etc/nginx/sites-available/myCloud 

location /myCloud {
  fastcgi_pass    127.0.0.1:9999;
  fastcgi_param   SCRIPT_FILENAME     $document_root$fastcgi_script_name;
  fastcgi_param   PATH_INFO           $fastcgi_script_name;

  fastcgi_param   SERVER_PROTOCOL     $server_protocol;
  fastcgi_param   QUERY_STRING        $query_string;
  fastcgi_param   REQUEST_METHOD      $request_method;
  fastcgi_param   CONTENT_TYPE        $content_type;
  fastcgi_param   CONTENT_LENGTH      $content_length;
  fastcgi_param   SERVER_ADDR         $server_addr;
  fastcgi_param   SERVER_PORT         $server_port;
  fastcgi_param   SERVER_NAME         $server_name;

  fastcgi_param   HTTPS               on;

  client_max_body_size 0;

  access_log      /var/log/nginx/seafdav.access.log;
  error_log       /var/log/nginx/seafdav.error.log;
}

Now you can access your files via WebDav under the address www.yourdomain.com/mycloud.

Step 4: Start Seafile during boot

Dafür wird jetzt jetzt noch eine neue Datei in dem Ordner /etc/init.d/ erstellt, z.B. meineCloud.
Dort den folgenden Inhalt einfügen und die Parameter user und seafile_dir an die eigene Installation anpassen.

For this create a new file in the folder /etc/init.d/, eg seafile.
There, insert the following content and adjust the parameters "user" and "seafile_dir" to your installation.

#!/bin/bash

### BEGIN INIT INFO
# Provides:          mathkernel
# Required-Start:    $local_fs 
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Seafile-Server
### END INIT INFO

# Change the value of "user" to your linux user name
user=SEAFILE-USER

# Change the value of "seafile_dir" to your path of seafile installation
seafile_dir=/home/SEAFILE-USER
script_path=${seafile_dir}/seafile-server-latest

# 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)
                su - ${user} ${script_path}/seafile.sh start 
                if [  $fastcgi = true ];
                then
                        su - ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} 
                else
                        su - ${user} ${script_path}/seahub.sh start 
                fi
        ;;
        restart)
                su - ${user} ${script_path}/seafile.sh restart 
                if [  $fastcgi = true ];
                then
                        su - ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} 
                else
                        su - ${user} ${script_path}/seahub.sh restart 
                fi
        ;;
        stop)
                su - ${user} ${script_path}/seafile.sh $1 
                su - ${user} ${script_path}/seahub.sh $1 
        ;;
        *)
                echo "Usage: /etc/init.d/seafile {start|stop|restart}"
                exit 1
        ;;
esac

Restart NginX with

/etc/init.d/nginx restart

and restart Seafile with

/etc/init.d/meineCloud restart

For starting Seafile at boot now, you can add the following line to the file /etc/rc.local

nano /etc/rc.local

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
     .
     .
     .

# start seafile-server
/etc/init.d/meineCloud start

exit 0

Be aware to insert the line in front of the "exit 0"

And that'it.

Add comment

Please insert your mail adress. Your mail address will not be displayed.