Setup Seafile Server on Ubuntu 16.04 | 18.04 | 18.10 with Nginx and MariaDB

For those who want to run Seafile platform with Nginx HTTP server, the steps below should be a great place to start. Our previous tutorial showed you how to run it with Apache2.

Seafile is a true open source, self-hosted cloud storage service with high performance and reliability that you host in your own environment on your own private servers.

Like Dropbox and other cloud storage services, Seafile provides similar functions and unlike the other proprietary storage providers, Seafile is free to use… For those who have tried OwnCloud, NextCloud and other storage services and they’re still not sold, they may want to try Seafile instead.

Seafile enables private cloud services on users’ own servers. It’s a self-hosted file sync and share app platforms and with it you can access & sync your files, contacts and data across your devices.

This brief tutorial is going to show students and new users how to install Seafile on with Nginx and MariaDB support on Ubuntu 16.04 | 18.04  and 18.10 servers.

To get started with installing Seafile, follow the steps below:

Step 1: Install Nginx HTTP Server on Ubuntu

Nginx HTTP Server is probably the second most popular web server in use. so install it since Seafile needs it.

To install Nginx HTTP on Ubuntu server, run the commands below.

sudo apt update
sudo apt install nginx

After installing Nginx, the commands below can be used to stop, start and enable Nginx service to always start up with the server boots.

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

To test Nginx setup, open your browser and browse to the server hostname or IP address and you should see Nginx default test page as shown below. When you see that, then Nginx is working as expected.

nginx default home page test

Step 2: Install MariaDB Database Server

MariaDB database server is a great place to start when looking at open source database servers to use with Seafile. To install MariaDB run the commands below.

sudo apt-get install mariadb-server mariadb-client

After installing MariaDB, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots.

Run these on Ubuntu 16.04 LTS

sudo systemctl stop mysql.service
sudo systemctl start mysql.service
sudo systemctl enable mysql.service

Run these on Ubuntu 18.04 and 18.10 LTS

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

After that, run the commands below to secure MariaDB server by creating a root password and disallowing remote root access.

sudo mysql_secure_installation

When prompted, answer the questions below by following the guide.

  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]:  Y
  • Reload privilege tables now? [Y/n]:  Y

Next, run the commands below to open MariaDB default config file…

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Then add the lines below and save…

innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_file_per_table = 1
innodb_default_row_format = dynamic

Restart MariaDB server

To test if MariaDB is installed, type the commands below to logon to MariaDB server

sudo mysql -u root -p

Then type the password you created above to sign on. if successful, you should see MariaDB welcome message

mariadb welcome

Step 3: Install Seafile Dependencies

There are some dependencies that must be installed and available for Seafile to function. to get those installed, run the commands below.

sudo apt install python2.7 libpython2.7 python-setuptools python-pil python-ldap python-urllib3 ffmpeg python-pip python-mysqldb python-memcache python-requests

Step 4: Create Seafile Database

Now that you’ve installed all the packages that are required for Seafile to function, continue below to start configuring the servers. First run the commands below to create a blank Seafile database.

To logon to MariaDB database server, run the commands below.

sudo mysql -u root -p

Then create a database called seafiledb, ccnetdb, seahubdb

CREATE DATABASE seafiledb default CHARACTER set utf8 default COLLATE utf8_general_ci;
CREATE DATABASE ccnetdb default CHARACTER set utf8 default COLLATE utf8_general_ci;
CREATE DATABASE seahubdb default CHARACTER set utf8 default COLLATE utf8_general_ci;

Create a database user called seafileuser with new password

CREATE USER 'seafileuser'@'localhost' IDENTIFIED BY 'new_password_here';

Then grant the user full access to the databases created above.

GRANT ALL ON seafiledb.* TO 'seafileuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;
GRANT ALL ON ccnetdb.* TO 'seafileuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;
GRANT ALL ON seahubdb.* TO 'seafileuser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;

Finally, save your changes and exit.

FLUSH PRIVILEGES;
EXIT;

Step 5: Download Seafile Latest Release

When you’re ready, run the commands below to download Seafile installer. At the time of this writing, the latest version is 6.3.4.

cd /tmp
wget 
tar -xvzf seafile-server_7.0.5_x86-64.tar.gz.tar.gz
sudo mv seafile-server_7.0.5_x86-64 /var/www/html/seafile

After that, run the commands below to configure Seafile.

cd /var/www/html/seafile
sudo ./setup-seafile-mysql.sh

Doing that should prompt you to enter the database connection info you created above and setup your environment.

