Set Up a Local HTTP/HTTPS File Server on Android with Termux

15 min read Turn your Android phone into a local web server using Termux. This step‑by‑step tutorial shows how to install Python, run HTTP and HTTPS servers, and keep them running reliably. October 10, 2026 10:00 How to Set Up a Local HTTP/HTTPS File Server on Android with Termux

Before you start

Running a web server on your Android device is safe as long as you keep the server on a trusted Wi‑Fi network and use HTTPS when possible. The steps below assume you have a recent Android version (7.0+), enough free storage (a few MB for Termux and Python), and a stable Wi‑Fi connection.

  • Battery: Plug the device in or ensure at least 50 % charge.
  • Network: Connect to a private Wi‑Fi network; avoid public hotspots where other users could reach your server.
  • Permissions: Termux needs storage access to serve files from your device. We'll grant it during the setup.

Step 1 – Install Termux and prepare the environment

  1. Open the F‑Droid page for Termux and install the latest version. (F‑Droid provides the most up‑to‑date, root‑free build.)
  2. Launch Termux. The first launch will install the basic package set and ask you to update the package repository.
  3. Run the following command to update everything:
    pkg update && pkg upgrade -y
  4. Grant storage permission so Termux can read files you want to serve:
    termux-setup-storage
    This creates a ~/storage folder that links to your shared storage (Downloads, Documents, etc.).

Why this matters: Updating the repository ensures you get the latest security patches, and the storage permission is required for the server to access files outside Termux’s private directory.

Step 2 – Install Python (the simplest way to run an HTTP server)

  1. In Termux, install the Python package:
    pkg install python -y
  2. Verify the installation:
    python --version
    You should see something like Python 3.11.x.

Python’s built‑in http.server module is lightweight and perfect for serving static files on a local network. No extra web server software is needed.

Step 3 – Choose a directory to serve

Pick a folder that contains the files you want to share. For this tutorial we’ll use the Downloads folder, but any folder works.

  1. Navigate to the shared storage root:
    cd ~/storage/downloads
  2. List the contents to confirm you’re in the right place:
    ls -l

If you prefer a private folder, create one inside Termux’s home directory (e.g., mkdir -p ~/myweb) and copy files there.

