Set Up a Local Web Development Server on Android Using Termux

20 min read Learn step‑by‑step how to turn an Android phone into a local web development server with Termux. Install Node, Python, PHP, or Nginx and test your sites without rooting. October 09, 2026 21:00 How to Set Up a Local Web Development Server on Android Using Termux (No Root)

Before you start

Preparing your device correctly saves you from dead‑ends later. Follow these checks before installing anything.

  • Android version: Android 7.0 (Nougat) or newer. Termux runs on most recent builds, but very old versions may lack required libraries.
  • Storage space: Allocate at least 500 MB for the server stack and your project files.
  • Internet connection: You’ll need Wi‑Fi to download packages. A stable connection speeds up the initial setup.
  • Power source: Keep the phone plugged in or fully charged; compiling packages can be CPU‑intensive.
  • Optional hardware: An external keyboard or a Bluetooth keyboard makes typing long commands easier.

If you plan to expose the server beyond your local network, read the Security warning at the end of the guide.

Step 1 – Install Termux and give it storage access

  1. Open the F‑Droid page for Termux (recommended for the latest stable build) and tap Install. The Play Store version is also acceptable.
  2. Launch Termux. The first run will set up the basic environment.
  3. Run termux-setup-storage. This command creates a ~/storage shortcut and asks for the standard Android storage permission. Grant it.

After granting permission you’ll see three symbolic links: shared, downloads, and external. You can store your web projects under ~/storage/shared/termux-web if you want them visible to other apps.

Step 2 – Update the package repository

  1. In Termux, execute:
    pkg update && pkg upgrade -y
  2. This refreshes the package list and upgrades any outdated libraries. Accept the prompts.

Keeping packages up‑to‑date prevents compilation errors later on.

Step 3 – Install the core web‑server tools

Termux’s pkg command pulls pre‑compiled binaries, which makes installation fast. Choose the stack that matches the language you plan to use.

  1. Common utilities (git, curl, wget):
    pkg install -y git curl wget
  2. Node.js (for JavaScript/Express apps):
    pkg install -y nodejs
  3. Python (for Flask or Django):
    pkg install -y python
  4. PHP (for simple scripts or Laravel):
    pkg install -y php
  5. NGINX (a lightweight HTTP server):
    pkg install -y nginx
  6. OpenSSL (useful for generating self‑signed certificates):
    pkg install -y openssl-tool

All of these packages install into Termux’s private filesystem (/data/data/com.termux/files/usr) and do not interfere with the system.

Step 4 – Choose a project directory

For clarity, create a dedicated folder for your web work.

  1. Navigate to the shared storage area:
    cd ~/storage/shared
  2. Create a folder called termux-web and move into it:
    mkdir termux-web && cd termux-web
  3. Inside, create a sub‑folder for the specific stack you’ll test, e.g. node-demo:
    mkdir node-demo && cd node-demo

Using the shared storage makes it easy to edit files later with a GUI editor like QuickEdit or VS Code Remote on a PC.

Step 5 – Create a simple server (Node.js example)

Node.js is popular for quick prototypes. The same workflow applies to Python or PHP – we’ll add those later.

  1. Initialize a new npm project:
    npm init -y
  2. Install the Express framework (optional but convenient):
    npm install express
  3. Create a file called server.js:
    cat > server.js <<'EOF'
    const express = require('express');
    const app = express();
    const PORT = 8080;
    app.get('/', (req, res) => {
      res.send('Hello from Termux!');
    });
    app.listen(PORT, () => console.log(`Server listening on http://0.0.0.0:${PORT}`));
    EOF
  4. Start the server:
    node server.js

You should see the message Server listening on http://0.0.0.0:8080. The 0.0.0.0 bind tells the server to listen on all network interfaces, which is required for other devices to reach it.

Step 6 – Verify the server locally

Open the Android browser (Chrome, Edge, etc.) and navigate to http://127.0.0.1:8080 or http://localhost:8080. You should see the text “Hello from Termux!”. If the page does not load:

  • Check that the Node process is still running (look for node server.js in the terminal).
  • Confirm that the port number matches the one in your code.
  • Make sure you didn’t accidentally start the server with sudo – Termux does not have sudo, and the command would have failed.

