DEV Community

Shanmugananthan A K
Shanmugananthan A K

Posted on

πŸ“±βœ¨ Host a Live Website from Your Android Phone Using Termux + Cloudflare Tunnel

A Step-by-Step Guide for Beginners (No Root Needed!)

🌟 What You’ll Learn

In this tutorial, you’ll learn how to:

  • Turn your Android phone into a mini web server using Termux
  • Serve a simple HTML website
  • Make your site accessible publicly over the internet (with HTTPS!)
  • Use Cloudflare Tunnel with your custom domain
  • All of this β€” without root access, and just using your mobile device!

🧰 Requirements

πŸ“± Android Phone = Any modern device (no root required)
πŸ“² Termux App Install = from F-Droid (recommended)
🌐 Internet Access = WiFi or Mobile Data
πŸ” Cloudflare Account = Free plan is enough
🌍 A Domain Name = Optional, but recommended

πŸ—οΈ Step-by-Step Instructions

Let’s walk through the entire setup with real commands. πŸ”§

🟒 1. Install Termux & Update Packages
pkg update && pkg upgrade

This updates Termux and its tools to the latest versions.

🌩️ 2. Install Cloudflared (Cloudflare Tunnel CLI)
pkg install cloudflared

Cloudflared allows you to create a secure tunnel to your local web server.

πŸ—‚οΈ 3. Create a Simple Website
mkdir ~/mysite
cd ~/mysite
echo '<h1>Welcome to Termux Site</h1>' > index.html

This creates a simple HTML page with a welcome message.

🌐 4. Start a Local Web Server
cd ~/mysite
python -m http.server 8000
This starts a local server at http://localhost:8000.

πŸ“ You can test it by visiting http://localhost:8000 in Termux’s browser or with curl.

🌍 5. Make Your Site Public with Cloudflare Tunnel
cloudflared tunnel --url http://localhost:8000

This will create a public link like:

https://some-random-string.trycloudflare.com

βœ… Now your site is live on the internet! Share the link!

πŸ’‘ Optional: Keep Server & Tunnel Running in Background

nohup python -m http.server 8000 > python.log 2>&1 &
nohup cloudflared tunnel --url http://localhost:8000 > tunnel.log 2>&1 &

This keeps the server and tunnel running even if you close Termux.

🌐 Bonus: Use Your Own Domain with Cloudflare

πŸ” 6. Login to Cloudflare
cloudflared login

This opens a URL to authenticate with Cloudflare. Open it in your phone browser and follow the instructions.

πŸ”§ 7. Create a Named Tunnel
cloudflared tunnel create app.shanmugananthan

This creates a persistent tunnel named app.shanmugananthan.

πŸ› οΈ 8. Configure Tunnel
mkdir -p ~/.cloudflared
nano ~/.cloudflared/config.yml

Paste the following into the file:
`tunnel: app.shanmugananthan
credentials-file: /data/data/com.termux/files/home/.cloudflared/app.shanmugananthan.json

ingress:

Press CTRL + O β†’ Enter to save, and CTRL + X to exit.

  1. Route Domain to Tunnel cloudflared tunnel route dns app.shanmugananthan app.shanmugananthan.com

This tells Cloudflare to route requests to your domain through the tunnel.

πŸš€ 10. Run the Tunnel
cloudflared tunnel run app.shanmugananthan

Or, run it in the background:
nohup cloudflared tunnel run app.shanmugananthan > tunnel.log 2>&1 &

Now your site is live on your own custom domain (with free HTTPS via Cloudflare)!

πŸ” Recap of Commands
`pkg update && pkg upgrade
pkg install cloudflared
mkdir ~/mysite && cd ~/mysite
echo '

Welcome to Termux Site

' > index.html
python -m http.server 8000
cloudflared tunnel --url http://localhost:8000

Background:

nohup python -m http.server 8000 > python.log 2>&1 &
nohup cloudflared tunnel --url http://localhost:8000 > tunnel.log 2>&1 &
`

For custom domain setup:
cloudflared login
cloudflared tunnel create <tunnel-name>
nano ~/.cloudflared/config.yml
cloudflared tunnel route dns <tunnel-name> <your-domain.com>
cloudflared tunnel run <tunnel-name>

βœ… Final Output

Your site is now:

βœ… Live
πŸ”’ Secured with HTTPS
🌐 Accessible globally
🧠 Hosted entirely from your Android phone!

πŸ’¬ FAQs

Q: Can I use this for dynamic websites?
Yes, you can use frameworks like Flask, Node.js, or PHP with a bit more setup.

Q: Will it stay online 24/7?
As long as Termux and your phone stay awake. You can use apps like Termux:Boot and battery settings to keep it alive longer.

Q: Is it free?
Yes! Everything used β€” Termux, Python server, and Cloudflare Tunnel β€” is 100% free.

✨ Conclusion

You just turned your Android phone into a live web server, accessible worldwide via Cloudflare Tunnel, using only Termux β€” no root, no paid hosting, and HTTPS included. πŸ’₯

This approach is perfect for:

⚑ Quick project demos
πŸ§ͺ Learning web hosting basics
πŸ› οΈ Emergency backup sites
🌐 Personal landing pages
If this helped you, feel free to connect or follow me for more tutorials and self-hosted tech setups:

πŸ”— Let’s Connect

πŸ’Ό LinkedIn
πŸ“Έ Instagram
πŸ™ GitHub
▢️ YouTube

Top comments (0)