Step 4 – Start a plain HTTP server

  1. Run the following command while you’re inside the directory you want to serve:
    python -m http.server 8000
    The number 8000 is the port. You can choose any unused port above 1024.
  2. You should see output similar to:
    Serving HTTP on :: port 8000 (http://[::]:8000/) ...
  3. On a computer connected to the same Wi‑Fi, open a browser and type:
    http://YOUR_PHONE_IP:8000
    Replace YOUR_PHONE_IP with the IP address shown by ip addr show wlan0 or by checking Settings > About > Status.

When you open the URL you’ll see a directory listing of the files you placed in the served folder. Clicking a file will download or display it, depending on the MIME type.

Step 5 – Upgrade to HTTPS for privacy

Plain HTTP transmits data unencrypted, which is fine for a closed home network but not ideal if you’re sharing sensitive files. We’ll create a self‑signed certificate and wrap the server with openssl’s s_server utility.

  1. Install OpenSSL inside Termux:
    pkg install openssl -y
  2. Create a directory to hold the certificate and key:
    mkdir -p ~/certs && cd ~/certs
  3. Generate a self‑signed certificate valid for one year:
    openssl req -x509 -newkey rsa:2048 -sha256 -days 365 \
      -nodes -keyout server.key -out server.crt \
      -subj "/C=US/ST=State/L=City/O=MyOrg/OU=IT/CN=android.local"
  4. Return to the folder you want to serve (e.g., ~/storage/downloads) and start the HTTPS tunnel:
    openssl s_server -quiet -cert ~/certs/server.crt -key ~/certs/server.key -port 8443 -WWW
    The -WWW flag tells OpenSSL to serve files from the current directory.
  5. From a browser on the same network, navigate to:
    https://YOUR_PHONE_IP:8443
    The browser will warn that the certificate is not trusted. Accept the exception (usually “Advanced → Proceed”) because you generated the cert yourself.

Why use OpenSSL instead of Python’s built‑in HTTPS server? Python’s http.server can be invoked with --bind and --directory, but its HTTPS support is limited to development and requires a separate key file. OpenSSL’s s_server is lightweight, already available in Termux, and works well for quick, local sharing.

Step 6 – Keep the server running after you close the terminal

Termux’s shell closes when you swipe the app away, which would stop the server. There are three common ways to keep it alive:

  • nohup – runs a command immune to hangups.
  • screen or tmux – terminal multiplexers that let you detach and re‑attach later.
  • Termux:Boot – a plug‑in that executes scripts automatically after device boot.

We’ll demonstrate the nohup method because it requires no extra packages.

  1. Navigate to the directory you want to serve.
  2. Start the server with nohup and redirect output to a log file:
    nohup python -m http.server 8000 > ~/http.log 2>&1 &
    The trailing & puts the process in the background.
  3. Check that the process is running:
    ps | grep http.server
  4. To stop the server later, note the PID (first number in the ps line) and run:
    kill PID

For HTTPS, replace the python -m http.server command with the OpenSSL line inside nohup:

nohup openssl s_server -quiet -cert ~/certs/server.crt -key ~/certs/server.key -port 8443 -WWW > ~/https.log 2>&1 &

Step 7 – Optional: Auto‑start the server on boot

If you want the server to be available every time you power on the phone, install the Termux:Boot add‑on from the Play Store or F‑Droid.

  1. Install Termux:Boot.
    pkg install termux-api -y
    (The add‑on itself is installed via the store; the termux-api package provides helper commands.)
  2. Create a script in ~/.termux/boot (create the folder if it doesn’t exist):
    mkdir -p ~/.termux/boot
    cat > ~/.termux/boot/start‑server.sh <<'EOF'
    #!/data/data/com.termux/files/usr/bin/sh
    cd ~/storage/downloads
    nohup python -m http.server 8000 > ~/http.log 2>&1 &
    EOF
    chmod +x ~/.termux/boot/start‑server.sh
  3. Reboot the device. After the system starts, Termux:Boot will execute the script and your HTTP server will be listening on port 8000.

If you prefer HTTPS on boot, adjust the script to launch the OpenSSL command instead.

Step 8 – Verify the server from another device

  1. On a laptop, open a terminal and ping the phone to confirm network reachability:
    ping YOUR_PHONE_IP
  2. Use curl to fetch the index page:
    curl http://YOUR_PHONE_IP:8000
    You should see an HTML directory listing.
  3. For HTTPS, add -k to ignore the self‑signed cert warning:
    curl -k https://YOUR_PHONE_IP:8443

If the request times out, double‑check that the phone’s Wi‑Fi is on the same subnet and that no firewall on the router blocks the chosen port.

Step 9 – Common troubleshooting

Port already in use

If you see an error like OSError: [Errno 98] Address already in use, another app (perhaps the built‑in Android hotspot or a VPN) is occupying the port.

  • Run netstat -tuln | grep 8000 to see which process holds the port.
  • Choose a different port (e.g., 8080) and restart the server.
Cannot bind to 0.0.0.0

On some devices the default network interface is wlan0. If the server only listens on 127.0.0.1, external devices cannot connect.

  • Explicitly bind to all interfaces: python -m http.server 8000 --bind 0.0.0.0.
  • For OpenSSL, add -accept 8443 -cert ... -key ... -WWW -dhparam ~/certs/dhparam.pem if you need custom binding.
HTTPS certificate warnings

Browsers will flag the self‑signed cert as untrusted. This is expected. If you need a trusted cert for a home LAN, consider using mkcert to generate a local CA that devices can install.

Server stops after screen lock

Some manufacturers aggressively kill background processes when the screen turns off. If you notice the server disappearing:

  • Enable “Battery optimization” exemption for Termux (Settings > Apps > Termux > Battery > Allow background activity).
  • Use termux-wake-lock to keep the CPU awake while the server runs:
    termux-wake-lock && nohup python -m http.server 8000 &

Step 10 – Security best practices

  • Limit exposure: Only share the server on a private network. Do not open ports to the internet unless you understand NAT and firewall rules.
  • Use HTTPS for any personal data: Even on a LAN, HTTPS prevents other devices on the same Wi‑Fi from sniffing traffic.
  • Rotate certificates: Self‑signed certs have no revocation mechanism. Regenerate them periodically (e.g., every 6 months).
  • Remove files after sharing: Delete sensitive files from the served directory once they’re no longer needed.

Wrap‑up

By following these steps you’ve turned an Android phone into a lightweight, on‑demand file server. The solution works entirely without root, leverages the familiar Termux environment, and can be customized to serve over HTTP or HTTPS, run in the background, and even start automatically after a reboot. Use it for quick file transfers, testing web pages on a mobile device, or sharing media with friends on the same network.

User Comments (0)

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