How to Install Seafile on Ubuntu 16.04 (Xenial Xerus)

Seafile is a private cloud such as Dropbox, mega.co.nz and others. Seafile is based on python and it is open source, so that you can create your own private cloud and it will be much more secure.

Seafile supports encryption libraries that make your data will be more secure. To encrypt files in a library, you need to set a password when you create the library. The password won't be stored on Seafile cloud. So even the administrator of the servers cannot view your encrypted data without the password.

This tutorial shows the installation of Seafile on Ubuntu 16.04.

Prerequisites

  • A Server with 2GB RAM
  • Ubuntu 16.04 64-bit

Installing Seafile

Step 1 - Install the necessary Dependencies

To perform the installation, the seafile need some dependencies:

  • openjdk-8jre
  • LibreOffice
  • Popler-utils
  • mysql-server
  • Python-pip and others.

apt-get install openjdk-8-jre poppler-utils libreoffice libreoffice-script-provider-python libpython2.7 python-pip mysql-server python-setuptools python-imaging python-mysqldb python-memcache ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy python-pip

Install boto with pip:

pip install boto

If you have error about locale setting, run all command below:

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales

Step 2 - Create a new "seafile" user

In this step, we will create a new user for the seafile installation. We will run the seafile server as this user.

Create new 'seafile' user for the installation.

useradd -m -s /bin/bash seafile
passwd seafile

Step 3 - Download and extract the Seafile archive

Seafile can be downloaded from the official site, please download according to your needs. Here I use Ubuntu 15.04 64-bit.

Download the Seafile archive with wget:

su - seafile
wget wget https://bintray.com/artifact/download/seafile-org/seafile/seafile-server_5.1.4_x86-64.tar.gz

Extract the seafile-server_5.1.4_x86-64.tar.gz and rename the directory to 'seafile-server'.

tar -xzf seafile-server_5.1.4_x86-64.tar.gz
mv seafile-server-5.1.4/ seafile-server/

So the directory for the seafile installation is on the seafile user home directory.

Step 4 - Create the Database

Seafile requires 3 databases:

  1. ccnet server
  2. seafile server
  3. seahub

Now back to the root user with "exit", then login to your mysql server.

Create 3 databases with one user and grant the user to all databases.

#Login to mysql
mysql -u root -p
    
#Create database
create database ccnet_db character set = 'utf8';
create database seafile_db character set = 'utf8';
create database seahub_db character set = 'utf8';

#Create user
create user [email protected] identified by 'yourpassword';

#Grant user to the databases
grant all privileges on ccnet_db.* to [email protected] identified by 'yourpassword';
grant all privileges on seafile_db.* to [email protected] identified by 'yourpassword';
grant all privileges on seahub_db.* to [email protected] identified by 'yourpassword';
flush privileges;

Step 5 - Install Seafile

Login to the 'seafile' user and  go to the installation directory 'seafile-server/', there run the setup-seafile-mysql.sh file.

su - seafile
cd seafile-server/
./setup-seafile-mysql.sh

Just press Enter and you will be asked about:

  • Server Name - we will use seafile-server.
  • Domain/IP - cloud.mydomain.co.
  • Seafile data directory - default data directory
  • Seafile server port configuration.

Seafile install on Ubuntu

Then you will be asked for the database setup. You can choose number 2 because all database have been created in step 4.

Seafile Database ConfigurationSeafile database setup

Seafile is installed. Start seafile and the seahub server:

./seafile.sh start
./seahub.sh start

You will be asked about the admin email and password for seafile admin email and password.

Configure seafile admin

If the admin user has been created. Stop seafile now, next we will create a service file for the seafile server:

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

Step 6 - Configure Seafile and Seahub Service files

Next, we will configure seafile and seahub services. We will create new service files for the seafile and seahub server.

As root user, go to the '/lib/systemd/system/' directory and create a new seafile service file 'seafile-server.service' with vim editor:

cd /lib/systemd/system/
vim seafile.service

Paste seafile service configuration below:

[Unit]
Description=Seafile Server
After=network.target mariadb.service

[Service]
Type=oneshot
ExecStart=/home/seafile/seafile-server/seafile.sh start
ExecStop=/home/seafile/seafile-server/seafile.sh stop
RemainAfterExit=yes
User=seafile
Group=seafile

[Install]
WantedBy=multi-user.target

Save and exit.

Now create new seahub service file seahub.service:

vim seahub.service

Paste configuration below:

[Unit]
Description=Seafile Hub
After=network.target seafile.target

[Service]
Type=oneshot
ExecStart=/home/seafile/seafile-server/seahub.sh start-fastcgi
ExecStop=/home/seafile/seafile-server/seahub.sh stop
RemainAfterExit=yes
User=seafile
Group=seafile

[Install]
WantedBy=multi-user.target

Save and exit.

Reload the systemd service and start seafile and seahub:

systemctl daemon-reload
systemctl start seafile
systemctl start seahub

Make sure there is no error and check the seafile and seahub server is running by checking the service ports.

