Turning an Android Phone into a Web Server with Termux, Ruby, Sinatra, and Puma
This guide shows how to repurpose an old Android phone into a functional web server by installing Termux, configuring SSH with Dropbear, setting a static IP, installing Ruby, Sinatra, Puma and nginx, enabling port forwarding, dynamic DNS, and performing basic load testing and security considerations.
Every year many old Android phones become electronic waste; this tutorial demonstrates how to reuse one as a web server.
Install Termux – download the Termux terminal emulator from the Google Play Store; no additional configuration is required.
Set up SSH using Dropbear so you can access the device remotely. Run the following commands in Termux:
pkg upgrade
pkg install dropbearSet a password for SSH access:
passwd
New password:
Retype new password:
New password was successfully set.Optionally install a terminal multiplexer for easier session management:
pkg install tmuxTest the connection from a desktop or laptop:
ssh android-ip-address -p 8022Configure a static IP address on the phone’s Wi‑Fi settings by disabling DHCP and assigning a fixed address, preventing the router from changing it frequently.
Install Ruby, Bundler, Sinatra, and Puma – these provide a lightweight web application framework and server:
pkg install ruby
gem install sinatra pumaInstall nginx to act as a reverse proxy and static file server:
pkg install nginxCopy a suitable nginx.conf (e.g., from https://gist.github.com/ctalkington/4448153) and set appdir to the directory of your Sinatra application, such as /data/data/com.termux/files/home/android-sinatra .
Set up port forwarding on your router so external requests reach the Android web server; the exact steps depend on the router model.
Configure Dynamic DNS (DDNS) to handle a changing public IP address. Services like No‑IP provide a static domain name that updates automatically.
Run a Hello World app to verify the server is working.
Load testing can be performed with siege to simulate concurrent users; the example shows the server handling three concurrent connections.
Security considerations – keep all software up to date, monitor access logs, and follow nginx hardening guides to protect the server from malicious traffic.
IT Services Circle
Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.