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.
pkg update && pkg upgrade -y
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.
pkg install python -y
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.
Pick a folder that contains the files you want to share. For this tutorial we’ll use the Downloads folder, but any folder works.
cd ~/storage/downloads
ls -l
If you prefer a private folder, create one inside Termux’s home directory (e.g., mkdir -p ~/myweb) and copy files there.
python -m http.server 8000
The number 8000 is the port. You can choose any unused port above 1024.
Serving HTTP on :: port 8000 (http://[::]:8000/) ...
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.
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.
pkg install openssl -y
mkdir -p ~/certs && cd ~/certs
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"
~/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.
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.
Termux’s shell closes when you swipe the app away, which would stop the server. There are three common ways to keep it alive:
We’ll demonstrate the nohup method because it requires no extra packages.
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.
ps | grep http.server
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 &
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.
pkg install termux-api -y
(The add‑on itself is installed via the store; the termux-api package provides helper commands.)
~/.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
If you prefer HTTPS on boot, adjust the script to launch the OpenSSL command instead.
ping YOUR_PHONE_IP
curl to fetch the index page:
curl http://YOUR_PHONE_IP:8000
You should see an HTML directory listing.
-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.
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.
netstat -tuln | grep 8000 to see which process holds the port.On some devices the default network interface is wlan0. If the server only listens on 127.0.0.1, external devices cannot connect.
python -m http.server 8000 --bind 0.0.0.0.-accept 8443 -cert ... -key ... -WWW -dhparam ~/certs/dhparam.pem if you need custom binding.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.
Some manufacturers aggressively kill background processes when the screen turns off. If you notice the server disappearing:
termux-wake-lock to keep the CPU awake while the server runs:
termux-wake-lock && nohup python -m http.server 8000 &
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.









