×


Configure Seafile for synching files

Seafile is a powerful self-hosted file sync tool which is used to share files within a server to enhance performance and reliability.


Configuring Seafile on your Ubuntu Server will help to sync files. To configure it, you need to create databases and install some dependencies which Seafile needs to function properly.

Here at Ibmi Media, we help our customers to perform Software Installations on their Server on a daily basis as part of our Server Management Services.

Now let us look into the ways to set up Seafile for file sharing on Ubuntu.

More about Seafile and how to use it to Sync  and share files on Ubuntu?

Seafile is an open-source, free to use file synchronization and sharing platform.

It makes sharing of files and folders easy via cross-platform syncing and password-protected links to files with expiration dates.

In a Business sector, it also serves as a file collaboration solution which can help employees and teams work efficiently and securely with their organization's files and documents.

In this context, we shall install and configure Seafile on Ubuntu 18.04 machine. Also, we will use MariaDB for management of data for different components of Seafile as well as a web server such as Apache for web traffic handling.

After setting up, we will test it to use web interface so that users can access it via desktop or mobile clients for the syncing and sharing files with users or groups on the Server or with external systems.

Now let us create a Database for Seafile Components.

The process of creating Databases for Seafile

For Seafile to work, it requires three components as outlined below;

i. Seahub.

Seahub encompasses of the web interface which Seafile will run on. It is written in Python with the infrastructure of Django web framework. Via Seahub, you can access, manager, sync and share files from a web browser.

ii. Seafile Server.

This is the data service daemon for the management of file uploads, download and synchronization of files.

iii. Ccnet server.

This is a RPC service daemon which enables communication internally between the different components of Seafile. For instance, with Seahub, data is easily accessible from the Seafile server by means of the Ccnet RPC service.

These components stores data in separate batches within its own database. Here, we will create the MariaDB databases and a user as we prepare to set up the server.

Now, log into the server via an SSH tool such as putty by running the command below as per your server information;

ssh ibmimedia@your_server_ip


Once logged in, then you can make a connection to the MariaDB server as the root user. To do this, run the command below;

sudo mariadb


Next, enter the SQL statement below to create the database user as shown below;

MariaDB [(none)]> CREATE USER 'ibmimedia'@'localhost' IDENTIFIED BY 'password';


Now you can create the following databases to store the data of the Seafile components earlier described.

You can see what we mean below;


"ccnetdb" for the Ccnet server.
"seahubdb" for the Seahub web frontend.
"seafiledb" for the Seafile file server.

To create the databases using the MariaDB prompt, run the statements as shown below;

MariaDB [(none)]> CREATE DATABASE ccnetdb CHARACTER SET = 'utf8';
MariaDB [(none)]> CREATE DATABASE seafiledb CHARACTER SET = 'utf8';
MariaDB [(none)]> CREATE DATABASE seahubdb CHARACTER SET = 'utf8';


Next, grant all privileges to the Seafile database user to allow access and to be able to make changes to the created databases. To do this run the statements below;

MariaDB [(none)]> GRANT ALL PRIVILEGES ON ccnetdb.* to ibmimedia@localhost;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON seafiledb.* to ibmimedia@localhost;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON seahubdb.* to ibmimedia@localhost;


Now you can exit the MariaDB prompt by running the statement below;

exit


How to install the Dependencies which Seafile needs and Seafile Download process
Seafile is written in Python and requires some Python modules and packages to function properly.

Start by installing "pip" and "setuptools". In Debian, it is called "python3-pip" and "python3-setuptools" respectively.
To install it, run the apt command as shown below;

sudo apt install -y python3-pip python3-setuptools


This will get pip and setuptools installed on your server.

To install other packages such as Python package index (PyPI) by running the pip3 command as shown below;

pip3 install Pillow captcha django-simple-captcha


This will get "Pillow" which is a python library for image processing, captcha and django-simple-captcha installed which will enable captcha support for authentication.

Now create a new directory with name "seafile" and change into it. To do this run the commands below;

mkdir seafile
cd seafile


You can download Seafile latest version (7.1.4) via  the official resource by running the command below;

wget https://download.seadrive.org/seafile-server_7.1.4_x86-64.tar.gz


This is a compressed tar archive which you must extract before continuing with the installation process. Now extract the archive via tar by running the command below;

tar -zxvf seafile-server_7.1.4_x86-64.tar.gz


Now change into the extracted directory as shown below;

cd seafile-server-7.1.4


How to configure Seafile Server?

To set up Seafile, you need to have a domain name as well as the database configuration information. You can run the "setup_seafile_mysql.sh" script which is included in the extracted archive by running the bash script as shown below;

bash setup-seafile-mysql.sh


This script will prompt a series of questions to enter information as per your requirements such as the MariaDB database information where you can use the previously created Seafile databases like ccnetdb, seafiledb, and seahubdb.
Once the database connection is successful, you can now proceed with the configuration of Apache web server.

How to Configure Apache Web Server for Seafile?

We need to configure Apache web server to forward all requests to Seafile. This will enable us use HTTPS connections, Caching functionalities for better performance.

Start by enabling the "proxy_http" module for proxying HTTP and HTTPS requests. To enable this module, run the command below;

sudo a2enmod proxy_http


