top of page
Search
  • Writer's pictureG.I.T.S.

Install Apache server

Open the Termux app and Update the list of packages type apt update && apt upgrade –y and press enter.


apt update && apt upgrade -y

----------


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, the installation will not take much time. Enter the command below to install.


apt install apache2

----------


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.


apachectl

----------


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”, if you see this at any time, it means that your server is down.


To stop a running Apache server, type:


apachectl -k stop

----------


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 apache2 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;

cd /$PREFIX/share/apache2/default-site/htdocs 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.


pkg install nano

----------


Now enter the command below and you will see the source code of the default HTML apache2 website.


nano index.html

----------


If you know basic HTML coding, you can edit this page or change iChange 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 . I have been configured so many times on /sdcard/web here.


Create a directory of your mobile internal storage.


mkdir /sdcard/web

----------


Open Apache Configuration Files Folder


cd /data/data/com.termux/files/usr/etc/apache2

----------


Edit Apache Configuration Files


nano httpd.conf

----------


Scroll Down and Find this DocumentRoot Line and Change Folder Location .


#

# DocumentRoot: The directory out of which you will serve your

# documents. By default, all requests are taken from this directory.

# symbolic links and aliases may be used to point to other location.

# DocumentRoot "/sdcard/web/" <Directory "/sdcard/web/">

#

# Possible values for the Options directive are "None", "All",

# or any combination of:

#


After Change type: CTRl + X and type Y .save file and open your file manager and Open Web Folder or Upload your HTML file to your web folder for that.

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.


cd /data/data/com.termux/files/usr/etc/apache2

----------


Edit Apache Configuration Files


nano httpd.conf

----------


Look for this line #52

Listen to port 8080

Replace port 8080 with the desired port number, for example, 4444.


#

# ports, instead of the default. See also the

# directive.

#

# Change this to Listen on specific IP addresses as shown below t>

# prevent Apache from glomming onto all bound IP addresses.

# Listen 8080

#

# Dynamic Shared Object (DSO) Support

#

# To be able to use the functionality of a module which was built>

# have to place corresponding `LoadModule' lines at this location>


After Change type: CTRl + X and type: Y to save the file.


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.

Recent Posts

See All

Comments


Post: Blog2_Post
bottom of page