Android smartphone into a web server

Started by CreativeDreamrz, Aug 21, 2022, 07:08 AM

Previous topic - Next topic

CreativeDreamrzTopic starter

It happens that a smartphone becomes unnecessary - for instance, the screen breaks on it or it's just old, even the browser slows down. What to do with such a gadget, do not throw it away? In fact, the Americans flew to the moon with computers that have much worse performance than your old phone. Most likely, it has 4-8 processor cores, 2-4 gigabytes of RAM, an uninterruptible power supply unit with a battery. No weaker than some computers.
Let's try to find a useful application for this smartphone.

We are considering options

The first option that comes to mind is to install a Linux environment on the phone and some useful software that will work in the "background" for the benefit of the household. What could it be?

It is clear that the phone will not be able to work as a media server and process video streams; for this, its processor is too weak.

Theoretically, you can connect an external HDD to it (also left over from a broken laptop, a special adapter case with a USB interface was bought for it). Even on a capacious microSD card, it may well work as a file storage or backup server, there is enough space. True, microSD cards can hardly be recommended as reliable storage, they often fail.

Simple synchronization

If you set up a backup server or a file server on your phone, then the easiest option is to install the Syncthing program.

Syncthing performs continuous file synchronization between two or more computers in real time. In this version of synchronization, there is no central server, and all computers participate in peer-to-peer synchronization.
Synchronization is based on the date the file was modified, there is also support for synchronization at the block level, i.e. with small changes in the file, only the changed blocks will be synchronized, and not the entire file at once. Traffic is encrypted using TLS (transport layer security). Again, the program is open source, which speaks in favor of the reliability and security of such a solution.

In any case, PCs and laptops in the house need backup storage, so this is a good option.

Syncthing is available for all common operating systems: Linux, Windows, macOS, FreeBSD, OpenBSD, NetBSD, Dragonfly BSD, Illumos, Solaris. Well, Android, of course. That is, you can synchronize files between all these devices if you put a client on each of them. Then, in the program on the computer, we add the device ID - and they are synchronized.

Then it remains to select folders for synchronization on the computer and phone.
Then the program can constantly work in the background. Alternatively, you can set specific conditions under which it is performed.

Linux backup server

You can install a more serious program - UrBackup. This is an open source backup server. It can work on the same principle as Syncthing - constantly monitoring folders in the background that need to be backed up, but this is a more serious solution, which is preferable when managing backups on a network of a dozen computers. The system is cross-platform and supports distributions of Linux, Windows and Mac OS.

In order for UrBackup to work, you need to install a Linux environment. Here we have two options:

    Install a real distribution via Linux Deploy, an open source open source application for easy and fast installation of GNU/Linux on Android.
    Install Termux Linux environment.

The first option is more difficult. But theoretically, it allows more efficient use of system resources.

A rooted phone is a must (you can use a tool like Magisk for rooting).

So, the algorithm is something like this, judging by the instructions from Hannah Lee, who implemented this plan.

    We connect HDD / SSD to the phone. You can connect it directly with a USB cable: in this case we will get the highest possible speed. But on a real file server or backup server, speed is not always the most critical factor, except for very large read / write volumes. More important is stability. With a USB cable, there is a much higher risk of I/O errors during the copy process.

    Therefore, to increase reliability, it is better to use a USB hub, which has a microUSB for output to the phone and a standard USB for connecting an HDD, plus an additional power connector.

    Ideally, you need to buy a hub with an Ethernet adapter. The server can also work over WiFi, but a cable connection is more reliable.

Mount the HDD to the phone, that is, make it available to the operating system on the phone. If you do not plan to format the disk in the future, then you can immediately add it to mounts - and it will be mounted on every boot. After mounting it, it will no longer be feasible to format it, and this is usually not necessary. It's better to mount it as a logical drive rather than a physical device, because in the latter case its name (/dev/block/sdX) may change after a reboot, which is undesirable. If you mount it as a logical drive (/dev/sdX), the name will not change.

You can find the connected HDD, that is, find out its name in the system, using the lsblk command.
On a rooted phone, download the Linux Deploy and BusyBox .apk files. After that, install BusyBox, configure Linux Deploy: select the Linux distribution, architecture, installation path (HDD), image size, file system, set login and password, permission to use the SSH server, etc. Specify the location of BusyBox, then install Linux Deploy.
After installation, we press the START button - and normal Linux is loaded on the Android phone. For instance Debian.
Since we allowed the use of an SSH server during installation, you can connect to it on the standard port 22 with the credentials that you specified when installing Linux Deploy. The IP address can be viewed in the program.
Download and install UrBackup:


apt install -f ./urbackup-server_2.4.13_arm64.deb

We create a working directory, install the start script, start the service and create crons for it. After that, the server will be available through the web interface at http://YOUR_SERVER_IP:55414.

We connect users (this can be done through the web interface) Windows, Linux, etc. Users need to install the appropriate software on their machines, there will be instructions on how to connect to the server and add a specific machine to the server.


Perhaps all this can be done without rooting, using the Termux Linux environment. Let's check if this is so.

Termux is a free console emulator and Linux environment for Android that installs like a regular application and does not require root access, includes many Linux operating system packages. In the basic format, a minimum is installed there, additional packages can be organized using the "pkg" package manager (similar to apt). This is the most convenient way to run almost any Linux program on Android. It's better to install it from F-Droid and not from Google Play.

Initially, Termux is installed as a bare emulator. A small base system boots up on first run, and all required packages can be installed using the apt package manager, which is standard on Debian and Ubuntu. But it will also need to be installed using the built-in pkg package manager.

In our case, you can immediately install apt:

pkg install apt

Then install wget with it, or use the native pkg command:

pkg install wget

Then you can install the same UrBackup, another file server or backup server of your choice.

For instance, we can install the nginx web server:

pkg install nginx

After that, we start the web server:


If you open a browser on your smartphone and type localhost:8080, then we will see a working web server.

Now you can copy the HTML files to the nginx working directory - and the phone will have a full-fledged site that can be shared via the Internet. Then we will have our own server and our own hosting server, we do not pay any provider other than a cellular operator, and we can publish anything on the Internet. In principle, the site will be available to everyone as long as the phone is connected to the cellular network, a Termux session is open on it, and nginx is running in it. The main thing is that the mobile operator does not block this traffic, because we can formally violate its terms of service.

Of course, for reliable hosting server, it is better to root your phone and install a normal distribution via Linux Deploy. But everything works in Termux, as we see.

Conclusion: Thus, even from an old Android smartphone, you can make an adequate, full-featured multi-core Linux server on the ARM architecture. If you connect an external HDD / SDD, it will work as a file storage, backup server for your home network or a webserver for your personal needs.


everybody has an old smartphone or tablet that is in good working order: it's a pity to throw it away (it works), it's not possible to use it for its intended purpose (outdated, the screen is broken, the battery doesn't hold), so it lies to itself. And here is a great way to reuse. Thank you buried.

The only thing from this place

QuoteNow you can copy the HTML files to the nginx working directory - and the phone will have a full-fledged website that can be shared via the Internet

.. it would be necessary in more detail - how to do all this in the absence of an adequate interface in the termux, using text commands.

I have an old smartphone (SGN4 with a broken microphone after 5 years of operation) used as a second camera for a vlog. It shoots more than satisfactorily by modern standards.

And instantly the question is: is there such an application that does nothing but spin mobile ads on the screen? The one for viewing which in games they give a crystal. Or just banners. If so, then under this you can stir up an interesting idea a la "mining screen", where the adv. network pays for impressions.


My old smartphone works as a "smart camera" for video surveillance, it's not enough for more (1 core, 512 MB of memory in total) - the video stream gives out via wifi, it really heats up a little.

The main problem with old devices is their almost complete non-repairability, everything has to be done with crutches.
Example: in almost all old devices, the battery dies (in my case, it swelled up a lot, i.e. it doesn't fit into the case anymore), it can be started from usb power, even it can't be a 10A unit, and of course there's nowhere to get a new battery either - release date batteries does not exceed 1-2 years after the release of the phone. We have to fence crutches out of the blue so that this miracle can turn on and work, and not only change the battery connection scheme, but also patch the software.
The second problem, for instance, is the degradation of the built-in emmc. This is again crutches to get around it. Moreover, in android, the emmc entry is made synchronous or something, because during degradation, the system response time grows reaching ANR right from the start, because of which the system tries to write a log, which (bingo!) Again leads to brakes, and so on in a circle . It saves loading from an external card, at least you can change it.

In both examples, it would be easy for manufacturers to greatly simplify the solutions to these problems, but nobody wants to.


In such projects, I am strained by the labor costs of deployment (getting rid of the battery, poking around with loaders and firmware, if you still find a model for your model, and they will have a severely curtailed outdated list of packages, for something non-standard - to compile again and not the fact that it will work), reliability and complexity of diagnostics in case of problems.

As a result, I bought an old nettop on atom for a penny. A normal bios, a normal bootloader, sate 2.5, a full-fledged, albeit slow Linux with all updates.
And the previous smartphone is easier to sell, let someone else use it for its intended purpose.