Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Debian 8 - Install Seafile Server 6.x

This is a "refresh" of my previous tutorial on setting up a seafile server on Debian 7 (somehow I missed 8). Some things have changed, like the ability to use ffmpeg to genereate thumbnails for video files, but it's mostly the same.

Installation

Update And Install Packages

Run the following commands:

sudo apt update && sudo apt dist-upgrade -y

sudo apt-get install -y \
  python2.7 \
  python-setuptools \
  python-imaging \
  python-ldap \
  python-mysqldb \
  python-urllib3 \
  python-simplejson \
  python-memcache \
  python-pip

FFmpeg and MoviePY

The seafile manual states that if you upgrade from 6.0 and you'd like to use the feature video thumbnail, you need to install FFmpeg, as well as the pillow and moviepy packages. Unfortunately, I have not been able to fingure out how to get moviepy installed successfully on Debian 8, but will update this if I ever do figure it out. Luckily this functionality is optional so we will skip it for now.

Install MySQL Database

If you have a MySQL or MariaDB database already deployed that you wish to use, just skip this section.

The Seafile docs don't appear to specify which versions of MySQL should be used, but I'm pretty sure it will work perfectly well with any version higher than 5.5 or even a MariaDB alternative. If you are unsure, use my guide to install MySQL 5.6 on Debian 8. I have other servers deployed that are using it, so I know it works.

Download And Install Seafile

cd $HOME
wget https://download.seadrive.org/seafile-server_6.2.5_x86-64.tar.gz

# extract the download
tar --extract --gzip --file seafile-server*

# remove the compressed file
rm seafile-server*.tar.gz

Create Seafile Database And User

Login to your database with your root user and run the following queries in order to create the seafile database and user.

CREATE DATABASE `seafile`;
GRANT ALL on seafile.* to seafile@localhost identified by 'mySeafileUserPasswordHere';
exit;

Be sure to change the mySeafileUserPasswordHere text for the password to something else!

Run The Setup Script

cd seafile-server-*
/bin/bash setup-seafile-mysql.sh

Install Nginx

The seafile manual wants us to install nginx 1.8+ but unfortunately, if you just install the nginx package as-is, you will get version 1.6.2, so follow this tutorial on installing the later version from dotdeb.

Configure Seahub To Use Nginx

sudo rm /etc/nginx/sites-enabled/default
sudo touch /etc/nginx/sites-available/seafile.conf
sudo ln -s /etc/nginx/sites-available/seafile.conf /etc/nginx/sites-enabled/seafile.conf

Copy/paste the following chunk into the file at /etc/nginx/sites-enabled/seafile.conf.

server {
    listen 80;
    server_name seafile.example.com;

    proxy_set_header X-Forwarded-For $remote_addr;

    location / {
         proxy_pass         http://127.0.0.1:8000;
         proxy_set_header   Host $host;
         proxy_set_header   X-Real-IP $remote_addr;
         proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header   X-Forwarded-Host $server_name;
         proxy_read_timeout  1200s;

         # used for view/edit office file via Office Online Server
         client_max_body_size 0;

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

# If you are using [FastCGI](http://en.wikipedia.org/wiki/FastCGI),
# which is not recommended, you should use the following config for location `/`.
#
#    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   REMOTE_ADDR         $remote_addr;
#          fastcgi_read_timeout 36000;
#
#         client_max_body_size 0;
#
#         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;
        proxy_request_buffering off;
        client_max_body_size 0;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_connect_timeout  36000s;
        proxy_read_timeout  36000s;
        proxy_send_timeout  36000s;

        send_timeout  36000s;
    }
    location /media {
        root /full/path/to/seafile-server-latest/seahub;
    }
}

Make sure to change seafile.example.com to whatever your server's hostname is, and replace /full/path/to/seafile-server-latest/seahub (towards the bottom), with the relevant path.

Now reload nginx:

sudo nginx -s reload

Change Seafile Settings To Use Nginx

Navigate to your conf directory.

cd $HOME/conf

Now edit your ccnet.conf file so that the SERVICE_URL no longer has the :8000. For example:

SERVICE_URL = http://seafile.mydomain.com

Now edit your seahub_settings.py file and add the following line (changing it for whatever your server's hostname is):

FILE_SERVER_ROOT = 'http://seafile.mydomain.com/seafhttp'

Start/Stop Scripts

Copy/paste the following script for starting seafile somewhere that you will find it and can execute it. E.g. I stick it at $HOME/start-seafile.sh.

/bin/bash $HOME/seafile-server-latest/seafile.sh start
/bin/bash $HOME/seafile-server-latest/seahub.sh start

Copy/paste the following script for stopping seafile somewhere that you will find it and can execute it. E.g. I stick it at $HOME/stop-seafile.sh.

/bin/bash $HOME/seafile-server-latest/seafile.sh stop
/bin/bash $HOME/seafile-server-latest/seahub.sh stop

Start Seafile

Run the script to start seafile. Since this is the first time you have started seafile, you will be promped for the admin's email address and password. This will be the login credentials for the first administrator in the system.

Once seafile has started, you should be able to connect to it in your browser at the hostname, and also be able to connect to it using the client.

Block Off Port 8000

I was having issues with my Seafile server becoming unresponsive until I made sure to use my firewall to block off port 8000. It appears if anyone connects directly rather than through the reverse proxy, your seafile server can become unresponsive so be sure to block off port 8000 to the outside world.

Optional - Add Memcached

I am pretty sure I have got something wrong with these instructions for setting up memcached for seafile 6.2, but mostly there. I would recommend combining these instructions with the official docs.

Stop seafile if its running

/bin/bash $HOME/seafile-server-latest/seafile.sh stop
/bin/bash $HOME/seafile-server-latest/seahub.sh stop

Install the necessary packages

sudo apt-get install libz-dev -y
sudo apt-get install python2.7-dev -y
sudo apt-get install libmemcached-dev memcached -y
sudo apt-get install python-pylibmc -y

sudo pip install --upgrade pylibmc
sudo pip install django-pylibmc

Now edit your seahub_settings.py configuration file.

vim conf/seahub_settings.py

Add/Append the following:

CACHES = {
    'default': {
        'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
        'LOCATION': '127.0.0.1:11211',
    },
    'locmem': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    },
}
COMPRESS_CACHE_BACKEND = 'locmem'

Start seafile

/bin/bash $HOME/seafile-server-latest/seafile.sh start
/bin/bash $HOME/seafile-server-latest/seahub.sh start

Conclusion

You now have a seafile server running that uses a MySQL database and an Nginx webserver. In future we will show you how to set up memcached and SSL certificates.

References

Last updated: 2nd September 2018
First published: 29th August 2018

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch