How to Install and Set Up Seafile on Ubuntu 18.04

Seafile is a free, open-source and self-hosted storage service very similar to DropBox and NextCloud. With Seafile, you can sync and share files, contacts and data across any devices with password-protected links. It is written in Python language and uses MySQL to store data for the different components. Seafile can be installed on Linux and Windows operating system and GUI clients for OS X, Android, Linux, iOS and Windows.  Seafile comes with a rich set of features including, cross-platform, version control, Two-Factor Authentication, snapshots, WebDAV, encryption and many more.

In this tutorial, we will learn how to install and configure Seafile server on Ubuntu 18.04 server.

Prerequisites

  • A server running Ubuntu 18.04 server.
  • A root password set up on your server.

Getting Started

Let’s start by updating your system to the latest stable version. Run the following command to update your system:

# apt-get update -y
# apt-get upgrade -y

Once updated, restart your system to apply all the updates.

Next, you will need to install Python with all required dependencies on your server. You can install all of them by running the following command:

# apt-get install python2.7 libpython2.7 python-setuptools python-pil python-ldap python-urllib3 ffmpeg python-pip python-mysqldb python-memcache python-requests unzip wget

Once all the dependencies are installed, you can proceed to the next step.

Install Apache and MariaDB

First, you will need to install Apache and MariaDB to your server. You can install both with the following command:

# apt-get install apache2 mariadb-server mariadb-client -y

Once both packages are installed, start Apache and MariaDB service and enable them to start after system reboot with the following command:

# systemctl start apache2
# systemctl enable apache2
# systemctl start mariadb
# systemctl enable mariadb

Once you have done, you can proceed to the next step.

Configure Database for Seafile

Next, you will need to create databases for the Seafile components. First, log in to MariaDB shell with the following command:

# mysql -u root -p

Provide your root password when prompt then create three database with the following command:

# MariaDB [(none)]> CREATE DATABASE seafile;
# MariaDB [(none)]> CREATE DATABASE ccnet;
# MariaDB [(none)]> CREATE DATABASE seahub;

Next, create a user for Seafile with the following command:

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

Next, grant all the privileges to the databases created above:

# MariaDB [(none)]> GRANT ALL ON seafile.* TO 'seafile'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
# MariaDB [(none)]> GRANT ALL ON ccnet.* TO 'seafile'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
# MariaDB [(none)]> GRANT ALL ON seahub.* TO 'seafile'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

Next, flush the privileges and exit from the MariaDB shell with the following command:

# MariaDB [(none)]> FLUSH PRIVILEGES;
# MariaDB [(none)]> EXIT;

Once you have done, you can proceed to the next step.

Install Seafile

First, you will need to download the latest version of Seafile installer from their official website. You can download it with the following command:

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

Once downloaded, extract the downloaded file with the following command:

# tar -xvzf seafile-server_7.0.4_x86-64.tar.gz

Next, copy the extracted directory to the Apache root directory with the following command:

# cp -r seafile-server-7.0.4 /var/www/html/seafile

Next, run the Seafile installer script to start the installation:

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

During the installation, you will need to answer a series of questions.

Checking python on this machine …

Checking python module: python-mysqldb … Done.

—————————————————————–

This script will guide you to setup your seafile server using MySQL.

Make sure you have read seafile server manual at

https://github.com/haiwen/seafile/wiki

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

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

What is the password for mysql user “seafile”?

[ password for seafile ]

verifying password of user seafile …  done

Enter the existing database name for ccnet:

[ ccnet database ] ccnet

verifying user “seafile” access to database ccnet …  done

Enter the existing database name for seafile:

[ seafile database ] seafile

verifying user “seafile” access to database seafile …  done

Enter the existing database name for seahub:

[ seahub database ] seahub

verifying user “seafile” access to database seahub …  done

———————————

This is your configuration

———————————

server name:            seafile

server ip/domain:       38.143.68.184

 

seafile data dir:       /var/www/html/seafile-data

fileserver port:        8082

 

database:               use existing

ccnet database:         ccnet

seafile database:       seafile

seahub database:        seahub

database user:          seafile

———————————

Press ENTER to continue, or Ctrl-C to abort

