How to Deploy a Flask App on Termux for Local Testing


Running a Flask web app directly on your Android phone might sound tricky, but with Termux, it’s surprisingly easy. Termux allows you to run Linux commands and tools like Python, making it possible to set up and test your Flask applications anywhere — no laptop required.
In this guide, we’ll walk you through installing Flask in Termux, creating a simple app, and running it locally for testing. If you’re new to Termux, check out Things to Do After Installing Termux before continuing.
Why Run Flask in Termux?
Using Termux for local Flask development is great if you want:
A mobile-friendly development environment without carrying a PC.
To test Python web apps before deploying them to production.
A simple way to learn Flask alongside other tools like Nmap in Termux or Ngrok in Termux.
Step 1: Update Termux Packages
Always start by updating your Termux environment:
pkg update && pkg upgrade -y
If you’re still setting up Termux, you might also want to explore Quick Termux Projects You Can Do.
Step 2: Install Python and Pip
Flask runs on Python, so you need to install it first:
pkg install python -y
Pip comes with Python in Termux, so you can use it right away.
Step 3: Install Flask
Now install Flask:
pip install flask
For more Termux Python projects, see Turn Your Android into a Web Server.
Step 4: Create a Basic Flask App
- Create a project folder:
mkdir flask_app && cd flask_app
- Create your app file:
nano app.py
- Paste this code:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return "Hello from Flask on Termux!"
if __name__ == '__main__':
app.run(host='127.0.0.1', port=5000)
Save with CTRL + O, then exit with CTRL + X.
Step 5: Run Your Flask App
python app.py
You should see:
* Running on http://127.0.0.1:5000
Step 6: Open in Your Browser
Go to:
http://127.0.0.1:5000
You should see:
Hello from Flask on Termux!
Step 7: Share Over the Internet (Optional)
If you want others to access your Flask app, you can pair it with Ngrok in Termux or explore How to Run Node.js Servers and Share Public URLs via Termux.
Related Posts for You
Here are some other guides you might find useful:
This kind of setup not only makes your Flask projects mobile but also integrates perfectly with other Termux tools like Netcat or Weeman.
Subscribe to my newsletter
Read articles from Stephano kambeta directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
