DEV Community

Stephano Kambeta
Stephano Kambeta

Posted on

Turn Your Android Phone Into a Local Development Server With Termux

You don't always need a computer to test a website or run a small development project.

With Termux, your Android phone can run a local development server. You can use it to test websites, run Python applications, work with APIs, or access projects from another device on the same network.

It is not a replacement for a production server, but it can be useful for development and testing.

What You Need

To get started, you mainly need:

  • An Android phone
  • Termux
  • A development project
  • A local network if you want to access the server from another device

Termux provides the command-line environment where you can install the tools needed to run your server. If you're just getting set up, it's worth running through our list of things to do after installing Termux first.

Start by updating its packages:

pkg update
pkg upgrade
Enter fullscreen mode Exit fullscreen mode

You can then install Python:

pkg install python
Enter fullscreen mode Exit fullscreen mode

Check that it works:

python --version
Enter fullscreen mode Exit fullscreen mode

For a more detailed walkthrough of setting up Python itself in Termux, see our guide on installing and using Python in Termux.

Create a Simple Website

Let's start with a basic HTML page.

Create a directory for your project:

mkdir ~/my-site
cd ~/my-site
Enter fullscreen mode Exit fullscreen mode

Create an HTML file:

nano index.html
Enter fullscreen mode Exit fullscreen mode

Add some simple HTML:

<!DOCTYPE html>
<html>
<head>
    <title>My Local Server</title>
</head>
<body>
    <h1>Hello from Android</h1>
    <p>This website is running from Termux.</p>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Save the file and return to the terminal.

Start the Local Server

Python includes a simple HTTP server that you can use for testing.

From your project directory, run:

python -m http.server 8000
Enter fullscreen mode Exit fullscreen mode

You should see a message indicating that the server is listening on port 8000.

Open a browser on your Android phone and visit:

http://127.0.0.1:8000
Enter fullscreen mode Exit fullscreen mode

Your website should now load.

The server is running directly on your phone. If you'd rather run a more full-featured web server instead of Python's built-in one, see our guide on installing and using Nginx in Termux.

What Is Localhost?

You may have seen addresses such as localhost or 127.0.0.1 before.

They refer to the device running the server.

So when you open:

http://127.0.0.1:8000
Enter fullscreen mode Exit fullscreen mode

your browser is connecting to the web server running on the same Android device.

The 8000 part is the port where the server is listening.

You can use another port if necessary:

python -m http.server 8080
Enter fullscreen mode Exit fullscreen mode

Then open:

http://127.0.0.1:8080
Enter fullscreen mode Exit fullscreen mode

Access the Server From Another Device

You can also access your Termux server from another device on the same Wi-Fi network.

First, find your phone's local IP address.

One way to do this in Termux is:

ip addr
Enter fullscreen mode Exit fullscreen mode

Look for an address associated with your Wi-Fi connection, such as:

192.168.1.25
Enter fullscreen mode Exit fullscreen mode

Start your server so it listens beyond the local loopback interface:

python -m http.server 8000 --bind 0.0.0.0
Enter fullscreen mode Exit fullscreen mode

Then, from another device connected to the same network, open:

http://192.168.1.25:8000
Enter fullscreen mode Exit fullscreen mode

Replace the IP address with the one assigned to your phone.

You can now test your website from another phone, tablet, or computer. If you ever need to reach that server from outside your local network rather than just your Wi-Fi, our guide on installing and using ngrok in Termux covers exposing a local port to the internet.

Run a Python Application

The same idea works with Python applications.

For example, you can install Flask:

pip install flask
Enter fullscreen mode Exit fullscreen mode

Create a file:

nano app.py
Enter fullscreen mode Exit fullscreen mode

Add:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello from Termux!"

app.run(host="0.0.0.0", port=5000)
Enter fullscreen mode Exit fullscreen mode

Run it:

python app.py
Enter fullscreen mode Exit fullscreen mode

You can then open:

http://127.0.0.1:5000
Enter fullscreen mode Exit fullscreen mode

You now have a small Python web application running locally on Android.

Run an API Locally

You can also use Termux to test APIs before deploying them somewhere else.

For example, your development setup could look like this:

Android
   ↓
Termux
   ↓
Python application
   ↓
Local API
Enter fullscreen mode Exit fullscreen mode

You could create endpoints for testing things such as authentication, JSON responses, forms, or database interactions.

This is useful when you want to experiment without immediately deploying your project to a remote server. It's the same pattern we used in our guide on automating Android tasks with Termux and AI, where a local script or endpoint becomes the entry point for a larger workflow.

Use Your Existing Projects

Termux can work with Git, so you can clone an existing project and run it on your phone.

Install Git:

pkg install git
Enter fullscreen mode Exit fullscreen mode

Then clone a repository:

git clone https://github.com/username/project.git
Enter fullscreen mode Exit fullscreen mode

Enter the project:

cd project
Enter fullscreen mode Exit fullscreen mode

From there, install the required dependencies and start the development server according to the project's instructions.

This makes your phone useful for testing projects when you don't have access to your usual development machine. If your project needs more than Termux's base environment can offer, you can also run a full Linux userspace alongside it with Termux and PRoot-Distro.

Keep the Server Running

One problem with running servers on Android is that the operating system may restrict background processes or terminate applications to save battery.

For longer-running Termux sessions, tools such as tmux can help keep your terminal session organized.

Install it with:

pkg install tmux
Enter fullscreen mode Exit fullscreen mode

Start a session:

tmux
Enter fullscreen mode Exit fullscreen mode

You can then run your development server inside that session.

This does not guarantee that Android will keep the process alive indefinitely, but it is useful when working with longer development sessions.

What Can You Use It For?

A local Termux server can be useful for many development tasks.

You can use it to:

  • Test HTML and CSS
  • Run small JavaScript projects
  • Develop Python applications
  • Test local APIs
  • Experiment with web frameworks
  • Share a development site over your local network
  • Work with Git repositories
  • Learn how web servers work

It can also be useful for quick experiments when you don't want to set up a full development environment on a computer — much like the ideas covered in our quick Termux projects you can try.

Is It a Real Server?

Technically, your phone is serving files or responding to requests, so it is acting as a server.

But there is an important difference between a local development server and a production server.

A Termux server is mainly useful for development, testing, learning, and temporary local services.

You should not treat a basic Python development server as a secure production hosting solution.

For a public website or application, you would normally use a properly configured server or cloud platform with appropriate security, monitoring, backups, and network configuration.

Final Thoughts

Termux can turn an Android phone into a surprisingly useful development environment.

With just Python and a few commands, you can serve a website, run an API, test an application, or access your project from another device on the same network.

It won't replace a full development machine for every project, but sometimes you only need a terminal, a few packages, and a phone.

What kind of development project would you try running locally on your Android phone?

Top comments (0)