• Get In Touch
March 12, 2017

How to Install Seafile on CentOS 7

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Seafile is a file hosting application. It allows you to store your files on a central server which can be synchronised with personal computers and mobile devices through apps. You can directly access your files from seafile server via server’s web interface. It is similar to other file hosting services such as Dropbox and Google Drive. But the difference between seafile and other file hosting services is that seafile is self-hosted file sharing solution for private cloud applications. Some of the features of Seafile are listed below:

  • Multi-platform file synchronisation
  • Public link sharing (upload and download)
  • Client-side encryption
  • Per-folder access control
  • Version control
  • AD/LDAP authentication
  • File locking
  • Full text search
  • MS Office document preview and office web app integration
  • Two-factor authentication
  • Distributed storage

Prerequisites

To install Seafile on your centos 7 server all you’ll need is a CentOS 7 server and root privileges over it. You can always switch between non root user to root user using sudo -i command.

Update the System

Before going through the installation process it is recommended to update your system and upgrade available packages, you can do so using this command.

yum -y update

Disable SELinux

Log in to your server using your root password then edit Selinux configuration file using any text editor here we will use nano text editor, you can also install it using yum -y install nano

nano /etc/sysconfig/selinux

Find the line SELINUX=enforcing and replace it with SELINUX=disabled, save the file and exit from the text editor.

You’ll need reboot the server to apply this change so reboot your server using reboot command and wait for server rebooting then log in again to your server as root user.

Installing the Seafile Dependencies

We will need to install some dependencies first to install seafile so here we will install several python packages, MariaDB and Nginx. We begin with the installation of the EPEL repository on our CentOS server.

yum -y install epel-release

Next, install the python packages, MariaDB and Nginx like shown below:

yum -y install python-imaging MySQL-python python-simplejson python-setuptools mariadb mariadb-server nginx

It may take some time so you should wait until all packages are installed.

Configure MariaDB

We have successfully installed MariaDB now we will need to configure MariaDB for Seafile. Start MariaDB and configure the root password with the commands below:

systemctl start mariadb
mysql_secure_installation

You’ll be asked to provide root password so simply type in your root password and answer yes to all questions by typing Y.

Set root password? [Y/n] Y
New password:
Re-enter new 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

We will create 3 databases for seafile:

  1. ccnet_db
  2. seafile_db
  3. seahub_db
  4. And we will create a new user ‘seacloud’ with the password ‘yourpassword’. Replace yourpassword with a secure password.

mysql -u root -p

Type your password and run following queries to create databases and the user for the seafile installation.
Execute all queries one by one.

create database ccnet_db character set = 'utf8';
create database seafile_db character set = 'utf8';
create database seahub_db character set = 'utf8';

create user seacloud@localhost identified by 'yourpassword';

grant all privileges on ccnet_db.* to seacloud@localhost identified by 'yourpassword';
grant all privileges on seafile_db.* to seacloud@localhost identified by 'yourpassword';
grant all privileges on seahub_db.* to seacloud@localhost identified by 'yourpassword';
flush privileges;
exit

Install Seafile

We have installed all the dependencies required now we are ready to install seafile. Seafile will be executed under the nginx user so we can use nginx as the reverse proxy for the seafile and seahub services.

We will install seafile under the nginx user in the directory ‘/var/www/seafile’, create that dirctory and enter it with cd command.

mkdir -p /var/www/seafile
cd /var/www/seafile

Next, download the Seafile with the wget command, and extract the downloaded archive as shown below:

wget https://bintray.com/artifact/download/seafile-org/seafile/seafile-server_6.0.8_x86-64.tar.gz

tar -xzvf seafile-server_6.0.8_x86-64.tar.gz

Next rename the directory to ‘seafile-server’ and switch to that directory and to do so run following command.

mv seafile-server-6.0.8 seafile-server
cd seafile-server/

Now you’ll have to execute the ‘setup-seafile-mysql.sh’ file to configure the database.

./setup-seafile-mysql.sh

You’ll be asked for following information.

server name - Use your server name 
server's ip or domain - ip address of your server
default data dirctory - just press Enter
default port - press Enter
Now for the database configuration, choose number 2
For the MySQL configuration:
use deafult host - localhost
default port - 3306
the mysql user - 'seacloud'
and the password is 'yourpassword'
ccnet database is 'ccnet_db'
seafile database is 'seafile_db'
seahub database is 'seahub_db'

Finally press enter and the script will create the database tables for the seafile. Now let’s start the seafile and seahub services using following commands.

./seafile.sh start
./seahub.sh start

You’ll be asked for the admin configuration like your admin email and password, then the seahub service will running.

We will use a reverse proxy for the seafile server and we will run seafile with a systemd service file. So we need to stop seafile and seahub service for now. So please run following commands to stop these services.

./seafile.sh stop
./seahub.sh stop

Configure Seafile and Seahub Service

We need to change the owner of seafile installation directory and seahub_cache directory to nginx user so we can run seafile as nginx user and to do so run following commands.

cd /var/www/
chown -R nginx:nginx
chown -R nginx:nginx /tmp/seahub_cache

Next we will need to create a system.service file using any text editor run following command it will do the job for you.

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

Add following content to the service file.

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

