Run a Local Web Server on Android
This guide explains how to set up a lightweight local web server on your Android device using Termux. This is perfect for testing HTML/CSS/JS projects or practicing web development on the go.
Step 1: Prepare the System
First, update and upgrade your Termux packages to ensure everything is current.
pkg update && pkg upgrade -y
Step 2: Install Python
Python includes a built-in module for running a simple HTTP server, which is ideal for our needs.
pkg install python -y
Step 3: Create a Project Directory
Create a dedicated folder for your website and navigate into it.
mkdir mywebsite && cd mywebsite
Step 4: Create a Webpage
Use the nano editor to create an index.html file with some basic content.
nano index.html
Paste the following HTML into the editor:
<h1>Welcome to My Local Server</h1> <p>This website is running on Android using Termux.</p>
To save in Nano: Press CTRL + X, then Y, then Enter.
Step 5: Start the Web Server
Run the Python HTTP server module on port 8080.
python -m http.server 8080
Step 6: Access the Server
Open your mobile browser and navigate to the following local address:
http://127.0.0.1:8080
Advanced: Exposing the Server Globally
To make your local server accessible from the internet, you can use Cloudflared.
pkg install cloudflared -y cloudflared tunnel --url http://127.0.0.1:8080