AI-generated and Transcribed my English.
This guide installs Nextcloud on an Android TV box using Termux + AnLinux + Ubuntu/proot.
Because Ubuntu is running under proot, there are a couple of important differences from a normal Ubuntu installation:
systemd is not available.
Services are started with service
Apache cannot normally use privileged port 80, so this example uses port 8080.
Running services such as Apache and MariaDB can prevent the proot Ubuntu session from exiting, so we add a shutdown command at the end.
Running Server Applications on an Android TV Box using Termux
I have successfully used an inexpensive Android TV box as a small, low-power Linux Nextcloud server using Termux.
This is the basic setup. I have used it 3 times so far.
- Install Termux
Install Termux from F-Droid or the official Termux GitHub releases.
One issue I encountered was with Termux:Boot. If Termux and its add-ons come from different sources, their Android signatures may not match. It is therefore best to install Termux and any Termux add-ons from the same source. I ended up used ~/.bashrc instead. The TV Box has Autostart function.
- Update Termux and install the basic tools
Open Termux and run:
pkg update && pkg upgrade -y
Install some useful tools:
pkg install git openssh iproute2 which wget nano proot -y
You can check the TV box hardware and available resources with:
nproc
free -h
uptime
cat /proc/cpuinfo
whoami
ip -a route
top
nproc shows the available CPU cores, while free -h is particularly useful for seeing how much RAM Android leaves available to Termux applications.
- Enable SSH access
Set a password for the Termux user:
passwd
Start the SSH server:
sshd
Termux OpenSSH normally listens on port 8022 rather than the standard SSH port 22.
Check it with:
ss -ltn | grep 8022
Use:
whoami
To find the Termux username.
From another Linux machine on the LAN:
ssh -p 8022 TERMUX_USER@ANDROID_TV_IP
For example:
ssh -p 8022 u0_a79@192.168.1.xxx
- Automatically start SSH when Termux starts
Edit:
nano ~/.bashrc
Add:
# Start SSH if it is not already running
if command -v sshd >/dev/null 2>&1; then
pgrep -x sshd >/dev/null || sshd
fi
Now whenever a Termux interactive shell starts, it checks whether sshd is already running and starts it if necessary.
This is not the same as Android boot autostart. .bashrc runs when Termux starts a shell. For true Android boot-time startup, Termux itself must be started at boot using something such as a compatible Termux:Boot installation or another Android/root startup mechanism.
- Ubuntu environment
Termux can also provide the foundation for running an Ubuntu userspace using proot.
This gives a layout such as:
Android TV Box
β
βββ Android
β
βββ Termux
β
βββ OpenSSH :8022
β
βββ Ubuntu / proot
β
βββ Apache
βββ MariaDB
βββ PHP
βββ other Linux applications
An important difference from a conventional Ubuntu installation is that a proot Ubuntu environment normally does not run systemd as PID 1.
Therefore services are generally controlled with commands such as:
service apache2 start
service mariadb start
rather than:
systemctl start apache2
Another consideration is that unprivileged/proot environments may not be able to bind services to privileged ports such as port 80. Using ports such as 8080 avoids this issue.
- SSH and automatic Ubuntu entry
If Ubuntu is installed and you want a locally opened Termux terminal to automatically enter Ubuntu, while still allowing SSH connections to remain at the Termux prompt, the Termux
nano ~/.bashrc can contain:
# Start sshd if needed
if command -v sshd >/dev/null 2>&1; then
pgrep -x sshd >/dev/null || sshd
fi
# Only auto-enter Ubuntu on a local interactive terminal
if [[ $- == i ]] &&
[ -z "$SSH_CONNECTION" ] &&
[ -z "$SSH_CLIENT" ]; then
if [ -x "$HOME/start-ubuntu.sh" ]; then
"$HOME/start-ubuntu.sh"
fi
fi
This gives two useful behaviours:
Open Termux locally
β
Ubuntu
SSH β port 8022
β
Termux
That makes troubleshooting considerably easier because SSH access does not automatically launch another proot environment.
Result
The result is a surprisingly useful little ARM server:
Android TV Box
β
Termux
β
βββ SSH :8022
β
βββ optional Ubuntu/proot
The box can then be used as the base for whatever Linux services you want to experiment with.
For inexpensive ARM Android TV boxes drawing only around 10 watts, Termux provides a simple way of turning otherwise basic hardware into a small home server without replacing Android or installing a conventional Linux distribution.
- Install Ubuntu with AnLinux
Install AnLinux and Termux, then in Termux:
pkg install wget openssl-tool proot -y
hash -r
Download the Ubuntu installer:
wget https://raw.githubusercontent.com/EXALAB/Anlinux-Resources/master/Scripts/Installer/Ubuntu/ubuntu.sh
Run the generated Ubuntu installer/startup script as appropriate for your AnLinux installation.
Once inside Ubuntu, update it:
apt update
apt full-upgrade -y
- Install Apache, MariaDB and PHP
Install the basic Nextcloud stack:
apt install -y \
apache2 \
mariadb-server \
libapache2-mod-php \
php \
php-mysql \
php-gd \
php-curl \
php-mbstring \
php-intl \
php-gmp \
php-bcmath \
php-xml \
php-zip \
php-imagick \
php-apcu \
unzip \
wget \
nano \
bzip2
Check the installation:
php -v
apache2 -v
mariadb --version
- Move Apache to port 8080
Under AnLinux/proot, use an unprivileged port such as 8080.
Edit:
nano /etc/apache2/ports.conf
Change:
Listen 80
to:
Listen 8080
For the initial Apache test, edit:
nano /etc/apache2/sites-enabled/000-default.conf
Change:
<VirtualHost *:80>
to:
<VirtualHost *:8080>
Suppress Apacheβs hostname warning:
echo "ServerName localhost" >> /etc/apache2/apache2.conf
Enable the Apache modules for Nextcloud needs:
a2enmod rewrite headers env dir mime setenvif
Start Apache:
service apache2 start
Check:
ss -ltn | grep 8080
From another computer on the LAN, open:
http://ANDROID_BOX_IP:8080/
If you get the Apache default page, Apache is working.
- Configure MariaDB
Start MariaDB:
service mariadb start
Enter MariaDB:
mariadb
CREATE DATABASE nextcloud
CHARACTER SET utf8mb4
COLLATE utf8mb4_general_ci;
CREATE USER 'nextcloud'@'localhost'
IDENTIFIED BY 'YOUR_DATABASE_PASSWORD';
GRANT ALL PRIVILEGES ON nextcloud.*
TO 'nextcloud'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace YOUR_DATABASE_PASSWORD with your own password.
- Download Nextcloud
Download the current Nextcloud release:
cd /tmp
wget https://download.nextcloud.com/server/releases/latest.tar.bz2
tar -xjf latest.tar.bz2
mv nextcloud /var/www/
Set ownership:
chown -R www-data:www-data /var/www/nextcloud
Configure Apache for Nextcloud
Create:
nano /etc/apache2/sites-available/nextcloud.conf
Use:
<VirtualHost *:8080>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/nextcloud
<Directory /var/www/nextcloud>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
<IfModule mod_dav.c>
Dav off
</IfModule>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/nextcloud-error.log
CustomLog ${APACHE_LOG_DIR}/nextcloud-access.log combined
</VirtualHost>
Disable the default Apache site:
a2dissite 000-default.conf
Enable Nextcloud:
a2ensite nextcloud.conf
Check the configuration:
apache2ctl configtest
You should get:
Syntax OK
Restart Apache:
service apache2 restart
Verify the virtual host:
apache2ctl -S
and:
ss -ltn | grep 8080
- Complete the Nextcloud browser installation
From another machine, browse to:
http://TV_BOX_IP:8080/
For example:
The Nextcloud installer start page should appear.
Create your Nextcloud administrator username and password.
For the database settings:
Database user: nextcloud
Database password: YOUR_DATABASE_PASSWORD
Database name: nextcloud
Database host: localhost
Click Install.
- Automatically start Nextcloud services
Because AnLinux/proot doesnβt use systemd, Apache and MariaDB can be started when the Ubuntu shell starts.
Edit Ubuntuβs:
nano ~/.bashrc
Add:
#Auto-start Nextcloud services
if ! pgrep -x mariadbd >/dev/null; then
service mariadb start
fi
if ! pgrep -x apache2 >/dev/null; then
service apache2 start
fi
Nextcloud itself does not require a separate daemon β Apache/PHP serves Nextcloud and MariaDB provides its database.
- Cleanly exit Ubuntu
One peculiarity of proot is that Apache and MariaDB can keep the Ubuntu environment alive when you type exit.
Add this alias to Ubuntuβs ~/.bashrc:
alias stop-ubuntu=βservice apache2 stop; service mariadb stop; exitβ
Then instead of:
exit
use:
stop-ubuntu
This stops both services and allows the proot Ubuntu session to exit cleanly.
- Optional: Termux SSH and automatic Ubuntu startup
In the Termux ~/.bashrc β not Ubuntuβs β you can start SSH automatically and enter Ubuntu only from a local interactive Termux terminal:
if command -v sshd >/dev/null 2>&1; then
pgrep -x sshd >/dev/null || sshd
fi
#Auto-enter Ubuntu only from a local interactive Termux session
if [[ $- == i ]] &&
[ -z "$SSH_CONNECTION" ] &&
[ -z "$SSH_CLIENT" ]; then
if [ -x "$HOME/start-ubuntu.sh" ]; then
"$HOME/start-ubuntu.sh"
fi
fi
This prevents an incoming SSH connection from unexpectedly launching the Ubuntu proot environment.
Termux SSH normally listens on port 8022, so from another Linux machine:
ssh -p 8022 USER@TV_BOX_IP
Troubleshooting: Apache page appears instead of Nextcloud
Check which virtual host Apache is using:
apache2ctl -S
Check enabled sites:
ls -l /etc/apache2/sites-enabled/
If the default site is still enabled:
a2dissite 000-default.conf
a2ensite nextcloud.conf
Then:
apache2ctl configtest
service apache2 reload
Verify:
apache2ctl -S | grep 8080
and:
curl -I ``http://127.0.0.1:8080/
The *:8080 virtual host should point to nextcloud.conf.