Install Seafile with nginx on Ubuntu 16.04

Seafile is a cross-platform file hosting tool with server applications for Linux and Windows, and GUI clients for Android, iOS, Linux, OS X and Windows. It supports file versioning and snapshots, two-factor authentication, WebDAV, and can be paired with nginx or Apache to enable connections over HTTPS.

Seafile has two editions: a free and open source Community Edition and a paid Professional edition. While the Pro edition is free for up to 3 users, this guide will use Seafile Community Edition with nginx serving an HTTPS connection, and MySQL on the backend. This application stack could also benefit from large amounts of disk space, so consider using our Block Storage service with this setup.

Prepare Ubuntu

Note

This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you’re not familiar with the sudo command, see the Linux Users and Groups guide.

Update the system:

apt update && apt upgrade

Create a standard user account with root privileges. As an example, we’ll call the user sfadmin:

adduser sfadmin
adduser sfadmin sudo

Log out of your Linode’s root user account and back in as sfadmin:

exit
ssh sfadmin@<your_linode's_ip>

You should now be logged into your Linode as sfadmin. Use our Securing Your Server guide to harden SSH access.

Set up UFW rules. UFW is Ubuntu’s iptables controller which makes setting up firewall rules a little easier. For more info on UFW, see our guide Configure a Firewall with UFW. Set the allow rules for SSH and HTTP(S) access with:

If you don’t want UFW allowing SSH on port 22 for both IPv4 and IPv6, you can delete it. For example, you can delete the rule to allow SSH over IPv6 with sudo ufw delete 4.

Set the Linode’s hostname. We’ll call it seafile as an example:

sudo hostnamectl set-hostname seafile

Add the new hostname to /etc/hosts. The second line in the file should look like this:

/etc/hosts

1

127.0.1.1 members.linode.com seafile

On first boot, your Linode’s timezone will be set to UTC. Changing this is optional, but if you wish, use:

sudo dpkg-reconfigure tzdata

Install and Configure MySQL

During Installation, you will be asked to assign a password for the root mysql user. Be sure to install the package mysql-server-5.7, not mysql-server. This is because an upstream issue causes problems starting the MySQL service if you install by using the mysql-server package.

Create a TLS Certificate for use with nginx

If you don’t already have an SSL/TLS certificate, you can create one. This certificate will be self-signed, and will cause web browsers to protest about a non-private connection. You should verify the SHA256 fingerprint of the certificate in the browser versus that on the server, and add a permanent exception to the browser to trust this certificate.

Change to the location where we’ll store the certificate files and create server’s certificate with key:

Run the nginx configuration test and restart the web server. If the test fails, it will give you a brief description of what’s wrong so you can troubleshoot the problem.

sudo nginx -t
sudo systemctl restart nginx

Configure and Install Seafile

The Seafile manual advises to use a particular directory structure to ease upgrades. We’ll do the same here, but instead of using the example haiwen directory found in the Seafile manual, we’ll create a directory called sfroot in the sfadmin home folder.

mkdir ~/sfroot && cd ~/sfroot

Download the Seafile CE 64 bit Linux server. You’ll need to get the exact link from seafile.com. Once you have the URL, use wget to download it to ~/sfadmin/sfroot.

You’ll be prompted to answer several questions and choose settings during the installation process. For those that recommend a default, use that.

Start the server.

./seafile.sh start
./seahub.sh start-fastcgi

The seahub.sh script will set up an admin user account used to log into Seafile. You’ll be asked for a login email and to create a password.

Seafile should now be accessible from a web browser using both your Linode’s IP address or the server_name you set earlier in nginx’s seafile.conf file. Nginx will redirect to HTTPS and as mentioned earlier, your browser will warn of an HTTPS connection which is not private due to the self-signed certificate you created. Once you tell the browser to proceed to the site anyway, you’ll see the Seafile login.

Automatically Start Seafile on Sever Bootup

The seafile.sh and seahub.sh scripts don’t automatically run if your Linode were to reboot.

Confirm the startup scripts are working by rebooting your Linode. After bootup, both the Seafile and Seahub services should be active when running the status commands in the previous step. You should also still be able to access Seafile with a web browser.

Updating Seafile

There are various ways to update Seafile depending on if you are upgrading from one milestone to another (version 5 to 6), or upgrading between point releases (5.1.0 to 5.1.1). See the Seafile Manual for upgrade instructions that best suit your needs.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.