Hello friends and welcome back to another new blog post. In the last blog post I shared with you, In this blog post, I will explain how you can install apache2 in termux. The World Wide Web is made with servers and with web servers the internet has become accessible to everyone, so in this post, I will show you how you can create your own Apache web server in Termux. You’ll learn how to install Apache2 in Termux, and I’ll also show you how to practice HTML with it.
In this article, we will learn how we can set up Apache web servers on any Android device. For this, we need to install the Termux app available on the Play Store. Termux is an Android terminal emulator and Linux application that works directly without rooting or setup. Termux provides the user with a Linux-like shell where they can perform tasks such as running commands and running scripts. Termux provides pkg and apt package managers to install packages, these package managers are just like apt and other Linux package managers.
What is Apache2
Apache HTTP Server is a free and open-source web server that delivers web content over the Internet. Commonly called Apache, it quickly became the most popular HTTP client on the web after its development. It is widely believed that Apache got its name from its development history and improvement process through applied patches and modules, but this was corrected in 2000. It was revealed that the name came from the Native American tribe’s respect for its durability and resilience. Before we get too deep into Install Apache2, we should first review what a web application is and the standard architecture typically found in web applications.
You can easily run Apache on Linux and since termux is a Linux terminal emulator, we can use it to run the Apache web server. Installation and use are very simple at a basic level. You can create your own website using HTML on Termux and you can run it on your Temux apache2. By default, this server will run on your local host on port 8080, but you can also use port forwarding to make it active.
Why Apache Servers?
Apache2 is considered open-source software, meaning that the original source code is freely available for viewing and collaboration. Because_Apache is open source, it is very popular with developers who have created and configured their own modules to use specific features and enhance its core functionality. Apache_has been around since 1995 and is responsible for being the foundational technology that helped accelerate the early growth of the Internet in its infancy.
Some of the most popular modules to add are SSL configuration, Server Side Programming Support (PHP), and Load Balancing to handle large amounts of traffic. Apache_can also be deployed on Linux, macOS, and Windows. If you learn how to configure_Apache on Linux, you can manage Apache2 on Windows and Mac. The only difference would be the directory paths and installation processes.
Step_1 – Download the Termux app
- First, open the F-Droid.org Website / App on your Android phone.
- Search for the Termux app.
- And install it on your Android phone by clicking the Download button
- And it will download to your phone.
Note: It’s safe because you downloaded it from Google Playstore and every app you get from Playstore is safe.
Step_2 – Install Apache2 Server In Termux :
To install apache2 on your Termux, follow the commands below –
After installation is complete, open the Termux app and Update the list of packages type “apt update && apt upgrade –y” and press enter
apache2 is a core package in termux, and to install apache2 in Termux, just use the core apt command. Apache2 server archive file in termux is about 5.5 MB, so installation will not take much time. Enter the command below to install.
Step_3 – Start & Stop Apache2 Server :
Everything on the apache2 termux server will be set up automatically and to test the server just enter the below command. This command will start the apache server, so whenever you want to start the Termux-Apache server again, you will use the below command.
Open your browser and go to localhost:8080, 127.0.0.1:8080 you will see the “It Works” message which means your Apache server is running without any error.
To stop the Apache2 server, just use a one-line command in termux. After entering this command, if you refresh your webpage in Chrome, you will see “This website is not available”, so if you see this at any time, it means that your server is down.
To stop a running apache server, type
Step_4 – Edit & Upload HTML file Apache2 Server :
Now the web server is up and running, you should know that the HTML file we get on localhost is actually present in your Termux and you can edit it on Learn Html in your termux. First, you need to learn how you can edit this website and print your own name instead of her works.
All apcahe2 webserver files are stored in your usr/share/apache2/default-site/htdocs folder in termux. and you’ll need to move into that folder first to edit the Index.html file located there. navigate to the htdocs path using the below command. Type ls and you will see the index.html file in the htdocs folder.
To remove the default page served by Apache, navigate to the following directory
In the htdocs directory, you can add your own HTML files or even edit the existing ones using a nano text editor or any other text editor.
You can also add anchor tags to your HTML files and link them to each other. For example, you can create your index.html homepage by editing it and then creating other web pages and then linking them to your index.html
Now if you already have some text editor in your Termux you can skip this part but if not you need to install a text editor, nano is a good text editor and it is lightweight too. use the below command to install nano in your termux.
Now enter the command below and you will see the source code of the default HTML apache2 website.
If you know basic HTML coding, you can edit this page or change it! text with your name
Step_5 – Change Apache Server Folder for Sdcard :
To remove the default Server Folder location by Apache, you will use the below command.
You need to change share/apache2/default-site/htdocs location to my mobile internal storage. I have been configured so many times on /sdcard/web here.
Create a directory of your mobile internal storage
Open Apache Configuration Files Folder
Edit Apache Configuration Files
Scroll Down and Find this DocumentRoot Line and Change Folder Location
After Change Type CTRl + X and type Y .save file
an open your file manager and Open Web Folder or Upload your HTML file to your web folder for that
Step_6 – Change Apache Server Default Port :
There is a time when we need to change the Apache server port. There are several reasons for this, such as when port 80 is already in use by other software or for security reasons, and there can be many other reasons that lead to changing the default port of the Apache web server. Here we will see how we can change the default port of the Apache web server on the Ubuntu server.
Edit Apache’s ports.conf file.
Open /etc/apache2/httpd.conf in any editor.
Edit Apache Configuration Files
Look for this line #52
Listen to 8080
Replace 8080 with the desired port number, for example, 4444.
After Change Type CTRl + X and type, Y save the file
So this is how you can run the apache2 web server on your android device using Termux. You can also bring your apache server online using ngrok so anyone on the internet can access it. If you are stuck somewhere feel free to watch my video about it.
Apache2 is an amazing software for creating a web server on your Termux. Apache2-termux is your own web server, so you can do whatever you want. You can practice the HTML code here. Try creating multiple web pages and then link them to the index where you can select your site, make sure you link back to the index so you can click the link to go back to the index page. If you are serious about learning, then this is the best tool to learn about servers and websites. If you need help with anything in this matter, you can always contact me