Home » Android » Setting Up Apache2 in Termux: A Step-by-Step Guide with Configuration Settings

Apache2 Termux

Setting Up Apache2 in Termux: A Step-by-Step Guide with Configuration Settings

Poated on by

Categories Android Mobile Technology Termux Web Development

Apache2 Server: Introduction

Apache2 is a powerful and widely used web server that allows you to host websites and serve web content.

In this blog post, we will see how to install and configure Apache2 in Termux. We’ll also cover some essential configuration settings and fix SsrverName warning. This will help you customize and optimize your Apache2 setup.

Apache2 Server On Android: Prerequisites

Before we begin, make sure you have the following prerequisites:

  • An Android device with Termux installed.
  • A stable internet connection.

Step 1: Installation

Open the Termux app on your Android device.

Termux Download

Update the package lists by running the command:

pkg upd

Install the Apache2 package by running:

pkg i apache2 -y

After runing these commands the latest version of Apache2 Server will be installed in Termux.

Step 2: Starting the Apache Server

Once the installation is complete, start the Apache server with the command:

apachect start

Here you may see ServerName Warning (How to fix? Continue reading…). Just ignore it and verify if Apache2 Server is started.

To verify if Apache2 Server is running, open a web browser on your device and enter the URL:


Or copy the command and run in termux.

termux-open http://localhost:8080

You would see the default Apache page if everything is working correctly

Step 3: Configuring Apache2

The Apache config file contains directives that define how the server operates, including settings for various modules, virtual hosts, security measures, and other server-related configurations.



We can open httpd.conf file with nano text editor and make changes.

nano $PREFIX/etc/apache2/httpd.conf

If you are new to nano, we already posted a detailed post on nano check it out.

In httpd.conf everything started with # sign is a comment and that configuration will not apply.

Fix ServerName Warning

If you are seeing ServerName Warning, it’s because ServerName is not set or is in comment section. We need to add or uncomment this setting.

Open httpd.conf in nano and find ServerName then uncomment and write following line

ServerName localhost

Other Configuration Options

Inside the httpd.conf file, you’ll find various configuration options. Here are a few essential settings you can customize:


This specifies the directory where your website’s files are located. By default, it is set to /data/data/com.termux/files/usr/share/apache2/default-site/htdocs. You can change it to the desired directory on your device.

For easy access you can change DocumentRoot within /sdcard so that you can easily access your project files. You can use any other code editor to write code.

Step A: First create project Directory in /sdcard named htdocs.

mkdir /sdcard/htdocs

Step B: Change document root in httod.conf and save.

DocumentRoot "/sdcard/htdocs"

<Directory "/sdcard/htdocs">

Step C: Create new webpage index.html file in your new DocumentRoot /sdcard/htdocs and write any message.

Step D: Restart Apache2 Server.

apachectl restart

Step E: Run the command to open URL http://localhost:8080 in web browser.

termux-open http://localhost:8080


By default, Apache listens on port 8080. If you want to use a different port, you can change it here. For example if you want run Apache on 8090 port change like this

Listen 8090

Now the Apche2 Server will run on 8090 post. The url will be looks like this:



These directives specify the log file paths for error messages and access logs, respectively. If you want you can change it.

Default ErrorLog path in Termux is:



The Apache error log has a logging level that filters the messages sent to the log. You can specify the level with the LogLevel setting.

LogLevel warn

Possible other values are:

emergSystem is unusable
alertImmediate action is required
critCritical conditions have occurred
errorError conditions have occurred
warnWarning conditions have occurred
noticeNormal but significant conditions
infoInformational messages
debugDetailed debug information

After making the desired changes, save the file by pressing CTRL + X, then Y to confirm the changes, and finally Enter to save.

Step 4: Restarting Apache

To apply the configuration changes, restart the Apache server with the command:

apachectl restart

Useful apachectl Commands

apachectl startStarts the Apache HTTP Server.
apachectl stopStops the Apache HTTP Server.
apachectl restartRestarts the Apache HTTP Server.
apachectl gracefulGracefully restarts the Apache HTTP Server, allowing active connections to complete before restarting.
apachectl configtestTests the Apache configuration for syntax errors.
apachectl statusChecks the status of the Apache HTTP Server.
apachectl versionDisplays the Apache HTTP Server version.


With Apache2’s extensive configuration options, you can further customize and optimize your setup according to your specific requirements. By exploring the httpd.conf file, you can fine-tune various settings, including the document root, server name, and directory options.

Apache2 HTTP Server Documentation

Check github repository

Tags: ,

1 Comment on 'Setting Up Apache2 in Termux: A Step-by-Step Guide with Configuration Settings'

  • injqxwomw says:

    Setting Up Apache2 in Termux: A Step-by-Step Guide with Configuration Settings – Easymux

  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    Subscribe Us