Step 7 – Access the server from another device on the same Wi‑Fi

This step proves that the phone is acting as a true network host.

  1. Find your phone’s local IP address:
    ip addr show wlan0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
  2. On a laptop, tablet, or another phone connected to the same Wi‑Fi, open a browser and go to http://<PHONE_IP>:8080. Replace <PHONE_IP> with the number you just retrieved.
  3. You should see the same “Hello from Termux!” message.

If the request times out, try these checks:

  • Is the phone on the same subnet? Most home routers use 192.168.1.x or 10.0.0.x. Both devices must share the prefix.
  • Does the router have client‑isolation enabled? Some guest networks block device‑to‑device traffic.
  • Did you forget to allow the app to use the network? Termux requests the INTERNET permission automatically, but some custom ROMs require manual approval in Settings → Apps → Termux → Permissions.

Step 8 – Try a Python Flask server (optional)

Flask is a micro‑framework that runs with a single command. It’s useful for quick APIs.

  1. Navigate back to the project root or create a new folder:
    cd ~/storage/shared/termux-web && mkdir flask-demo && cd flask-demo
  2. Install Flask via pip:
    pip install flask
  3. Create app.py:
    cat > app.py <<'EOF'
    from flask import Flask
    app = Flask(__name__)
    
    @app.route('/')
    def hello():
        return "Hello from Flask on Termux!"
    
    if __name__ == '__main__':
        app.run(host='0.0.0.0', port=5000)
    EOF
  4. Run the server:
    python app.py

Open http://127.0.0.1:5000 on the phone or http://<PHONE_IP>:5000 from another device. The response should be “Hello from Flask on Termux!”.

Step 9 – Set up a PHP script with NGINX

NGINX can serve static files and proxy to PHP‑FPM. In Termux, we’ll use the built‑in PHP built‑in server for simplicity, but we’ll also show how to start NGINX.

  1. Create a folder for the PHP demo:
    mkdir -p ~/storage/shared/termux-web/php-demo && cd $_
  2. Create index.php:
    cat > index.php <<'EOF'
    
    EOF
  3. Start the built‑in PHP server (quick test):
    php -S 0.0.0.0:8081
  4. Visit http://<PHONE_IP>:8081 from another device. You should see the PHP output.
  5. If you prefer NGINX, edit its config:
    nano $PREFIX/etc/nginx/nginx.conf
    Replace the server block with:
    server {
        listen 8082;
        server_name _;
        root /data/data/com.termux/files/home/storage/shared/termux-web/php-demo;
        index index.php;
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME  $request_filename;
        }
    }
  6. Start PHP‑FPM (Termux ships a php-fpm binary):
    php-fpm
  7. Start NGINX:
    nginx
  8. Now browse to http://<PHONE_IP>:8082 to see the same message.

NGINX is optional for simple demos, but it mirrors a production setup where static assets are served directly and dynamic requests are handed to PHP‑FPM.

Step 10 – Keep the server alive after you close the terminal

Termux sessions end when you swipe the app away or when Android reclaims resources. Two tools help you run services in the background.

Option A – Use termux-wake-lock

  1. Install the wake‑lock utility (if not already present):
    pkg install -y termux-api
  2. Before starting your server, run:
    termux-wake-lock
  3. Now start the server as usual. The wake lock prevents the CPU from sleeping, keeping the process alive.
  4. When you are finished, release the lock with termux-wake-unlock.

Option B – Use tmux or screen

Both provide detachable terminal sessions.

  1. Install tmux:
    pkg install -y tmux
  2. Start a new session named web:
    tmux new -s web
  3. Inside the tmux window, launch your server (e.g., node server.js).
  4. Detach from the session without stopping the process by pressing Ctrl+b then d.
  5. Later, re‑attach with tmux attach -t web to view logs or stop the server.

Using tmux is especially handy when you want to run multiple services simultaneously (e.g., Node API on 8080 and Flask on 5000).

