Setting Up a Local Web Server on Termux with Apache (2025 Guide)
Setting Up a Local Web Server on Termux with Apache (2025 Guide)

Welcome to this comprehensive 2025 guide on setting up an Apache web server on your Android device using Termux! Whether you're a developer needing a portable testing environment, a student learning web technologies, or just curious about server administration, this tutorial will transform your phone into a fully functional local web server.
Why Run Apache Web Server on Termux?
Termux brings powerful Linux capabilities to Android, allowing you to run real server software like Apache. Key benefits include:
- Develop/test websites anywhere without internet
- Learn server administration on a low-risk environment
- Host personal projects locally on your phone
- Significantly lighter than desktop virtualization
- Perfect for PHP/HTML/CSS development workflows
Prerequisites
Before we start, ensure you have:
- Android 8.0 or higher
- Termux installed from F-Droid (official version)
- At least 500MB free storage
- Stable internet connection for installation
Section 1: Installing Apache on Termux

Follow these steps carefully to install Apache:
- Launch Termux and update packages:
pkg update && pkg upgrade -y
- Install Apache web server:
pkg install apache2 -y
- Start Apache service:
apachectl start
Verify installation by visiting http://localhost:8080 in your Android browser. You should see the Apache test page.
Section 2: Configuring Apache Server in Termux

Default Apache configuration needs adjustments for Termux environment:
- Open Apache configuration file:
nano $PREFIX/etc/apache2/httpd.conf
- Make these critical changes:
# Change document root
DocumentRoot "/data/data/com.termux/files/usr/share/apache2/htdocs"
# Change directory path
<Directory "/data/data/com.termux/files/usr/share/apache2/htdocs">
# Change port from 8080 to 80 if needed (requires root)
Listen 8080
- Save changes (Ctrl+O in nano) and restart Apache:
apachectl restart
Section 3: Hosting Websites on Your Termux Apache Server
Your website files belong in Apache's htdocs directory:
- Navigate to web root directory:
cd $PREFIX/share/apache2/htdocs
- Create a test HTML file:
echo "<h1>My Termux Server Works!</h1>" > test.html
- Access your file at http://localhost:8080/test.html
Adding PHP Support
Enable dynamic content with PHP:
- Install PHP:
pkg install php-apache -y
- Edit Apache configuration:
# Add these lines to httpd.conf
LoadModule php_module libexec/apache2/libphp.so
AddHandler php-script .php
Section 4: Essential Apache Commands for Termux
Command | Function | Usage Frequency |
---|---|---|
apachectl start |
Starts Apache server | Daily |
apachectl stop |
Stops Apache server | Daily |
apachectl restart |
Restarts Apache server | After config changes |
apachectl configtest |
Checks configuration syntax | Before restarting |
htpasswd |
Creates password files | For security setup |
Section 5: Securing Your Apache Server in Termux

Even for local development, security matters:
- Disable directory listing: Add "Options -Indexes" in httpd.conf
- Change default port: Use Listen 8080 instead of 80
- Restrict access: Configure <Directory> permissions carefully
- Use .htaccess protection: For sensitive directories
- Keep Termux updated: Regularly run "pkg upgrade"
Section 6: Troubleshooting Common Apache Issues in Termux
Encountered problems? Try these solutions:
Port 8080 Already in Use
# Find conflicting process
pkg install procps
ps aux | grep apache
# Kill conflicting process
kill -9 PROCESS_ID
# Alternatively change Apache port
PHP Files Downloading Instead of Executing
- Verify PHP module is loaded in httpd.conf
- Check AddHandler directive exists
- Ensure files have .php extension
- Restart Apache after changes
Permission Denied Errors
# Change ownership of web directory
chown -R $USER:$USER htdocs/
# Set appropriate permissions
chmod -R 755 htdocs/
Frequently Asked Questions (FAQ)
1. Can I access my Termux Apache server from other devices?
Yes! Install pkg install openssh
and set up port forwarding. Access via your phone's IP address on the same network.
2. How do I make my Apache server start automatically?
Use Termux:boot add-on. Create ~/.termux/boot directory and add a script with "apachectl start" command.
3. Can I host WordPress on Termux Apache?
Absolutely! Install MySQL/MariaDB and PHP, then follow standard WordPress installation. Great for mobile development testing.
4. Why can't I use port 80?
Android restricts ports below 1024. Either run as root (not recommended) or use higher ports like 8080 or 8888.
5. How much traffic can Termux Apache handle?
While suitable for development and small personal projects, it's not designed for production traffic. Performance depends on your device specs.
Need Further Assistance?
Stuck with your Termux Apache setup? I offer personalized consultation for Termux server configurations! Subscribe to my newsletter for upcoming tutorials on MySQL integration, WordPress optimization on Termux, and advanced Apache security configurations!