Skip to content
Back to Series Homelab from Scratch
Homelab

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.

A
Alif Afriza Author
· · 5 min read
A Used Android as a Web Server: A Complete Tutorial from Scratch

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?

AdvantageExplanation
CheapYou already own the used phone, no need to buy anything new
Low power drawConsumes far less power than a PC
PortableYou can carry it anywhere
Always-onAndroid is designed to run 24/7
Battery backupThere 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

  1. A used Android phone, at least Android 7, 3GB+ RAM, 32GB+ storage
  2. USB cable, for continuous charging
  3. USB OTG + Ethernet adapter (optional), for a more stable wired connection
  4. Micro SD card (optional), for extra storage

Software

  1. Termux, a terminal emulator for Android
  2. Nginx, a lightweight web server
  3. PHP (optional), for dynamic content
  4. 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
# Install cloudflared
pkg install cloudflared

# Run the tunnel
cloudflared tunnel --url http://localhost:8080

Tips for Keeping the Server Stable

  1. Disable screen auto-lock, Settings → Display → Sleep → Never
  2. Disable battery optimization for Termux
  3. Keep it charging at all times, do not run it on battery
  4. Monitor the temperature, make sure it does not overheat
  5. Use a cooling fan if needed
  6. Static IP, set a fixed IP for the Android phone in your router

Use Cases

  1. Personal website, a simple blog or portfolio
  2. API server, a backend for a mobile app
  3. File server, share files on the local network
  4. Monitoring dashboard, display IoT sensor data
  5. Learning platform, learn web development

Android vs Raspberry Pi

AspectUsed AndroidRaspberry Pi
PriceFree (second-hand)~Rp700K - Rp1.5M
RAM3-8GB1-8GB
Storage32-256GBSD card
ConnectivityWiFi, BluetoothEthernet, WiFi, GPIO
Power consumption~5W~5-10W
Ethernet portNoneYes

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.

Open for Contributors

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.

Discussion & Comments