Verify all the configuration and press ENTER to continue the installation. Once the installation has been completed successfully, you should see the following output:

—————————————————————–

Your seafile server configuration has been finished successfully.

—————————————————————–

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

run seahub  server:     ./seahub.sh  { start <port> | stop | restart <port> }

—————————————————————–

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

—————————————————————–

port of seafile fileserver:   8082

port of seahub:               8000

Ir a problem occurs, refer to:

https://github.com/haiwen/seafile/wiki

for information.

Next, set the correct permissions for Seafile with the following command:

# chown -R www-data:www-data /var/www/html/

Next, you will need to set the value of FILE_SERVER_ROOT. You can do it by editing seahub_settings.py file:

 nano /var/www/html/conf/seahub_settings.py 

Add the following line:

 FILE_SERVER_ROOT = 'http://38.143.68.184/seafhttp'

Save and close the file when you are finished.

Configure Apache for Seafile

Next, you will need to configure Apache as a reverse proxy for Seafile. You can do it by creating the following file:

 nano /etc/apache2/sites-available/seafile.conf 

Add the following lines:

<VirtualHost *:80>;

ServerAdmin [email protected]

DocumentRoot /var/www/html/seafile/

ServerName 38.143.68.184
Alias /media "/var/www/html/seahub/media"
 <Directory /var/www/html/seafile/>
Options +FollowSymlinks
AllowOverride All
Require all granted
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/html/seafile
SetEnv HTTP_HOME /var/www/html/seafile
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://127.0.0.1:8000/
ProxyPassReverse / http://127.0.0.1:8000/
ProxyPass /seafhttp http://127.0.0.1:8082
ProxyPassReverse /seafhttp http://127.0.0.1:8082
RewriteRule ^/seafhttp - [QSA,L] 
<VirtualHost>

Save and close the file. Then, enable the Seafile virtual host file and other required modules with the following command:

# a2ensite seafile.conf
# a2enmod rewrite
# a2enmod proxy
# a2enmod proxy_http
# a2enmod headers
# a2enmod env
# a2enmod dir
# a2enmod mime

Finally, restart Apache service to load all the settings:

# systemctl restart apache2

Create Admin User for Seafile

Next, you will need to create an admin user and set a password for it.

First, start the Seafile service with the following command:

# su -p -l www-data -s /bin/bash -c "./seafile.sh start"

Next, start Seahub service to create admin account with the following command:

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

You will be prompted to create an admin account as shown below:

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

—————————————-

Seahub is started

Done.

Create Systemd Service file for Seafile and Seahub

Next, you will need to create a systemd service file to manage Seafile and Seahub service.

First, create a seafile service file with the following command:

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

Add the following lines:

[Unit]
Description=Seafile
After= mysql.service
After=network.target
[Service]
User=www-data
Group=www-data[/php

Type=forking
ExecStart=/var/www/html/seafile-server-latest/seafile.sh start
ExecStop=/var/www/html/seafile-server-latest/seafile.sh stop
[Install]
WantedBy=multi-user.target 

Save and close the file. Then, create a systemd service file for Seahub with the following command:

# nano /etc/systemd/system/seahub.service

Add the following lines:

[Unit]
Description=Seafile
After= mysql.service
After=network.target
 [Service]
User=www-data
Group=www-data
Type=forking
ExecStart=/var/www/html/seafile-server-latest/seahub.sh start
ExecStop=/var/www/html/seafile-server-latest/seahub.sh stop
[Install]
WantedBy=multi-user.target

Save and close the file. Then, reload the systemd daemon with the following command:

# systemctl daemon-reload

Next, restart Seafile and Seahub service and enable them to start after system reboot with the following command:

# systemctl restart seafile
# systemctl enable seafile
# systemctl restart seahub
# systemctl enable seahub

Access Seafile Web Interface

Now, open your web browser and type the URL http://your-server-ip. You will be redirected to the Seafile login page:

Provide your admin username and password, and click on the Log in button. You should see the Seafile default dashboard in the following screen:

Congratulations! you have successfully installed and configured Seafile server on Ubuntu 18.04 server.

You can now share files, contacts and data with any users 🙂

To write a comment on this article, fill out the form below. Fields marked with an asterisk (*) are required.