Install Nextcloud on Android with Termux (No Root)

15 min read Step‑by‑step guide to set up a fully functional Nextcloud server on an Android device using Termux, without rooting. Includes configuration, HTTPS, and troubleshooting. October 12, 2026 20:30 How to Install and Run a Self‑Hosted Nextcloud Server on Android Using Termux (No Root)

Why Run Nextcloud on Android?

Nextcloud lets you store files, photos, contacts, and calendars on your own hardware, keeping data out of third‑party clouds. Installing it on an Android phone gives you a portable, always‑on personal server that can be accessed over Wi‑Fi or, with proper routing, from the internet. Because the process uses Termux, no rooting or custom recovery is required, making it safe for most users.

Note: This tutorial assumes Android 7.0 (Nougat) or newer, at least 2 GB of free storage, and a reliable Wi‑Fi connection. The phone will act as a server, so keep it plugged in or ensure the battery stays above 50 % during setup.

Before You Start

  • Termux – Install from F‑Droid (preferred) or the Google Play Store.
  • Internet access for downloading packages and the Nextcloud archive.
  • At least 2 GB of free internal storage (external SD cards work but require additional mounting steps).
  • A secondary device (laptop, tablet, or another phone) on the same Wi‑Fi network to test the web interface.
  • Basic comfort with the Linux command line.

Safety warning: The server will be reachable by any device on your local network. Do not expose it to the public internet without configuring proper TLS certificates and a firewall.

Step 1 – Install Termux and Update Packages

  1. Open the Play Store or F‑Droid, search for Termux, and install it.
  2. Launch Termux. The first run will set up its environment. When the prompt appears, run:
pkg update && pkg upgrade -y

This updates the package repository and upgrades existing tools.

Step 2 – Install Required Packages

Nextcloud needs a web server, PHP, and a database. In Termux we’ll use nginx, php-fpm, and mariadb. Install them with a single command:

pkg install nginx php-fpm mariadb proot tar wget openssl -y

Explanation of each package:

  • nginx – lightweight HTTP server.
  • php-fpm – PHP FastCGI Process Manager, required by Nextcloud.
  • mariadb – MySQL‑compatible database engine.
  • proot – provides a chroot‑like environment that lets us run Linux binaries without root.
  • tar and wget – for downloading and extracting the Nextcloud archive.
  • openssl – used later to generate a self‑signed certificate.

Step 3 – Create a Working Directory and Download Nextcloud

  1. Choose a location for the server files. We’ll use ~/nextcloud:
mkdir -p ~/nextcloud && cd ~/nextcloud
  1. Download the latest stable Nextcloud tarball. At the time of writing the URL points to version 28, but you can replace the version number with the current one:
wget https://download.nextcloud.com/server/releases/nextcloud-28.0.0.tar.bz2
  1. Extract the archive:
tar -xjf nextcloud-28.0.0.tar.bz2 --strip-components=1

The --strip-components=1 flag removes the top‑level folder from the archive, placing all files directly into ~/nextcloud.

Step 4 – Initialise the MariaDB Database

Nextcloud stores all metadata in a database. We’ll create a dedicated database and user.

  1. Start the MariaDB daemon for the first time:
mysqld_safe --datadir=$PREFIX/var/lib/mysql &

Wait a few seconds, then secure the installation:

mysql_secure_installation

You’ll be prompted for a root password and a series of security questions. Choose a strong password and answer “Y” to all prompts.

  1. Log in as root and create a database and user for Nextcloud:
mysql -u root -p
CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'nc_user'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nc_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace StrongPassword123! with a password you can remember securely.

Step 5 – Configure PHP for Nextcloud

Nextcloud requires a few PHP extensions. Most are already bundled with the php-fpm package, but we need to enable them in the configuration file.

  1. Edit $PREFIX/etc/php/php.ini (or create it if missing):
nano $PREFIX/etc/php/php.ini

Add or uncomment the following lines:

memory_limit = 512M
upload_max_filesize = 1024M
post_max_size = 1024M
max_execution_time = 360
extension=mysqli.so
extension=gd.so
extension=zip.so
extension=xml.so
extension=mbstring.so
extension=intl.so
extension=curl.so