Also you need to enable Apache rewrite and ssl modules.

Next, you have to update the virtual host configuration of your domain to forward requests to the Seafile file server and to the Seahub web interface. To do this open the configuration file by running the command below;

sudo nano /etc/apache2/sites-enabled/your_domain-le-ssl.conf


Then take note of the lines from ServerAdmin to SSLCertificateKeyFile which are part of the initial Apache and Let's Encrypt configuration.

The file will look like this;

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName your_domain
ServerAlias www.your_domain
DocumentRoot /var/www/your_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

SSLCertificateFile /etc/letsencrypt/live/your_domain/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/your_domain/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf

Alias /media /home/sammy/seafile/seafile-server-latest/seahub/media
<Location /media>
Require all granted
</Location>

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

# seahub web interface
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
ProxyPass / http://127.0.0.1:8000/
ProxyPassReverse / http://127.0.0.1:8000/

</VirtualHost>
</IfModule>


Note that the Alias directive maps the URL path your_domain/media to a local path in the file system that Seafile uses. The following Location directive enables access to content in this directory.
The ProxyPass and ProxyPassReverse directives make Apache act as a reverse proxy for this host, forwarding requests to / and /seafhttp to the Seafile web interface and file server running on local host ports 8000 and 8082 respectively. The RewriteRule directive passes all requests to /seafhttp unchanged and stops processing further rules ([QSA,L]).

Now save and exit the file.

To test the file for syntax for errors, run the command below;

sudo apache2ctl configtest


If everything is fine, then you will get an output the the syntax is OK.

Next, restart Apache to effect changes made to Apache configuration file by running the command below;

sudo systemctl restart apache2


How to update Seafile's Configuration and Start its Services?

Since we are using Apache to proxy all requests to Seafile, we will need to update the URLs in Seafile’s configuration files in the conf directory using a text editor before we start the Seafile service.
Start by opening "ccnet.conf" file via the command below;

nano /home/ibmimedia/seafile/conf/ccnet.conf


In the file, modify the SERVICE_URL setting in the file to point to the new HTTPS URL without the port number. For instance, update /home/ibmimedia/seafile/conf/ccnet.conf. To do this, run the command below;

SERVICE_URL = https://your_domain


Note that "https://your_domain" should be replaced by your actual domain.

Now save and exit this file.

Next, open "seahub_settings.py" file by running the command below;

nano /home/ibmimedia/seafile/conf/seahub_settings.py


Now, we can add a FILE_SERVER_ROOT setting in the file to specify the path where the file server is listening for file uploads and downloads. To do this, Update /home/ibmimedia/seafile/conf/seahub_settings.py ;

SECRET_KEY = "..."
FILE_SERVER_ROOT = 'https://your_domain/seafhttp'


Now, you can start the Seafile service and the Seahub interface with the command below;

cd /home/bob/seafile/seafile-server-7.1.4
./seafile.sh start
./seahub.sh start


Since this is the first time we are working with Seahub service on the server, you will be prompted to create an admin account. Here enter a valid email address and a password for the admin user.

Then open your Seafile url (https://your_domain) in a web browser and log in using the Seafile admin email address and password.

As soon as you are logged in to Seafile web interface, you can play around the admin interface or create new users.

Additionally, we can enable these services to start automatically at system boot as shown below.

How to enable Seafile Server to start on system boot?

To enable the file server and the web interface to start automatically at boot, we can simply create the respective systemd service files and activate them.
To create a systemd service file for the Seafile file server, run the command below;

sudo nano /etc/systemd/system/seafile.service


Then add the following contents to the file;

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

[Service]
Type=forking
ExecStart=/home/ibmimedia/seafile/seafile-server-latest/seafile.sh start
ExecStop=/home/ibmimedia/seafile/seafile-server-latest/seafile.sh stop
User=ibmimedia
Group=ibmimedia

[Install]
WantedBy=multi-user.target


Now save a exit this file.

Then, you can enable both the Seafile and Seahub services to start automatically at boot by running the following commands below;

sudo systemctl enable seafile.service
sudo systemctl enable seahub.service


This will reboot the server and the Seafile service will start automatically.

How to test File Syncing and Sharing Functionality?

Now, we will test the file synchronization and sharing functionality of the server which we have configured to ensure that it is working correctly. To do this, we need to install a Seafile client program on a different computer or on a compatible mobile device.

Go to the download page on Seafile official website and follow the instructions there on how to install the latest version of the program on the computer.

After installing Seafile client, you can now test the file synchronization and sharing functionality.

Open the Seafile client program on the computer or device. Here, accept the default location for the Seafile folder and click Next.

In the next window, enter the server address, username, and password, then click Login.

On the home page, right click on My Library and click Sync this library. Accept the default value for the location on the computer or device.

Add a file, for instance a document or a photo, into the My Library folder. After some time, the file will upload to the server.

Now, log in to the web interface at https://your_domain and verify that the file is present on the server.

Click on Share next to the file to generate a download link for this file.

Need support to sync files via Seafile and to Set up Seafile on your Server? We are available to help you today.


Conclusion

This article will guide you on the steps to take in order to install and configure Seafile server for syncing of files, adding users and groups, and sharing files between them or with the public without relying on an external service.