Apache in Termux - Complete Installation and Usage Guide
What is apache
Apache HTTP Server is a free and open-source cross-platform web server software. It is one of the oldest and most reliable web servers in the world, powering a significant portion of the internet. In Termux, Apache allows you to host local websites, test web applications, and create a mobile development environment directly on your Android device.
Prerequisites
Before installing Apache, ensure your Termux environment is ready:
- Storage Permission: Useful if you want to host files from your internal storage.
- Port Awareness: By default, Termux services cannot use ports below 1024 without root. Apache in Termux typically uses port 8080.
- Stable Internet: Required for downloading the initial package.
Installation Commands in Termux
Follow these steps to set up the Apache (httpd) package.
1. Update Repositories
Ensure your package list is current.
pkg update && pkg upgrade -y
2. Install Apache (httpd)
Install the apache2 package (sometimes referred to as httpd in other distros).
pkg install apache2 -y
3. Start the Server
Launch the Apache daemon.
apachectl start
Basic Usage & Examples
Once started, your server is live. Here is how to manage it and locate your files.
Accessing the Default Page
Open your browser and navigate to the local host address.
http://localhost:8080
Locating Web Files
In Termux, the default document root where you should place your HTML files is:
/data/data/com.termux/files/usr/share/apache2/default-site/htdocs/
Stopping the Server
Kill the Apache process when you are finished testing.
apachectl stop
Restarting for Configuration Changes
Apply changes made to the httpd.conf file.
apachectl restart