Turn an old Android phone into a web server
Introduction
The purpose of this article is to show you how to give an old, unused Android phone a second life by converting it into a low-power, lightweight web server.
For this, we need Termux — a free and open-source terminal emulator and Linux environment application designed specifically for Android devices. Think of it as a way to open a fully functioning command-line interface (like the Terminal on Mac or Linux) right on your phone or tablet.
Installing Termux
To install Termux correctly, you need to download it directly from GitHub.
Install it on your Android device. From settings, give all permissions, and allow the app to run in the background with no battery restrictions.
Congrats, now you have a fully functioning Linux terminal within Android OS.
I recommend executing the following commands to make the app run smoothly:
termux-wake-lock
pkg update && pkg upgrade -y
Connecting to the phone with SSH
If you want to connect to Android via SSH and type the commands from your laptop terminal, you can do it. It takes a few minutes to set up.
On the phone (Termux)
Install openssh and set a password for SSH connections:
pkg install openssh -y
passwd
Find your username:
whoami
Check your phone's IP address within the Wi-Fi network where the Android phone and laptop are connected:
pkg install iproute2 -y
ip route
Your IP will look like 192.168.22.54
Finally, start the SSH server:
sshd
On your laptop
Now you can establish an SSH connection to the phone:
ssh YOUR_USERNAME@YOUR_PHONE_IP -p 8022
So, yeah, now you have established an SSH connection to the phone.
Simple hello world Node.js app
Now let's create a simple project in Node.js that prints just Hello World when port 1212 is called.
Install Node.js, create a project folder, and navigate to it:
pkg install nodejs -y
mkdir hello-server && cd hello-server
Create a simple script for the app with nano server.js and save it with this content:
const http = require('http');
const PORT = 1212;
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
});
server.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
Run the server:
node server.js
And as you can see, you successfully ran your backend project on an Android phone server.
Configuring a domain for the server
Well, the backend is running on the local Wi-Fi, but this might not be useful if you want to expose something globally. Here, tunnelling apps come to help. They help to expose local computers to the internet. A common example is ngrok, which is a paid service. But for this session, I prefer Cloudflare, which is a free service. It also offers exposing the local computer to a specific domain — you can research more about custom domains, they are out of scope for this session.
Install the Cloudflare CLI and create a tunnel to expose localhost to the public:
pkg install cloudflared -y
cloudflared tunnel --url http://localhost:1212
That will give you a URL like https://bonus-medicines-disco-seq.trycloudflare.com
We have successfully exposed the Android server to the public. You can use this for testing or for any purpose.
Conclusion
So, yeah, that's it. With just Termux, Node.js, and Cloudflare, your old Android phone is now a working web server exposed to the internet. It's low-power, silent, and costs nothing. You can go further from here: host a real API, run a Telegram bot, or set up a custom domain. Not bad for a phone that was sitting in a drawer.