-----------------------------------------------------------------
This script will guide you to setup your seafile server using MySQL.
Make sure you have read seafile server manual at

        

Press ENTER to continue
-----------------------------------------------------------------
What is the name of the server? It will be displayed on the client.
3 - 15 letters or digits
[ server name ] Seafile

What is the ip or domain of the server?
For example: www.mycompany.com, 192.168.1.101
[ This server's ip or domain ] example.com

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

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 ] 2

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

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

Which mysql user to use for seafile?
[ mysql user for seafile ] seafileuser

What is the password for mysql user "seafileuser"?
[ password for seafileuser ] 

verifying password of user seafileuser .  done

Enter the existing database name for ccnet:
[ ccnet database ] ccnetdb

verifying user "seafileuser" access to database ccnetdb .  done

Enter the existing database name for seafile:
[ seafile database ] seafiledb

verifying user "seafileuser" access to database seafiledb .  done

Enter the existing database name for seahub:
[ seahub database ] seahubdb

verifying user "seafileuser" access to database seahubdb .  done

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

    server name:            Seafile
    server ip/domain:       example.com

    seafile data dir:       /var/www/html/seafile-data
    fileserver port:        8082

    database:               use existing
    ccnet database:         ccnetdb
    seafile database:       seafiledb
    seahub database:        seahubdb
    database user:          seafileuser

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

Generating ccnet configuration .

done
Successly create configuration dir /var/www/html/ccnet.
Generating seafile configuration .

Done.
done
Generating seahub configuration .

----------------------------------------
Now creating seahub database tables .

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

creating seafile-server-latest symbolic link .  done

-----------------------------------------------------------------
Your seafile server configuration has been finished successfully.
-----------------------------------------------------------------

run seafile server:     ./seafile.sh { start | stop | restart }
run seahub  server:     ./seahub.sh  { start  | stop | restart  }

-----------------------------------------------------------------
If you are behind a firewall, remember to allow input/output of these tcp ports:
-----------------------------------------------------------------

port of seafile fileserver:   8082
port of seahub:               8000

When problems occur, Refer to

        

for information.

You need to add a line in seahub_settings.py to set the value of FILE_SERVER_ROOT. You can also modify FILE_SERVER_ROOT via web UI in “System Admin->Settings”. (Warning: if you set the value both via Web UI and seahub_settings.py, the setting via Web UI will take precedence.)

FILE_SERVER_ROOT = 'http:/example.com/seafhttp'

Next, run the commands below to set the correct permissions for Seafile to function.

sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/

Step 6: Configure Nginx

Finally, configure Apahce2 site configuration file for Seafile. This file will control how users access Seafile content. Run the commands below to create a new configuration file called seafile

sudo nano /etc/nginx/sites-available/seafile

Then copy and paste the content below into the file and save it. Replace the highlighted line with your own domain name and directory root location.

server {
    listen 80;
    listen [::]:80;
    root /var/www/html/seafile;
    server_name  example.com www.example.com;

     client_max_body_size 100M;
  
     autoindex off;

     access_log /var/log/nginx/example.com.access.log;
     error_log /var/log/nginx/example.com.error.log;

     location / {
            proxy_pass         
            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;
        }

     location /seafhttp {
            rewrite ^/seafhttp(.*)$ $1 break;
            proxy_pass 
            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 /var/www/html/seahub;
        }
}

Save the file and exit.

Step 7: Enable the Seafile Site

After configuring the VirtualHost above, enable it by running the commands below

sudo ln -s /etc/nginx/sites-available/seafile /etc/nginx/sites-enabled/
sudo systemctl restart nginx.service

Run the commands below to start and stop Seafile inside Seafile home directory at /var/www/html/seafile.

cd /var/www/html/seafile
sudo su -p -l www-data -s /bin/bash -c "./seafile.sh start"
sudo su -p -l www-data -s /bin/bash -c "./seafile.sh stop"

To create Seafile backend admin account, run the commands below to start seahub.

sudo su -p -l www-data -s /bin/bash -c "./seahub.sh start"

That should prompt you to create Seafile admin account.

LC_ALL is not set in ENV, set to en_US.UTF-8
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 ] [email protected]
What is the password for the admin account?
[ admin password ] 
Enter the password again:
[ admin password again ] 

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

Then open your browser and browse to the server domain name. You should see Seafile logon page.

Type in the admin account and password created above and login.

Seafile ubuntu install

That’s it! You can now begin using Seafile self storage service.

Seafile ubuntu setup

Congratulation! You have successfully installed Seafile on Ubuntu 16.04 | 18.04 and may work on upcoming 18.10.

You may also like the post below: