In this bog post I will tell you how I transformed my Redmi K20 pro into a server that hosts Nextcloud.
We are gonna need:
- termux
- tailscale/headscale or a public domain if you want to access it from anywhere Since I already bought my domain (the URL of this blog), I will use the latter.
Running Nextcloud
Setting up termux
Note: termux must be installed from f-droid and not from the playstore since PlayStore version hasn’t been updated in years.
Nextcloud setup was inspired by this reddit post and I added what I discovered while setting this up myself.
Note: If you have a computer I suggest you to run sshd
as first command so you can ssh into the phone from your computer.
First of all we want all the commands to be read in aarch64 architecture by typing setarch aarch64
From what I understood the K20 Pro is already aarch64 since uname -m
already returns “aarch64”, so we can skip this step.
Installing Dependencies
Termux is cool but but its repos might not contain all the necessary packages needed to run Nextcloud, so we’ll use a “proot-distro” to get get ourselves into an environment where all package dependencies are available. I choosed ubuntu since my experience tells me it’s the one where most things work out of the box but you can try using alpine which is lighter. To set up the proot-distro:
Once inside the environment we update the packages:
Now we can proceed to install the dependencies:
Nextcloud is a php based web server application. I choose to use mariaDB since it’s faster and more scalable than MySQL
You’ll get a bunch of warnings like debconf: falling back to frontend: Readline
telling us that a dialog-based graphical interface isn’t installed, so it’s falling back to a basic terminal interface (readline). That’s fine.
Setting Dependencies
We then need to create the apache configuration:
Paste in it:
In /var/www
we have to enable the nextcloud website
To setup the database we first login without password, so we can set one for next runs.
We enter the mariaDB shell doing:
As said we want to setup password authentication to enter the database shell
Once done, we can kill mariaDB
Now we can access the DB shell using the password we created using mysql -p
. It will prompt for a password and we enter the password we set before.
Once inside the shell we will create nextcloud user
Installing Nextcloud
Nextcloud provides a zip file that contains an installer. To download it we use wget:
we will extract everything in nextcloud default folder:
And we set the correct permissions:
Now you should be able to connect to http://localhost:8080
and continue the installation there setting the credentianls for the admin user we created before in the database.
Nextcloud on server boot
This section provides a quick guide to start nextcloud server on boot. We’ll use termux-services (runit) so each service will stay in the foreground so runit can supervise it and start it again if something goes wrong and the service stops.
sshd service
paste in it
create a symlink for sv
Enable the service
nextcloud service
paste in it
create a symlink for sv
Enable the service
Notes
I strongly suggest you to create another user from nexcloud gui when logged in as admin and use that account for all the rest while keeping the admin account clean
Remove some warnings and speeding up performances
Warnings and errors appear
Memcache
run apt install php8.2-apcu
and add 'memcache.local' => '\OC\Memcache\APCu',
in nextcloud config.php
Log level
'loglevel' => 3
in nextcloud config.php
Ajax -> cronie
According to this reddit post, changing the nextcloud job scheduler from ajax to cron drastically increases performances. This makes sense because ajax runs once when there is a click while cron we can schedule the cron jobs every x minutes, decreasing load when a page has to be loaded.
Since we are in a proot-distro cron jobs cannot be started from inside we have to start them from termux shell. We install cronie and make it start using sv.
We create a script
And add it to cronie crontab
Redis for locking files
It seems overkill and it might be, but it is very easy and straightforward to setup. Redis has a bug on ARM64 that might lead to data corruption. Fortunately we are not using Redis to store data but we are only using to track lock of files. To install redis:
Then we edit the config at /etc/redis/redis.conf
uncommenting/adding:
in the nextcloud config.php
also, we want to start redis automatically, so from termux shell we edit .termux/sv/nextcloud/run
adding: