How to Install a Seafile Server to Run a Private Cloud

1891

Cloud is a buzzword these days; everyone is moving to the cloud even if most of us don’t even know what it actually means. To me, cloud is a fictional place that processes and stores my data; in the process it liberates me from that one device where my data is stored. With ‘Cloud’ I can access my data from any networked device.

What actually happens is that my data moves from my local machine to a remote machine or a remote cluster of machines – the storage and processing of the data happens at those machines.

This ‘movement’ of data changes things dramatically. If I don’t ‘own’ those remote machines, the one who does also becomes the ‘co-owner’ of my data. The ‘co-owner’ will scan my private data to see if it infringes upon any copyrights and it may block access to my own data for numerous, unclear reasons.

There was one incident where Microsoft allegedly blocked a user from accessing their own data after the company found some objectionable content in the user’s private folder. I wonder what Microsoft was doing in a private folder?

The point is, I don’t trust third party cloud providers, and cases like these further reinforce my belief to not trust them.

That’s why I keep all of my private data on a cloud that I run and own. I have used a couple of open source file sync and storage solutions, including ownCloud, and recently came to know about Seafile which is quickly becoming my favorite.

A few weeks ago I installed Seafile on my server and made it my primary cloud. Since open source is all about sharing, let’s share the procedure I followed to install Seafile on a server.

My server

I am running Seafile on a Virtual Private Server (VPS) running fully patched Ubuntu 14.04. So get yourself an Ubuntu or Debian machine and let’s get started.

Step #1 Install and secure MariaDB

I don’t use MySQL and heavily recommend MariaDB. To get the latest version of MariaDB, which is 10.x (I don’t recommend 5.x branch) on Ubuntu, you need to enable extra repositories. Check out this page to get instructions for adding the appropriate repository for your OS. Since I am using Ubuntu 14.04 I added the repo through following steps:

sudo apt-get install software-properties-common
sudo apt-key adv –recv-keys –keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository ‘deb http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.0/ubuntu trusty main’

Update the repositories and install MariaDB:

sudo apt-get update
sudo apt-get install mariadb-server

During the installation, MariaDB will ask for a root password for the database, which is different from the system root password. Enter the desired password to proceed.

mariadb

Now we need to secure the database, but we need to kill the database server daemon before we proceed to the next step or you will encounter an error:

sudo killall mysqld

Now run the following command:

sudo mysql_install_db

Once it runs successfully start the database server:

sudo service mysql start

Then run this command:

sudo mysql_secure_installation

It will ask you to provide the root password. In the next step, it will ask whether you want to change the root password for the database: say no. In the rest of the steps, say ‘yes’ to everything. If everything works fine then you will see this message:

Thanks for using MariaDB!

Step #2 Install Apache

Now it’s time to install the web server and enable the needed modules. On this server I am using Apache with FastCGI. Since FastCGI is not available through default repositories we have to enable the Multiverse repository. In most cases, depending on your VPS provider, the multiverse repos are available in the source list but commented out. Open the source list file and uncomment them:

sudo nano /etc/apt/source.list

If the repositories are not in the source.list file, then add them from this page of the Ubuntu Wiki.

The default Ubuntu repositories look like the ones below, but you may want to find a mirror closer to your server for better performance:

deb http://us.archive.ubuntu.com/ubuntu/ trusty multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ trusty multiverse
deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse

Once the multiverse repos are enabled, run an update and install the two packages:

sudo apt-get update
sudo apt-get install apache2 libapache2-mod-fastcgi

Then enable these modules:

a2enmod rewrite
a2enmod fastcgi
a2enmod proxy_http

Step #3 Configure Vhost

Before we move ahead let’s create the web directory where we will download Seafile packages. On Ubuntu it should be under /var/www/

sudo mkdir -p /var/www/directory_name

example

sudo mkdir -p /var/www/sea

Now we have to create a vhost file for the seafile server:

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

Example

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

The vhost file should look something like the one below:

<VirtualHost *:80>
 ServerName www.your-domain-name.com
 # Use "DocumentRoot /var/www/html" for Centos/Fedora
 # Use "DocumentRoot /var/www" for Ubuntu/Debian
 DocumentRoot /var/www/your-directory/
 Alias /media /var/www/your-directory/seafile-server-latest/seahub/media
 RewriteEngine On 
    #  </Location>
    <Location /media>
        Require all granted
    </Location>
 # seafile fileserver
 ProxyPass /seafhttp http://127.0.0.1:8082
 ProxyPassReverse /seafhttp http://127.0.0.1:8082
 RewriteRule ^/seafhttp - [QSA,L]
 # seahub
 RewriteRule ^/(media.*)$ /$1 [QSA,L,PT]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ /seahub.fcgi$1 [QSA,L,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</VirtualHost>

In your vhost you have to change three things: ServerName to reflect the URL or your server DocumentRoot: provide the path to the directory we created above Alias /media /var/www/your_directory_path/seafile-server-latest/seahub/media

Open the apache.conf file

nano /etc/apache2/apache2.conf

and add the this line at the end (don’t forget to change the path of directory):

FastCGIExternalServer /var/www/your_directory_path/seahub.fcgi -host 127.0.0.1:8000

Step #4 Install Seafile

First install the packages needed by Seafile:

apt-get install python2.7 python-setuptools python-imaging python-mysqldb python-flup

Now let’s ‘cd’ to the newly create directory where we will install Seafile

cd /var/www/sea/

wget the latest Seafile packages into this directory (you should check the download page for the latest release):

sudo wget https://bitbucket.org/haiwen/seafile/downloads/seafile-server_4.0.5_x86-64.tar.gz

Extract the files:

tar xzvf seafile-server*

Then cd to the extracted ’seafile-server’ directory

cd seafile-server*

Run this script which will create the required databases and directories for the Seafile server:

./setup-seafile-mysql.sh

This script will guide you to setup your Seafile server using MySQL. Choose the default options for steps between 3–6:

“ENTER” to continue 1: Give Server name 2: Server IP or domain 3: Default port 4: Where do you want to put your seafile data? 5: Which port do you want to use for the seafile server? 6: Which port do you want to use for the seafile fileserver? 7: Create user (If you don’t have users then choose the option [1] which will automatically create database and users.)

If you chose option [1] to create databases, you will come across following options: In option 4, instead of using ‘root’ as root user for Seafile database create a new user. In my case, I created a user named ‘seau’. Leave everything else as is.

1 What is the host of mysql server?
[ default “localhost” ] 
2 What is the port of mysql server?
[ default “3306” ] 
3 What is the password of the mysql root user?
[ root password ] 
verifying password of user root … done
4 Enter the name for mysql user of seafile. It would be created if not exists.
[ default “root” ] seau
5 Enter the password for mysql user “seau”:
[ password for seau ] 
6 Enter the database name for ccnet-server:
[ default “ccnet-db” ] 
7 Enter the database name for seafile-server:
[ default “seafile-db” ] 
8 Enter the database name for seahub:
[ default “seahub-db” ]

Once done the script will give you a summary of the tasks performed.

Now we have to edit two configuration files: ccnet.conf and seahub_settings.py. These files reside in the document root directory.

Open ccnet.conf with desired editor, I use nano:

sudo nano /var/www/your-directory/ccnet/ccnet.conf

In this file check that the ‘SERVICE_URL’ points to the correct domain.

SERVICE_URL = http://www.your_domain.com:8000

Now edit the second config file:

sudo nano /var/www/your-directory/seahub_settings.py

and add the following line before DATABASES

FILE_SERVER_ROOT = ‘http://www.your-domain.com/seafhttp’

Step #5 Start the server

First we have to run a script which will enable the site which we configured within the apache2 configuration at Step #3 Configure Vhost.

a2ensite your_vhost_name.conf

In my case it was:

a2ensite sea.conf

Then restart apache:

service apache2 restart

Now let’s run Seafile server

/var/www/your-directory/seafile-server-latest/./seafile.sh start
/var/www/your-directory/seafile-server-latest/./seahub.sh start-fastcgi

The second command will ask you to create an admin account for your Seafile server, which will be an existing email ID and password. This email ID and password will be used to log into your server.

That’s it. You are all set.

Open any web browser, Chrome is recommended, and enter the site URL or IP address of your server

Example:

www.seafile.com

or

10.20.11.11

seafile

This will open the login page of your Seafile sever. Enter the username and password, which you created above, and you will be logged into your very own Seafile server! Bye bye Dropbox!

Getting started with Seafile server

Seafile uses a different model. Unlike Dropbox or ownCloud, everything is a library here. You can think of these as directories. These Libraries are the ones that are synced between different machines using desktop clients.

You can either create desired folders inside the default ‘My Library’ or create new Libraries if you want more flexibility with syncing. I simply deleted the default ‘My Library’ and created a couple of Libraries such as Images, Documents, eBooks, Music, Movies, etc. The great news about Seafile is that you can encrypt these libraries right from the web browser.

Go ahead and download the desktop client for your OS. When you run the client for the first time it will ask for the location where you would like the client to keep files.

seafile

Enter the account details for the server. Then right click on the library that you want to sync with this machine.

seafile file sync

seafile desktop

The client will give you the option to choose the desired location for this file. This is one part that I love the most about Seafile, as I can have different Libraries synced with folders on different partitions.

That’s all! Enjoy your very own ‘Seafile Cloud Server’.