Step 11 – Edit files comfortably

Termux includes vim and nano, but many developers prefer a graphical editor.

  • Vim/NeoVim: Install with pkg install -y vim. Learn basic commands (:wq, /search) for quick edits.
  • External editor: Use the termux-open command to launch a file in a third‑party app, e.g., termux-open server.js.
  • Remote editing: Install openssh (pkg install -y openssh) and enable the SSH daemon:
    sshd
    Then connect from a PC using ssh u0_aXXX@<PHONE_IP>. This gives you full VS Code Remote or Sublime Text editing capabilities.

Step 12 – Secure your local server (optional but recommended)

Even a development server can be abused if left open on a public Wi‑Fi. Here are low‑effort hardening steps.

  • Bind to localhost only: If you only need to test on the phone itself, change the bind address to 127.0.0.1 in your code.
  • Use a self‑signed TLS certificate:
    openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out cert.pem -subj "/CN=android-local"
    Then start Node with node server.js --tls-key key.pem --tls-cert cert.pem (or configure Flask/NGINX accordingly).
  • Basic authentication: For quick protection, add a middleware that checks an Authorization header.
  • Firewall with termux‑iptables: Install iptables (pkg install -y iptables) and block inbound traffic except from your own IP range.

These measures are optional for pure local development, but they illustrate good security hygiene.

Step 13 – Troubleshooting common problems

Port already in use

If you see EADDRINUSE (Node) or “Address already in use” (Python), another process is listening on the same port.

  • List occupied ports:
    netstat -tuln | grep LISTEN
  • Kill the offending process:
    kill -9 <PID>
  • Or simply change the port number in your code (e.g., 8080 → 8083).

Cannot bind to 0.0.0.0

Some Android builds restrict apps from listening on non‑loopback interfaces unless the app has the INTERNET permission, which Termux already declares. If binding fails, try:

  • Restart Termux to refresh the permission state.
  • Check SELinux mode with getenforce. If it returns Enforcing, you may need to switch to Permissive via setenforce 0, but this requires root. In a no‑root scenario, the workaround is to bind to 127.0.0.1 and use adb reverse tcp:8080 tcp:8080 to forward the port to a PC.

Server not reachable from other devices

  • Confirm the phone’s Wi‑Fi is not in “Metered” or “Data Saver” mode, which can block inbound traffic.
  • Disable any VPN that isolates the device.
  • Test with ping <PHONE_IP> from the other device to verify basic connectivity.

Termux closes unexpectedly

Android may kill background processes to reclaim RAM.

  • Enable Battery optimization exemption for Termux: Settings → Apps → Termux → Battery → Allow background activity.
  • Use the termux-wake-lock method described earlier.

Step 14 – Real‑world use cases

Now that the basics work, here are a few practical scenarios where a local Android server shines.

  • Quick API mock: When testing a mobile app on the same device, spin up a Flask mock that returns JSON fixtures.
  • Static site preview: Build a Jekyll or Hugo site on a laptop, copy the _site folder to ~/storage/shared/termux-web/site, and serve it with NGINX for on‑the‑go demos.
  • IoT gateway: Use Node‑RED (installable via npm install -g node-red) to connect Bluetooth sensors to your phone and expose data over HTTP.

Because everything runs in user space, you can experiment without risking the system partition.

Security warning – Do not expose the server to the public internet without proper hardening

Termux does not provide a firewall UI, and the binaries run with the same privileges as your user account. If you forward ports through your router (port‑forwarding) or use a reverse‑proxy service, anyone on the internet could reach your phone. Always:

  • Use strong authentication (basic auth, JWT, or OAuth) for any endpoint that modifies data.
  • Serve over HTTPS with a self‑signed certificate or a free Let’s Encrypt certificate if you have a public domain.
  • Keep the server process stopped when not in use.

With the steps above you now have a fully functional, portable web development environment on your Android device. Whether you’re debugging a React Native backend, prototyping a Python API, or simply need a quick static file server, Termux gives you the flexibility of a Linux workstation in the palm of your hand.

User Comments (0)

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