How to create localhost using Termux


Hello, and welcome again.
Today we are going to know about how to populate our own HTML file in the localhost.

Before starting I would like to declare, this blog and video below the blog are just for educational purposes if you use it against someone which is unethical. You will be responsible for that. My team and I will never support hacking tracking or stealing things over the internet.
Let me first share the commands we will be using for today's tutorial.

Commands for creating localhost using Termux are listed below:- To understand more read way below the command lines.

apt update
apt upgrade
pkg install php
termux-setup-storage
apt install termux-api php
mkdir /sdcard/php Download index.html file here  and paste it in the HTML folder 
Copy paster the files into the HTML folder ( file.html file.php) 
nano index.html  
php endlessloop.php
cd /sdcard/php
php -S localhost:8080 -t /sdcard/php/

Now let us talk about what does localhost means, and what kind of things can be done using that.
Localhost means the computer that all the programs running on continuously. For example, if you are running your Termux on your computer, your computer is Localhost for Termux. This is not required that only a single computer can run that program. It can be operated from many computers within the network. So Every network has multiple access to any localhost.

The local machine is defined as "localhost," which gives it an IP address of 127.0.0.1. This is considered a "loopback" address because the information sent to it is routed back to the local machine. Localhost is often used in Web scripting languages like PHP and ASP when defining what server the code should run from or where a database is located.

So today again we are going to use Termux, to create localhost that can run a small HTML file. In my upcoming tutorial, I will be showing how to execute that HTML file over the internet. This means how to publish our local host for the public. Yes, I know this will be quite interesting.
What are the things you can do using the localhost?
Localhost provides you the way to share things within the network. You can share any information or image even a website. Localhost enables a device to create things within the network which can be used by multiple hosts. Localhost denotes the pc (sharing data) host stands for the list of users trying to access the particular page or how they have access to reach the page by typing http://localhost:port.

Now we will understand the command lines we have used to get the localhost used.

apt update : This command is used to update all the Packages.
apt upgrade : This command is used to upgrade all the Packages
pkg install php : Install PHP in the Termux.
termux-setup-storage : to allow storage access to Termux.
apt install termux-api php : Enables Termux to use Termux API with PHP
mkdir /sdcard/HTML  : To make a folder we usees mkdir command
nano HTML.html  : we use nano to execute the HTML file to.
php endlessloop.php : to execute the .php file in endless loop. It will help the PHP to execute again and again.
cd /sdcard/HTML : To get into the folder or directory we use the cd command.
php -S localhost:8080 -t /sdcard/php/ : -S is used to allocate the IP or address or a network path to PHP, Port 8080 provides web services to document or an executable file. -t provides a path to the directory.

So what we did overall. First, we updated and upgraded the Termux app packages, After that, we installed PHP because it is required to create localhost using Termux. After that we allowed the device to provide the storage permission to access the files. We installed the Termux API, again a supported required file. We created the folder HTML in the internal storage main root. Then we executed the HTML.html file and setup the endless loop to run the PHP again and again. We went to the HTML folder using the cd command. In the final step, we executed the command to populate the localhost via 8080 port.

This was it for the day. In my next blog, we will how to publish the localhost to the internet to access it from anywhere in the world.

Disqus Comments