How to setup a self hosted Seafile for your server.

We’ll assume that you have a freshly installed Digitalocean server, and have logged into it via ssh:

alias l='ls -lah --color'
apt-get update && apt-get install emacs
# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes
AllowUsers haiwen
service ssh restart
useradd haiwen -s /bin/bash -m
adduser haiwen sudo
usermod -a -G www-data haiwen
passwd haiwen
apt-get install sudo
sed -i 's/main/main contrib non-free/g' /etc/apt/sources.list
apt-get update
locale-gen en_US.UTF-8

Now connect as user haiwen to ssh:

wget https://bitbucket.org/haiwen/seafile/downloads/seafile-server_4.1.2_x86-64.tar.gz
tar -xzf seafile-server_*
mkdir installed
mv seafile-server_* installed
cd seafile-server-4.1.2/
sudo apt-get install python2.7 python-setuptools python-imaging python-mysqldb mysql-server

Run setup-seafile-mysql.sh

[email protected]:~/seafile-server-4.1.2$ ./setup-seafile-mysql.sh
Checking python on this machine ...
  Checking python module: setuptools ... Done.
  Checking python module: python-imaging ... Done.
  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 ] acloud.dzon.in

acloud.dzon.in is not a valid name

What is the name of the server? It will be displayed on the client.
3 - 15 letters or digits
[ server name ] DroidzoneCloud

What is the ip or domain of the server?
For example: www.mycompany.com, 192.168.1.101
[ This server's ip or domain ] 42.34.117.163

Which port do you want to use for the ccnet server?
[ default "10001" ]

Where do you want to put your seafile data?
Please use a volume with enough free space
[ default "/home/haiwen/seafile-data" ]

Which port do you want to use for the seafile server?
[ default "12001" ]

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

What is the host of mysql server?
[ default "localhost" ]

What is the port of mysql server?
[ default "3306" ]

What is the password of the mysql root user?
[ root password ]

verifying password of user root ...
Failed to connect to mysql server using user "root" and password "***": Can't connect to MySQL server on '127.0.0.1' (111)

What is the password of the mysql root user?
[ root password ]

verifying password of user root ...  done

Enter the name for mysql user of seafile. It would be created if not exists.
[ default "root" ] seafilusr

Enter the password for mysql user "seafilusr":
[ password for seafilusr ]

Enter the database name for ccnet-server:
[ default "ccnet-db" ]

Enter the database name for seafile-server:
[ default "seafile-db" ]

Enter the database name for seahub:
[ default "seahub-db" ]

---------------------------------
This is your configuration
---------------------------------

    server name:            DroidzoneCloud
    server ip/domain:       42.34.117.163
    ccnet port:             10001

    seafile data dir:       /home/haiwen/seafile-data
    seafile port:           12001
    fileserver port:        8082

    database:               create new
    ccnet database:         ccnet-db
    seafile database:       seafile-db
    seahub database:        seahub-db
    database user:          seafilusr
---------------------------------
Press ENTER to continue, or Ctrl-C to abort
---------------------------------
Generating ccnet configuration ...
done
Successly create configuration dir /home/haiwen/ccnet.
Generating seafile configuration ...

Done.
done
Generating seahub configuration ...
----------------------------------------
Now creating seahub database tables ...
----------------------------------------
creating seafile-server-latest symbolic link ...  done
-----------------------------------------------------------------
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 ccnet server:         10001
port of seafile server:       12001
port of seafile fileserver:   8082
port of seahub:               8000

When problems occur, Refer to

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

for information.

[email protected]:~/seafile-server-4.1.2$ ulimit -n 30000
[email protected]:~/seafile-server-4.1.2$ ./seafile.sh start

Starting seafile server, please wait ...
Seafile server started

Done.
[email protected]:~/seafile-server-4.1.2$ ./seahub.sh start

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



Loading ccnet config from /home/haiwen/ccnet
Loading seafile config from /home/haiwen/seafile-data

Seahub is started

Done.

Now seafile is accessible at http://45.55.195.173:8000/

Next up, setting https for seafile.

To start Seafile at Boot:

[email protected]:~$ sudo emacs /etc/init.d/seafile-server
#!/bin/bash

# Change the value of "user" to your linux user name
user=haiwen

# Change the value of "seafile_dir" to your path of seafile installation
# usually the home directory of $user
seafile_dir=/home/haiwen
script_path=${seafile_dir}/seafile-server-latest
seafile_init_log=${seafile_dir}/logs/seafile.init.log
seahub_init_log=${seafile_dir}/logs/seahub.init.log

# Change the value of fastcgi to true if fastcgi is to be used
fastcgi=false
# Set the port of fastcgi, default is 8000. Change it if you need different.
fastcgi_port=8000
#
# Write a polite log message with date and time
#
echo -e "\n \n About to perform $1 for seafile at `date -Iseconds` \n " >> ${seafile_init_log}
echo -e "\n \n About to perform $1 for seahub at `date -Iseconds` \n " >> ${seahub_init_log}
case "$1" in
        start)
                sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
                if [ $fastcgi = true ];
                then
                        sudo -u ${user} ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log}
                else
                        sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
                fi
        ;;
        restart)
                sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
                if [ $fastcgi = true ];
                then
                        sudo -u ${user} ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log}
                else
                        sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
                fi
        ;;
        stop)
                sudo -u ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
                sudo -u ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
        ;;
        *)
                echo "Usage: /etc/init.d/seafile-server {start|stop|restart}"
                exit 1
        ;;
esac
sudo emacs /etc/init/seafile-server.conf
start on (started mysql
and runlevel [2345])
stop on (runlevel [016])

pre-start script
/etc/init.d/seafile-server start
end script

post-stop script
/etc/init.d/seafile-server stop
end script
[email protected]:~$ sudo chmod +x /etc/init.d/seafile-server
[email protected]:~$ sudo update-rc.d seafile-server defaults

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.