Seafile is a self-hosted cloud storage platform for secure file synchronization, sharing, and collaboration. It provides users with a robust and flexible solution to manage their files and data while maintaining full control over their infrastructure. Here are some key features and benefits of Seafile:
- Secure File Storage
- File Synchronization
- Version Control
- File Sharing and Collaboration
- Customization and Extensibility
- Scalability and Performance
In this tutorial, we will show you how to install Seafile Self-Hosted Cloud Storage with Nginx on Ubuntu 22.04.
Step 1 – Install Required Dependency
Seafile is a Python-based application. To install it on your server, you will need to install Python and other required dependencies. You can do this using the following command:
apt install -y python3 python3-setuptools python3-pip libmysqlclient-dev memcached libmemcached-dev
Next, install other required packages using the PIP command:
pip3 install --timeout=3600 django==3.2.* future==0.18.* mysqlclient==2.1.* pymysql pillow==9.3.* pylibmc captcha==0.4 markupsafe==2.0.1 jinja2 sqlalchemy==1.4.3 psd-tools django-pylibmc django_simple_captcha==0.5.* djangosaml2==1.5.* pysaml2==7.2.* pycryptodome==3.16.* cffi==1.15.1 lxml
Step 2 – Install and Configure Database
First, install the MySQL database server using the following command:
apt install -y mysql-server
Next, connect to the MySQL shell.
mysql
Then, set the MySQL root password using the following command:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Next, create a database for Seafile.
mysql> CREATE DATABASE ccnet_db CHARACTER SET utf8; mysql> CREATE DATABASE seafile_db CHARACTER SET utf8; mysql> CREATE DATABASE seahub_db CHARACTER SET utf8;
Then, create a user for Seafile.
mysql> CREATE USER 'seafile'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Then, the user will be granted all privileges on the three databases.
mysql> GRANT ALL PRIVILEGES ON `ccnet_db`.* to `seafile`@localhost; mysql> GRANT ALL PRIVILEGES ON `seafile_db`.* to `seafile`@localhost; mysql> GRANT ALL PRIVILEGES ON `seahub_db`.* to `seafile`@localhost;
Finally, flush the privileges and exit from the MySQL shell.
mysql> FLUSH PRIVILEGES; mysql> exit
Step 3 – Install Seafile
First, create a user and directory for Seafile.
mkdir /opt/seafile adduser --home /opt/seafile --shell /bin/bash seafile
Then, change the ownership of the seafile directory.
chown -R seafile: /opt/seafile
Next, log in to the Seafile user and download the latest version of the Seafile server.
su seafile wget https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-server_10.0.1_x86-64.tar.gz
Next, extract the downloaded file.
tar xf seafile-server_10.0.1_x86-64.tar.gz
Then, navigate to the extracted directory and configure Seafile.
cd seafile-server-10.0.1 ./setup-seafile-mysql.sh
Answer all the questions as shown below:
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-server What is the ip or domain of the server? For example: www.mycompany.com, 192.168.1.101 [ This server's ip or domain ] seafile.example.com 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_db verifying user "seafile" access to database ccnet_db ... done Enter the existing database name for seafile: [ seafile database ] seafile_db verifying user "seafile" access to database seafile_db ... done Enter the existing database name for seahub: [ seahub database ] seahub_db verifying user "seafile" access to database seahub_db ... done --------------------------------- This is your configuration --------------------------------- server name: seafile-server server ip/domain: seafile.example.com seafile data dir: /opt/seafile/seafile-data fileserver port: 8082 database: use existing ccnet database: ccnet_db seafile database: seafile_db seahub database: seahub_db database user: seafile
Step 4 – Start Seafile Server
Now, please navigate to the seafile server directory and start it using the following command:
cd /opt/seafile/seafile-server-latest ./seafile.sh start
Then, start the SeaHub server using the following command:
./seahub.sh start
You will be asked to set up your admin username and password 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.
Next, stop both Seafile and SeaHub service.
./seafile.sh stop ./seahub.sh stop
Next, edit the SeaHub configuration file.
nano /opt/seafile/conf/seahub_settings.py
Add / Modify the following lines:
SERVICE_URL = "http://seafile.example.com/" CSRF_TRUSTED_ORIGINS = ['http://seafile.example.com/'] FILE_SERVER_ROOT = "http://seafile.example.com/seafhttp" CACHES = { 'default': { 'BACKEND': 'django_pylibmc.memcached.PyLibMCCache', 'LOCATION': '127.0.0.1:11211', }, }
Save and close the file, then log out of the seafile user.
exit
Step 5 – Create a Systemd Service File
Next, you will need to create a systemd file to manage Seafile services.
First, create a service file for Seafile.
nano /etc/systemd/system/seafile.service
Add the following configuration:
[Unit] Description=Seafile # add mysql.service or postgresql.service depending on your database to the line below After=network.target mysql.service [Service] Type=forking ExecStart=/opt/seafile/seafile-server-latest/seafile.sh start ExecStop=/opt/seafile/seafile-server-latest/seafile.sh stop LimitNOFILE=infinity User=seafile Group=seafile [Install] WantedBy=multi-user.target
Then, create a service file for SeaHub.
nano /etc/systemd/system/seahub.service
Add the following configuration:
[Unit] Description=Seafile hub After=network.target seafile.service [Service] Type=forking # change start to start-fastcgi if you want to run fastcgi ExecStart=/opt/seafile/seafile-server-latest/seahub.sh start ExecStop=/opt/seafile/seafile-server-latest/seahub.sh stop User=seafile Group=seafile [Install] WantedBy=multi-user.target
Save the file, then reload the systemd daemon using the following command:
systemctl daemon-reload
Next, start both Seafile and SeaHub services.
systemctl start seafile systemctl start seahub
You can check the status of both services using the following command:
systemctl status seafile seahub
Output:
● seafile.service - Seafile Loaded: loaded (/etc/systemd/system/seafile.service; disabled; vendor preset: enabled) Active: active (running) since Fri 2024-03-15 03:03:53 UTC; 1min 46s ago Process: 42678 ExecStart=/opt/seafile/seafile-server-latest/seafile.sh start (code=exited, status=0/SUCCESS) Tasks: 18 (limit: 4579) Memory: 4.0M CPU: 158ms CGroup: /system.slice/seafile.service ├─42698 /opt/seafile/seafile-server-10.0.1/seafile/bin/seafile-controller -c /opt/seafile/ccnet -d /opt/seafile/seafile-data -F /opt/seafile/conf └─42700 seaf-server -F /opt/seafile/conf -c /opt/seafile/ccnet -d /opt/seafile/seafile-data -l /opt/seafile/logs/seafile.log -P /opt/seafile/pids/seaf-ser> Mar 15 03:03:50 ubuntu systemd[1]: Starting Seafile... Mar 15 03:03:50 ubuntu seafile.sh[42678]: Starting seafile server, please wait ... Mar 15 03:03:50 ubuntu seafile-control[42696]: seafile-controller.c(621): No seafevents. Mar 15 03:03:53 ubuntu seafile.sh[42678]: Seafile server started Mar 15 03:03:53 ubuntu seafile.sh[42678]: Done. Mar 15 03:03:53 ubuntu systemd[1]: Started Seafile. ● seahub.service - Seafile hub Loaded: loaded (/etc/systemd/system/seahub.service; disabled; vendor preset: enabled) Active: active (running) since Fri 2024-03-15 03:05:00 UTC; 38s ago Process: 42751 ExecStart=/opt/seafile/seafile-server-latest/seahub.sh start (code=exited, status=0/SUCCESS) Main PID: 42765 (python3) Tasks: 6 (limit: 4579) Memory: 67.6M CPU: 1.304s CGroup: /system.slice/seahub.service ├─42765 python3 /opt/seafile/seafile-server-10.0.1/seahub/thirdpart/bin/gunicorn seahub.wsgi:application -c /opt/seafile/conf/gunicorn.conf.py --preload ├─42766 python3 /opt/seafile/seafile-server-10.0.1/seahub/thirdpart/bin/gunicorn seahub.wsgi:application -c /opt/seafile/conf/gunicorn.conf.py --preload ├─42767 python3 /opt/seafile/seafile-server-10.0.1/seahub/thirdpart/bin/gunicorn seahub.wsgi:application -c /opt/seafile/conf/gunicorn.conf.py --preload ├─42768 python3 /opt/seafile/seafile-server-10.0.1/seahub/thirdpart/bin/gunicorn seahub.wsgi:application -c /opt/seafile/conf/gunicorn.conf.py --preload ├─42769 python3 /opt/seafile/seafile-server-10.0.1/seahub/thirdpart/bin/gunicorn seahub.wsgi:application -c /opt/seafile/conf/gunicorn.conf.py --preload └─42770 python3 /opt/seafile/seafile-server-10.0.1/seahub/thirdpart/bin/gunicorn seahub.wsgi:application -c /opt/seafile/conf/gunicorn.conf.py --preload Mar 15 03:04:55 ubuntu systemd[1]: Starting Seafile hub... Mar 15 03:04:55 ubuntu seahub.sh[42751]: LC_ALL is not set in ENV, set to en_US.UTF-8 Mar 15 03:04:55 ubuntu seahub.sh[42751]: Starting seahub at port 8000 ... Mar 15 03:05:00 ubuntu seahub.sh[42751]: Seahub is started Mar 15 03:05:00 ubuntu seahub.sh[42751]: Done.
Step 6 – Configure Nginx for Seafile
First, install the Nginx server using the following command:
apt install nginx
Next, create an Nginx virtual host configuration file.
nano /etc/nginx/conf.d/seafile.conf
Add the following configuration:
log_format seafileformat '$http_x_forwarded_for $remote_addr [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $upstream_response_time'; server { listen 80; server_name seafile.example.com; server_tokens off; # Prevents the Nginx version from being displayed in the HTTP response header location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host $server_name; proxy_read_timeout 1200s; proxy_set_header X-Forwarded-Proto http; # used for view/edit office file via Office Online Server client_max_body_size 0; access_log /var/log/nginx/seahub.access.log seafileformat; error_log /var/log/nginx/seahub.error.log; } location /seafhttp { rewrite ^/seafhttp(.*)$ $1 break; proxy_pass http://127.0.0.1:8082; client_max_body_size 0; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 36000s; proxy_read_timeout 36000s; proxy_send_timeout 36000s; send_timeout 36000s; # Uncomment the following line if you want to support uploads > 4GB # proxy_request_buffering off; access_log /var/log/nginx/seafhttp.access.log seafileformat; error_log /var/log/nginx/seafhttp.error.log; } location /media { root /opt/seafile/seafile-server-latest/seahub; } }
Then, edit the Nginx main configuration file.
nano /etc/nginx/nginx.conf
Add the following line after the line http{:
server_names_hash_bucket_size 64;
Save the file, then restart the Nginx to apply the changes.
systemctl restart nginx
Step 7 – Access Seafile Web Interface
Now, open your web browser and access the Seafile web UI using the URL http://seafile.example.com. You will see the Seafile login page.
Provide your admin username and password and click on Log In. You will see the Seafile dashboard on the following page.
Conclusion
Overall, Seafile provides a comprehensive solution for organizations seeking secure and flexible cloud storage and collaboration capabilities. Its self-hosted nature, robust security features, and extensive customization options make it a popular choice for businesses and individuals looking to take control of their data and workflows. You can now implement secure cloud storage using Seafile on dedicated server hosting from Atlantic.Net!