Save with Ctrl+O then exit with Ctrl+X.

Step 6 – Set Up Nginx to Serve Nextcloud

We’ll create a simple server block that points to the Nextcloud directory and forwards PHP requests to php-fpm.

  1. Create a new Nginx configuration file:
mkdir -p $PREFIX/etc/nginx/conf.d
nano $PREFIX/etc/nginx/conf.d/nextcloud.conf

Paste the following content (adjust server_name if you plan to use a custom hostname):

server {
    listen 8080 default_server;
    server_name localhost;
    root /data/data/com.termux/files/home/nextcloud;

    index index.php index.html /index.php;

    client_max_body_size 1024M;
    fastcgi_buffers 64 4K;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
        deny all;
    }

    location ~ \.php(?:$|/){
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_pass unix:/data/data/com.termux/files/usr/var/run/php-fpm.sock;
    }

    location ~ \\.{php|phar}$ {
        deny all;
    }
}

This configuration listens on port 8080 – you can change it later if needed.

Step 7 – Start Services

We need three daemons running: MariaDB, PHP‑FPM, and Nginx. Termux provides the termux-services package to manage them, but for simplicity we’ll start them manually.

  1. Start MariaDB (if not already running):
mysqld_safe --datadir=$PREFIX/var/lib/mysql &
  1. Start PHP‑FPM:
php-fpm -y $PREFIX/etc/php/php-fpm.conf &
  1. Start Nginx:
nginx -c $PREFIX/etc/nginx/nginx.conf

If you receive “permission denied” for the socket, make sure the directory $PREFIX/var/run exists:

mkdir -p $PREFIX/var/run && php-fpm -y $PREFIX/etc/php/php-fpm.conf &

Step 8 – Complete the Web Installer

Open a browser on any device connected to the same Wi‑Fi network and navigate to:

http://PHONE_IP_ADDRESS:8080

Replace PHONE_IP_ADDRESS with the IP shown by ifconfig or ip addr inside Termux. You should see the Nextcloud setup wizard.

  1. Choose an admin username and a strong password.
  2. When prompted for “Data folder”, keep the default (/data/data/com.termux/files/home/nextcloud/data) or point to a location on external storage (requires proper permissions).
  3. Enter the database details you created earlier:
    • Database user: nc_user
    • Database password: the password you set
    • Database name: nextcloud
    • Host: localhost
  4. Click “Finish setup”. Nextcloud will perform migrations and finish installation. This may take a minute.

When the dashboard appears, you have a working Nextcloud instance!

Step 9 – Enable HTTPS (Optional but Recommended)

Running on plain HTTP is fine for local use, but if you ever expose the server to the internet you’ll want TLS.

  1. Generate a self‑signed certificate (valid for 1 year):
openssl req -newkey rsa:2048 -nodes -keyout nextcloud.key -x509 -days 365 -out nextcloud.crt -subj "/C=US/ST=State/L=City/O=MyNextcloud/OU=IT/CN=$(hostname)"
  1. Move the files to a location Nginx can read:
mkdir -p $PREFIX/etc/nginx/ssl
mv nextcloud.key nextcloud.crt $PREFIX/etc/nginx/ssl/
  1. Edit nextcloud.conf to listen on 443 and use the certificate:
nano $PREFIX/etc/nginx/conf.d/nextcloud.conf

Replace the existing listen 8080 default_server; line with:

listen 443 ssl http2;
ssl_certificate $PREFIX/etc/nginx/ssl/nextcloud.crt;
ssl_certificate_key $PREFIX/etc/nginx/ssl/nextcloud.key;

Optionally keep the HTTP block and add a redirect:

server {
    listen 80;
    server_name localhost;
    return 301 https://$host$request_uri;
}
  1. Reload Nginx:
nginx -s reload

Now access the server via https://PHONE_IP_ADDRESS. Your browser will warn about a self‑signed cert – accept it for local testing.

Step 10 – Keep the Server Running After Closing Termux