[Service]
Type=oneshot
ExecStart=/var/www/seafile/seafile-server/seafile.sh start
ExecStop=/var/www/seafile/seafile-server/seafile.sh stop
RemainAfterExit=yes
User=nginx
Group=nginx

[Install]
WantedBy=multi-user.target

Save the file and exit from the text editor and now create a new seahub.service file.

nano seahub.service

Add following content to the seahub.service file.

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

[Service]
Type=oneshot
ExecStart=/var/www/seafile/seafile-server/seahub.sh start-fastcgi
ExecStop=/var/www/seafile/seafile-server/seahub.sh stop
RemainAfterExit=yes
User=nginx
Group=nginx

[Install]
WantedBy=multi-user.target

Save the file and exit from the text editor now reload the systemd service and start seafile and seahub.

systemctl daemon-reload
systemctl start seafile
systemctl start seahub

Generate SSL Certificate Files

We will run seafile and seahub as nginx user over a Nginx proxy. We can use a free SSL certificate file or the paid SSL certificate, this does not matter for the configuration, here we will generate self-signed SSL certificate file with the OpenSSL.

First of all create a ssl directory using following commands.

mkdir -p /etc/nginx/ssl
cd /etc/nginx/ssl

Now we can generate self signed certificate files and a dhparam file with command below:

openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
openssl req -new -x509 -sha256 -days 365 -newkey rsa:2048 -nodes -keyout server.key -out server.crt

You’ll have to answer some questions so answer them and then change the permissions of directory and files using these following commands.

chmod -R 700 /etc/nginx/ssl
chmod 400 server.*
chmod 400 dhparam.pem

Your SSL certificates have been generated now.

Now we will have to configure nginx as a reverse proxy for the seafile-server on port 8000 and 8002 and to do so we will have to create a virtual host for seafile.

cd /etc/nginx/
nano conf.d/seafile.conf

Add following content to the virtual host file and replace server name with your own.

server {  
        listen        80;
        server_name   cloud.yourServer;
        return 301  https://$host$request_uri;
}

server {  
    listen 443 ssl;
    server_name cloud.yourServer;
    ssl on;
    ssl_protocols           TLSv1 TLSv1.1 TLSv1.2;
    ssl_certificate         /etc/nginx/ssl/server.crt;
    ssl_certificate_key    /etc/nginx/ssl/server.key;

    ssl_ciphers  'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4';
    ssl_dhparam   /etc/nginx/ssl/dhparam.pem;
    ssl_prefer_server_ciphers  on;

    location / {
        fastcgi_pass    127.0.0.1:8000;
        fastcgi_param   SCRIPT_FILENAME     $document_root$fastcgi_script_name;
        fastcgi_param   PATH_INFO           $fastcgi_script_name;

        fastcgi_param   SERVER_PROTOCOL        $server_protocol;
        fastcgi_param   QUERY_STRING        $query_string;
        fastcgi_param   REQUEST_METHOD      $request_method;
        fastcgi_param   CONTENT_TYPE        $content_type;
        fastcgi_param   CONTENT_LENGTH      $content_length;
        fastcgi_param   SERVER_ADDR         $server_addr;
        fastcgi_param   SERVER_PORT         $server_port;
        fastcgi_param   SERVER_NAME         $server_name;
        fastcgi_param   REMOTE_ADDR         $remote_addr;

        access_log      /var/log/nginx/seahub.access.log;
        error_log       /var/log/nginx/seahub.error.log;
        fastcgi_read_timeout 36000;
    }

    # Reverse Proxy for seahub
    location /seafhttp {
        rewrite ^/seafhttp(.*)$ $1 break;
        proxy_pass http://127.0.0.1:8082;
        client_max_body_size 0;
        proxy_connect_timeout  36000s;
        proxy_read_timeout  36000s;
        proxy_send_timeout  36000s;
        send_timeout  36000s;
    }

    #CHANGE THIS PATH WITH YOUR OWN DIRECTORY
    location /media {
        root /var/www/seafile/seafile-server/seahub;
    }

}

Save the file and exit from the text editor and then restart nginx using following command.

systemctl start nginx

It is good to check all the configuration so make sure port 80 and 443 are available in the list that netstat provides:

netstat -plntu

Next, we have to add the domain name to the seafile configuration.

cd /var/www/seafile/
nano conf/ccnet.conf

Change service url to your domain and then save and exit from text editor.
SERVICE_URL = https://yourDomain

Now edit the seahub configuration file.

“nano conf/seahub_settings.py`

Add below configuration on second line.

HTTP_SERVER_ROOT = 'https://yourDomain/seafhttp'

Finally restart seafile and add all services to start at boot time using following command.

systemctl restart seafile
systemctl restart seahub
systemctl enable nginx
systemctl enable mariadb
systemctl enable seafile
systemctl enable seahub

Configure FirewallD

Start and enable the firewalld services using following commands.

systemctl start firewalld
systemctl enable firewalld

Now change firewall rules and then restart these using following commands.

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload

Web Interface of Seafile

Open up your favorite web browser and visit your seafile domain and you’ll see a login webpage of seafile.

HP_NO_IMG/data/uploads/users/744ed2f1-2baa-42b2-b09d-ad15a2ae3934/702825325.png” alt=” ” />

Type in your admin email and password and click on login button then you’ll be redirected to admin dashboard of seafile. Now you can manage your files and data using seafile.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]