netstat -plntu

Seafile and seahub startedCheck that Seafile has been started.

You will see the seafile port 8002 and the seahub port 8000.

Step 7 - Install and Configure Nginx as Reverse Proxy

In this step, we will install nginx from the Ubuntu repository and then configure it as a reverse proxy server for seafile-server on port 8000 and 8002.

Install nginx with this apt-get command:

apt-get install nginx -y

When the installation is finished, go to the nginx virtual host directory and create a new virtual host file cloud.mydomain.conf with vim:

cd /etc/nginx/sites-available/
vim cloud.mydomain.conf

Paste virtual host configuration below:

server {
    listen 80;
    server_name cloud.mydomain.co;

    proxy_set_header X-Forwarded-For $remote_addr;

    # Reverse proxy for seafile
    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;

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

    # Reverse Proxy for seahub
    location /seafhttp {
        rewrite ^/seafhttp(.*)$ $1 break;
        proxy_pass http://127.0.0.1:8082;
        client_max_body_size 0;
        proxy_connect_timeout  36000s;
        proxy_read_timeout  36000s;
        proxy_send_timeout  36000s;
        send_timeout  36000s;
    }

    #CHANGE THIS PATH WITH YOUR OWN DIRECTORY
    location /media {
        root /home/seafile/seafile-server/seahub;
    }
}

Save and exit.

I will use 'cloud.mydomain.co' as the domain name.

Next, enable the new virtual host by creating a link to the 'sites-enabled' directory and restart nginx.

Enable new virtual host:

ln -s /etc/nginx/sites-available/cloud.mydomain.co

Test and restart the nginx web server.

nginx -t
systemctl restart nginx

Step 8 - Testing with the Web Browser

Open your browser cloud.mydomain.co and try to login with your admin account.

Login to seafile serverSeafile Login

Seafile admin dashboard:

Seafile has been startedseafile under nginx webserver

Conclusion

With the wide variety of cloud applications today, Seafile is a private cloud solution that is good for use on this day. With the encryption feature at the library/folder, you can make the data more secure. And also ease to configure it, make it easy to implement in your server.

Share this page:

8 Comment(s)

Add comment

Comments

From: Pete at: 2016-08-23 18:52:14

Why the java/jdk dependency? I'm not seeing **any** reason this would be needed.  Also, I'd use mariaDB over mysql every day of the week.

From: till at: 2016-08-24 06:24:59

Seafile requires Java for Elasticsearch only according to their website. If you don't use Elasticsearch, then you might be able to leave out the jdk dependency.

From: Justin Partain at: 2016-08-25 10:51:28

Honestly, at this time, you guys probably should refrain from posting anything about seafile, seeing as two different groups currently claim ownership over this program, thus making it nearly impossible to know which is the right code. From security to basic stability in the program, you never know whats going on until this dust settles.

From: libreman at: 2016-08-29 15:15:41

According Wikipedia the mayor issue has been solved: https://en.wikipedia.org/wiki/Seafile.

From: Henrik at: 2016-09-09 16:16:05

Great work!

But I don't know why "Step 6 - Configure Seafile and Seahub Service Files" doesn't work for me. Ubuntu 16.04. LTS. No errors shown, but seafile/seahub won't start at bootup automatically.

I tried "systemctl enable seafile-service" and "systemctl enable seahub-service" (is this part is missing in the manual?) but that doesn't help. 

Starting seafile.sh/seahub.sh manually works fine. 

Thank you! 

 

From: Merioz at: 2016-10-02 15:04:34

Hi,

I'm writing because I have the same problem of Henrik at "Step 6". 

From: Merioz at: 2016-10-08 08:09:12

I found the solution of the seafile startup

Modify "seafile.service" in this mode:

-----------------------------------------------------------------------------------

[Unit]

Description=Seafile Server

After=network.target mysql.service

 

[Service]

Type=oneshot

ExecStart=/home/seafile/seafile-server/seafile.sh start

ExecStop=/home/seafile/seafile-server/seafile.sh stop

RemainAfterExit=yes

User=seafile

Group=seafile

 

[Install]

WantedBy=multi-user.target

----------------------------------------------------------------------------------

And file "seahub.service" in this mode:

----------------------------------------------------------------------------------

[Unit]

Description=Seafile Hub

After=network.target seafile.service

 

[Service]

Type=oneshot

ExecStart=/home/seafile/seafile-server/seahub.sh start

ExecStop=/home/seafile/seafile-server/seahub.sh stop

RemainAfterExit=yes

User=seafile

Group=seafile

 

[Install]

WantedBy=multi-user.target

----------------------------------------------------------------------------

Reboot and enjoy!!

Thats all!!

From: Dunstan at: 2016-12-02 06:52:26

Merioz's and Henrik's problem is caused by an error in the description.

Description=Seafile HubAfter=network.target seafile.targetis bad, because seafile is a service, not a target. Please correct the line to

After=network.target seafile.service

and the automatic start will work.