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:
β 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:
- hostname: app.shanmugananthan.com service: http://localhost:8000
- service: http_status:404`
Press CTRL + O β Enter to save, and CTRL + X to exit.
- 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.htmlpython -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
Top comments (0)