How to Install EteSync server on Ubuntu 20.04
EteSync is an open-source solution to sync your contacts, calendars, and tasks. It is self-hosted, provides end-to-end encryption, and allows you to share data with other users. It can be integrated with GNOME and KDE desktops. It can be accessed through desktop, web, Android, and iOS clients.
In this tutorial, I will show you how to install EteSync with Apache on Ubuntu 20.04.
Prerequisites
- A server running Ubuntu 20.04.
- A valid domain name pointed with your server IP.
- A root password is configured on the server.
Getting Started
First, update the system packages to the updated version by running the following command:
apt-get update -y
Once all the packages are updated, you can proceed to the next step.
Installing MariaDB Server
By default, EteSync uses the SQLite database to store its information. Here, we will install and use MariaDB as a database backend.
First, install the required dependencies using the following command:
apt-get install software-properties-common gnupg2 -y
Next, add the MariaDB GPG key and repository using the following command:
apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://mirror.lstn.net/mariadb/repo/10.5/ubuntu focal main'
Next, update the MariaDB repository and install the latest version of MariaDB with the following command:
apt-get install mariadb-server -y
After installing the MariaDB server, log in to the MariaDB shell with the following command:
mysql
Once you are log in, create a database and user for EteSync with the following command:
MariaDB [(none)]> create database etesync;
MariaDB [(none)]> create user etesync@localhost identified by 'securepassword';
Next, grant all the privileges to the EteSync database with the following command:
MariaDB [(none)]> grant all privileges on etesync.* to etesync@localhost;
Next, flush the privileges and exit from the MariaDB with the following command:
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;
Once you are finished, you can proceed to the next step.
Installing and Configuring EteSync
First, you will need to install some Python dependencies required for EteSync. You can install all of them with the following command:
apt-get install python3-virtualenv python3-pip gcc libmysqlclient-dev build-essential git -y
After installing all the dependencies, download the latest version of EteSync using the following command:
git clone https://github.com/etesync/server.git etesync
Once the download is completed, change the directory to etesync and create a Python virtual environment with the following command:
cd etesync
virtualenv -p python3 .venv
Next, activate the virtual environment with the following command:
source .venv/bin/activate
Next, install all the requirements using the following command:
pip install -r requirements.txt
Next, copy the sample configuration file:
cp etebase-server.ini.example etebase-server.ini
Next, edit the configuration file using the command below:
nano etebase-server.ini
Add or modify the following lines as per your configuration:
media_root = /opt allowed_host1 = etesync.example.com ;engine = django.db.backends.sqlite3 ;name = db.sqlite3 engine = django.db.backends.mysql name = etesync user = etesync password = securepassword host = 127.0.0.1 port = 3306
Save and close the file then install other modules using the following command:
pip3 install daphne
pip3 install mysqlclient
pip3 install aioredis
Next, generate the static files and migrate the database with the following command:
./manage.py collectstatic
./manage.py migrate
Finally, start the EteSync server with the following command:
daphne -b 0.0.0.0 -p 8001 etebase_server.asgi:application
If everything is fine, you should get the following output:
2021-07-09 05:42:28,510 INFO Starting server at tcp:port=8001:interface=0.0.0.0 2021-07-09 05:42:28,510 INFO HTTP/2 support not enabled (install the http2 and tls Twisted extras) 2021-07-09 05:42:28,511 INFO Configuring endpoint tcp:port=8001:interface=0.0.0.0 2021-07-09 05:42:28,512 INFO Listening on TCP address 0.0.0.0:8001
Press CTRL + C to stop the server.
Next, create an administrative user using the following command:
./manage.py createsuperuser
Provide your username, password, and email as shown below:
Username: etesync Email address: [email protected] Password: Password (again): Superuser created successfully.
Next, deactivate from the Python virtual environment with the following command:
deactivate
Create a Systemd Unit File for EteSync
Next, you will need to create a systemd unit file for managing EteSync. You can create it with the following command:
nano /etc/systemd/system/etesync.service
Add the following lines:
[Unit] Description=EteSync: End-to-End Encryption to Sync Calender, Contacts, Tasks and Notes. [Service] WorkingDirectory=/root/etesync ExecStart=/root/etesync/.venv/bin/daphne -b 127.0.0.1 -p 8001 -u /tmp/etebase_server.sock etebase_server.asgi:application User=root Group=root Restart=always RestartSec=5s [Install] WantedBy=multi-user.target
Save and close the file then reload the systemd daemon to apply the configuration changes:
systemctl daemon-reload
Next, start and enable the EteSync service with the following command:
systemctl start etesync
systemctl enable etesync
To verify the status of EteSync service, run the following command:
systemctl status etesync
You will get the following output:
? etesync.service - EteSync: End-to-End Encryption to Sync Calender, Contacts, Tasks and Notes. Loaded: loaded (/etc/systemd/system/etesync.service; disabled; vendor preset: enabled) Active: active (running) since Fri 2021-07-09 05:45:45 UTC; 5s ago Main PID: 16213 (daphne) Tasks: 1 (limit: 2353) Memory: 48.7M CGroup: /system.slice/etesync.service ??16213 /root/etesync/.venv/bin/python /root/etesync/.venv/bin/daphne -b 127.0.0.1 -p 8001 -u /tmp/etebase_server.sock etebase_se> Jul 09 05:45:45 node1 systemd[1]: Started EteSync: End-to-End Encryption to Sync Calender, Contacts, Tasks and Notes.. Jul 09 05:45:46 node1 daphne[16213]: 2021-07-09 05:45:46,993 INFO Starting server at tcp:port=8001:interface=127.0.0.1, unix:/tmp/etebase_> Jul 09 05:45:46 node1 daphne[16213]: 2021-07-09 05:45:46,995 INFO HTTP/2 support not enabled (install the http2 and tls Twisted extras) Jul 09 05:45:46 node1 daphne[16213]: 2021-07-09 05:45:46,995 INFO Configuring endpoint tcp:port=8001:interface=127.0.0.1 Jul 09 05:45:46 node1 daphne[16213]: 2021-07-09 05:45:46,997 INFO Listening on TCP address 127.0.0.1:8001 Jul 09 05:45:46 node1 daphne[16213]: 2021-07-09 05:45:46,998 INFO Configuring endpoint unix:/tmp/etebase_server.sock
At this point, EteSync is started and listening on port 8001. You can now proceed to the next step.
Configuring Apache as a Reverse Proxy
It is also advisable to install and use Apache as a reverse proxy to access the EteSync. First, install the Apache server with the following command:
apt-get install apache2 -y
After installing the Apache server, enable all proxy modules with the following command:
a2enmod proxy proxy_http headers proxy_wstunnel
Next, create a new Apache virtual host configuration file:
nano /etc/apache2/sites-available/etesync.conf
Add the following lines:
<VirtualHost *:80> ServerName etesync.example.com ErrorDocument 404 /404.html ErrorLog ${APACHE_LOG_DIR}/etebase_error.log CustomLog ${APACHE_LOG_DIR}/etebase_access.log combined ProxyPreserveHost On ProxyPass / http://127.0.0.1:8001/ ProxyPassReverse / http://127.0.0.1:8001/ Alias /static /etesync/static </VirtualHost>
Save and close the file then activate the Apache virtual host with the following command:
a2ensite etesync.conf
Next, restart the Apache to update the changes:
systemctl restart apache2
You can now verify the Apache status using the following command:
systemctl status apache2
You should get the following output:
? apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2021-07-09 05:50:26 UTC; 5s ago Docs: https://httpd.apache.org/docs/2.4/ Process: 17551 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS) Main PID: 17567 (apache2) Tasks: 55 (limit: 2353) Memory: 5.3M CGroup: /system.slice/apache2.service ??17567 /usr/sbin/apache2 -k start ??17568 /usr/sbin/apache2 -k start ??17569 /usr/sbin/apache2 -k start Jul 09 05:50:26 node1 systemd[1]: Starting The Apache HTTP Server... Jul 09 05:50:26 node1 apachectl[17558]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 45.58.3>
Access EteSync Admin Console
Now, open your web browser and access the EteSync admin interface using the URL http://etesync.example.com/admin/. You will be redirected to the following page:
Provide your admin username, password and click on the Sign In button. You should see the following page:
Secure EteSync with Let's Encrypt SSL
First, you will need to install the Certbot Let's Encrypt client to download and install the SSL certificate for your domain.
You can install it with the following command:
apt-get install python3-certbot-apache -y
Once installed, you can run the following command to install the Let's Encrypt Certificate for your domain etesync.example.com.
certbot --apache -d etesync.example.com
During the installation, you will be asked to provide your email address and accept the term of service as shown below:
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator apache, Installer apache Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): [email protected] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (A)gree/(C)ancel: A - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y Obtaining a new certificate Performing the following challenges: http-01 challenge for etesync.example.com Enabled Apache rewrite module Waiting for verification... Cleaning up challenges Created an SSL vhost at /etc/apache2/sites-available/etesync-le-ssl.conf Deploying Certificate to VirtualHost /etc/apache2/sites-available/etesync-le-ssl.conf Enabling available site: /etc/apache2/sites-available/etesync-le-ssl.conf Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Next, type 2 and hit Enter to download and install a free SSL certificate for your domain. Once the installation has been completed successfully. You should get the following output:
Enabled Apache rewrite module Redirecting vhost in /etc/apache2/sites-enabled/etesync.conf to ssl vhost in /etc/apache2/sites-available/ etesync-le-ssl.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://etesync.example.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=etesync.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Conclusion
Congratulations! you have successfully installed EteSync on Ubuntu 20.04 server with Let's Encrypt SSL. You can now sync your calendar and contact easily with EteSync.