Termux sessions stop when you close the app. To keep Nextcloud alive, use the termux-wake-lock command or install the termux-services package and create a service script.

  1. Install the service manager:
pkg install termux-services
  1. Create a service file for each daemon. Example for MariaDB (~/.termux/boot/mariadb.sh):
#!/data/data/com.termux/files/usr/bin/sh
mysqld_safe --datadir=$PREFIX/var/lib/mysql &

Make it executable:

chmod +x ~/.termux/boot/mariadb.sh
  1. Repeat for PHP‑FPM and Nginx (e.g., php-fpm.sh and nginx.sh).
  2. Enable the boot scripts:
termux-setup-storage   # grants storage permission if not yet done
termux-wake-lock       # prevents Doze mode from killing the process

Now, whenever you open Termux, run the three scripts or add them to ~/.bashrc for automatic start.

Step 11 – Accessing Nextcloud From Other Devices

  • Open the Nextcloud app (available on Google Play) on any Android device and enter the server URL (https://PHONE_IP_ADDRESS or http://PHONE_IP_ADDRESS:8080).
  • Log in with the admin credentials you created.
  • Upload files, create folders, and explore the web interface just like a regular cloud service.

Because the server runs on your phone, files are stored on the device’s internal storage or on an attached SD card (if you configured the data folder there).

Troubleshooting Common Issues

1. Port Already in Use

If Nginx fails to start with “bind() to 0.0.0.0:8080 failed (98: Address already in use)”, another app is occupying the port. Either stop that app or change the listen directive to an unused port (e.g., 8081) and adjust the URL accordingly.

2. PHP Errors – “Class not found”

Make sure all required PHP extensions are enabled in php.ini. If you see messages about missing intl or gd, install them via:

pkg install php-intl php-gd

Then restart php-fpm.

3. Database Connection Failed

Double‑check the username, password, and database name you entered in the web installer. You can test the connection manually:

mysql -u nc_user -p -e "SHOW DATABASES;"

If the command fails, revisit the steps in Step 4.

4. File Permission Errors

Nextcloud needs write access to the data folder and the configuration directory. Set the correct ownership:

chmod -R 750 ~/nextcloud
chmod -R 750 ~/nextcloud/data

If you store data on external SD card, ensure Termux has the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions (run termux-setup-storage).

5. Server Stops When Device Sleeps

Android’s Doze mode can pause background processes. Use termux-wake-lock while the server is needed, or whitelist Termux from battery optimizations:

settings put global ignore_battery_optimize 1

Note: The exact path may differ per manufacturer; you can also manually disable battery optimisation for Termux in Settings → Battery → Battery optimisation.

Security & Maintenance Tips

  • Keep packages updated. Periodically run pkg upgrade -y inside Termux.
  • Back up the database. Export it with mysqldump -u nc_user -p nextcloud > nextcloud.sql and store the dump on another device or cloud.
  • Update Nextcloud. When a new version is released, download the latest tarball, replace the old files (preserve the config and data folders), and run the web updater or the occ command:
php occ upgrade

Run the command from the Nextcloud directory:

cd ~/nextcloud && php occ upgrade
  • Use HTTPS. For any remote access, replace the self‑signed certificate with one from Let’s Encrypt (requires a public domain and port forwarding) or use a reverse proxy on a home router.
  • Limit exposure. If you only need local access, keep the firewall on your router closed to inbound connections.
  • What You’ve Achieved

    By following this guide you now have a fully functional Nextcloud server running directly on your Android phone, without rooting or flashing custom firmware. You can store files, share links, sync calendars, and even install Nextcloud apps (e.g., Talk, Photos) just as you would on a dedicated NAS.

    The same principles apply to other lightweight web services – you’ve essentially turned Termux into a mini Linux environment capable of hosting PHP‑based applications.

    Tip: If you plan to use the server for longer periods, consider mounting an external USB‑OTG drive and pointing the Nextcloud data folder to it. This preserves internal storage and provides faster read/write speeds.

    User Comments (0)

    Add Comment
    We'll never share your email with anyone else.