Apache on Android – Installation, Usage & Basic Commands

Apache is a powerful and widely used web server that helps you host websites and web applications on Android using Termux. It provides a lightweight local server environment where you can test HTML, CSS, JavaScript, and PHP projects directly from your mobile device. Apache is useful for learning web development, practicing server management, and creating a portable localhost setup. Here’s what you can do with Apache on Android:

  • Host local websites on Android.
  • Practice web development.
  • Test HTML, CSS, JavaScript, and PHP files.
  • Learn Apache web server basics.
  • Create a portable local hosting environment.
  • Run a lightweight development server directly on mobile.

Requirements

Before using Apache on Android, make sure your device meets the following requirements.

  • Termux installed (latest version).
  • Internet connection required.
  • Free storage: Minimum 500MB.
  • Android version: Android 7 or above.
  • Basic terminal knowledge recommended.

Installation Commands

Update and upgrade Termux packages:

pkg update && pkg upgrade

Install required packages:

pkg install lynx -y

Install Apache server:

pkg install apache2 -y

Check Apache version:

apachectl -v

Usage Commands

Fix Apache ServerName warning message:

echo "ServerName localhost" >> $PREFIX/etc/apache2/httpd.conf

Start Apache server:

apachectl start

Stop Apache server:

apachectl stop

Restart Apache server:

apachectl restart

Reload Apache configuration:

apachectl graceful

Check Apache server status:

apachectl status

Test Apache configuration:

apachectl configtest

Run Apache in foreground mode:

httpd -D FOREGROUND

Check listening ports:

ss -tulnp | grep httpd

Open localhost in browser:

http://127.0.0.1:8080

Open localhost using device IP (Root device):

ifconfig wlan0

Then open:

http://YOUR-IP:8080

Apache Basic Commands

Apache basic commands allow you to manage website files, check server information, edit configurations, and monitor Apache processes directly from the terminal.

Go to Apache website directory:

cd $PREFIX/share/apache2/default-site/htdocs

List website files:

ls

Create a simple HTML page:

echo "<h1>Apache Running on Android</h1>" > index.html

Open HTML file in Nano editor:

nano index.html

Create a CSS file:

nano style.css

Show Apache version:

apachectl -v

Show loaded Apache modules:

apachectl -M

Show virtual host configuration:

apachectl -S

View Apache configuration file:

nano $PREFIX/etc/apache2/httpd.conf

Search inside Apache configuration:

grep "Listen" $PREFIX/etc/apache2/httpd.conf

Check Apache process:

ps aux | grep httpd

Check disk usage:

df -h

Check memory usage:

free -h

Clear terminal screen:

clear

Remove test HTML file:

rm index.html

These commands are useful for beginners to understand how Apache works and how to manage a local web server on Android using Termux.

End Note

Now your Apache server is successfully running on Android using Termux, allowing you to host local websites and practice web development directly from your mobile device. Apache provides a simple and powerful way to test projects locally, manage web server functions, and explore Linux server administration on Android.

SHARE THIS POST: