A Used Android as a Web Server: A Complete Tutorial from Scratch
Turn a spare Android phone into a home web server with Termux and Nginx, from installation to hosting a website in your hand.
- Why a Used Android?
- Drawbacks
- Preparation
- Hardware You Need
- Software
- Step 1: Install Termux
- Step 2: Set Up Nginx
- Basic Nginx Configuration
- Step 3: Create a Website
- Step 4: Dynamic PHP Content
- Step 5: Set Up Auto-Start
- Step 6: Access from Outside
- Port Forwarding
- Dynamic DNS
- Cloudflare Tunnel (Recommended)
- Tips for Keeping the Server Stable
- Use Cases
- Android vs Raspberry Pi
- Conclusion
A used Android phone that nobody needs usually ends up in a drawer or gets sold for next to nothing. But in reality, that phone has huge potential: becoming a home web server. With a processor and RAM that are more than enough for light tasks, a used Android can run a website, an API server, or even a simple web app.
Why a Used Android?
| Advantage | Explanation |
|---|---|
| Cheap | You already own the used phone, no need to buy anything new |
| Low power draw | Consumes far less power than a PC |
| Portable | You can carry it anywhere |
| Always-on | Android is designed to run 24/7 |
| Battery backup | There is a built-in battery that acts as a UPS |
Drawbacks
- Limited storage, most phones have 32-64GB
- Limited RAM, 3-4GB is enough for a light web server
- Thermal throttling, the phone can get hot under high load
- No Ethernet port, only WiFi (unless you use a USB Ethernet adapter)
Preparation
Hardware You Need
- A used Android phone, at least Android 7, 3GB+ RAM, 32GB+ storage
- USB cable, for continuous charging
- USB OTG + Ethernet adapter (optional), for a more stable wired connection
- Micro SD card (optional), for extra storage
Software
- Termux, a terminal emulator for Android
- Nginx, a lightweight web server
- PHP (optional), for dynamic content
- MySQL/MariaDB (optional), database
Step 1: Install Termux
Download and install Termux from F-Droid (not the Play Store, since the Play Store version is outdated).
# After installing, open Termux and run:
pkg update && pkg upgrade
# Install the required packages
pkg install nginx
pkg install php
pkg install mysql
pkg install git
pkg install openssh
Step 2: Set Up Nginx
# Start nginx
nginx
# Check whether it is running
curl http://localhost
# It should print "Welcome to nginx!"
# Edit the configuration
nano $PREFIX/etc/nginx/nginx.conf
Basic Nginx Configuration
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server {
listen 8080;
server_name localhost;
root /data/data/com.termux/files/usr/share/nginx/html;
index index.html index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
}
Step 3: Create a Website
# Create the index.html file
cat > /data/data/com.termux/files/usr/share/nginx/html/index.html << 'EOF'
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Android Web Server</title>
<style>
body {
font-family: system-ui, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
background: #0D1117;
color: #F3F4F6;
}
h1 { color: #39FF14; }
.info {
background: #161B22;
padding: 20px;
border-radius: 8px;
margin: 20px 0;
}
</style>
</head>
<body>
<h1>Android Web Server</h1>
<div class="info">
<p>This server runs on a used Android phone.</p>
<p>Powered by Termux + Nginx</p>
<p>IP Address: <span id="ip"></span></p>
</div>
<script>
document.getElementById('ip').textContent = window.location.hostname;
</script>
</body>
</html>
EOF
Step 4: Dynamic PHP Content
# Create the PHP file
cat > /data/data/com.termux/files/usr/share/nginx/html/info.php << 'EOF'
<?php
phpinfo();
?>
# Start PHP-FPM
php-fpm
# Restart nginx
nginx -s reload
Now access http://IP_ANDROID:8080/info.php to see the PHP info.
Step 5: Set Up Auto-Start
So that nginx starts automatically when the phone boots:
# Install Termux:Boot from F-Droid
# Create the boot script file
mkdir -p ~/.termux/boot
cat > ~/.termux/boot/start-server.sh << 'EOF'
#!/data/data/com.termux/files/usr/bin/bash
termux-wake-lock
nginx
php-fpm
EOF
chmod +x ~/.termux/boot/start-server.sh
Step 6: Access from Outside
Port Forwarding
1. Open your router admin panel (usually 192.168.1.1)
2. Find the Port Forwarding menu
3. Add a rule:
- External Port: 8080
- Internal IP: Android IP
- Internal Port: 8080
- Protocol: TCP
4. Save
Dynamic DNS
Since home IPs are usually dynamic, use dynamic DNS:
# Install ddclient
pkg install ddclient
# Configuration
nano $PREFIX/etc/ddclient.conf
protocol=dyndns2
server=dyndns.org
login=your_username
password=your_password
your_domain.dyndns.org
Cloudflare Tunnel (Recommended)
# Install cloudflared
pkg install cloudflared
# Run the tunnel
cloudflared tunnel --url http://localhost:8080
Tips for Keeping the Server Stable
- Disable screen auto-lock, Settings → Display → Sleep → Never
- Disable battery optimization for Termux
- Keep it charging at all times, do not run it on battery
- Monitor the temperature, make sure it does not overheat
- Use a cooling fan if needed
- Static IP, set a fixed IP for the Android phone in your router
Use Cases
- Personal website, a simple blog or portfolio
- API server, a backend for a mobile app
- File server, share files on the local network
- Monitoring dashboard, display IoT sensor data
- Learning platform, learn web development
Android vs Raspberry Pi
| Aspect | Used Android | Raspberry Pi |
|---|---|---|
| Price | Free (second-hand) | ~Rp700K - Rp1.5M |
| RAM | 3-8GB | 1-8GB |
| Storage | 32-256GB | SD card |
| Connectivity | WiFi, Bluetooth | Ethernet, WiFi, GPIO |
| Power consumption | ~5W | ~5-10W |
| Ethernet port | None | Yes |
Conclusion
A used Android is no longer a useless item. With Termux and Nginx, you can turn it into a fully functional web server. Even though it is not as powerful as a VPS or a Raspberry Pi, a used Android is still an appealing choice for a learning project or a light server. Most importantly: cost-effective and environmentally friendly, because it makes use of something you already own.
Related Articles
Self-Hosted Analytics with Umami: A Privacy-Friendly Google Analytics Alternative
A complete guide to setting up self-hosted Umami analytics as a Google Analytics alternative that is privacy-friendly, fast, and keeps your data entirely yours.
HomelabSynology NAS: A Complete Guide to Setting Up a Private Cloud at Home
Learn what a Synology NAS is, set one up step by step, and turn it into a secure private cloud that keeps your data yours.
HomelabBuy an Office Server or a Cheap Barebone? A Complete Guide for Homelab and Small Business
A complete guide to buying a used office server or cheap barebone for your homelab. Includes price comparisons, specifications, and tips for choosing wisely.
Your ideas deserve to be read by thousands of people.
ByteNesia is built for everyone. If you have experience, tutorials, or opinions about technology, write and share them here. Your name will be credited as a contributor.
Write anything: tool reviews, homelab tutorials, security tips, or your tech stories.