Tutorials  /  Linux Basics

How to Host a Web Server on Android with Termux and Ngrok

Ccentron Redaktion · December 2024 ·4 min read ·Linux Basics, Tutorial

Steps to Host a Web Server on Android

Let’s get right into the steps to host a web server on our Android devices now.

1. Install Termux and Hacker’s Keyboard

First, we will need two Applications before we continue on: Termux (which will help us issue commands) and Hacker’s Keyboard (which will help us to use keys like Ctrl, Esc, Alt which are usually not available on standard Android Keyboards).

You can get Termux from their official website or from Google Playstore.

You can install Hacker’s Keyboard as well for better navigation within the Termux window.

2. Install Packages on Termux

Now we need to install some of the packages we require on Termux. Open the app and type in the following commands:

Console
$ pkg update && pkg upgrade

This should upgrade our current system. Next up we will need to install some necessary packages with:

Console
$ pkg install apache2 git neovim wget curl

3. Connect to Android Device via SSH (Optional)

Note that this section is completely optional. Here we will install some additional packages just to aid us during the whole process:

Console
$ pkg install openssh neofetch fish nmap

First let’s enable SSH so that we can connect to our phone via our PC by:

Console
$ sshd

Next, check your username and IP with:

Console
$ whoami
$ ifconfig wlan0

Now we need to check which port the SSH service is running. You can check it with:

Console
$ nmap -sV 127.0.0.1

Once you have the Port Number, switch over to your PC and connect to your device with:

Console
$ ssh -p  @

4. Start the Webserver on Android

Now, we can start our server with:

Console
$ apachectl

By default, the webpage is hosted on port 8080.

To edit the message, we need to change the index.html file with:

Console
$ vi $PREFIX/share/apache2/default-site/htdocs/index.html

5. Port Forwarding with Ngrok

First, we need to get the compressed file from the official website with:

Console
$ wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm64.tgz

Unzip the file with:

Console
$ tar -xvzf ngrok-stable-linux-arm64.tgz

Finally, with our webserver still running, type:

Console
$ ./ngrok http 8080
VM

Matching infrastructure at centron

No hardware needed to follow along: ccloud³ VMs with full root access start at €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Conclusion

Thus, in this way, we can use our Android phones as web servers. On non-rooted phones, you can host a webserver on any of the higher ports while on rooted phones you can use the default port 80.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Linux Basics
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren