Skip to main content
Ultimate Guide: Hosting a Live Website in Termux with Nginx & Apache! 🚀

Ultimate Guide: Hosting a Live Website in Termux with Nginx & Apache! 🚀

Do you want to turn your Android phone into a fully functional web server ? With Termux , you can run Nginx or Apache to host a live website locally—or even make it public! This in-depth guide will wa

rocky4 min read

Do you want to turn your Android phone into a fully functional web server? With Termux, you can run Nginx or Apache to host a live website locally—or even make it public! This in-depth guide will walk you through setting up both web servers, configuring custom websites, and exposing them to the internet.

Why Use Termux for Web Hosting?

✅ Portable web server – Host websites directly from your phone.
✅ Great for testing & development – Perfect for web developers on the go.
✅ Low-resource & efficient – Nginx and Apache run smoothly on Android.
✅ Public or local hosting – Share with others via LAN or the internet.

Prerequisites

Before we begin, ensure you have:
✔ Termux installed (Download from F-Droid)
✔ A stable internet connection
✔ Basic knowledge of Linux commands

Option 1: Hosting a Website with Nginx

Nginx is a lightweight, high-performance web server perfect for Termux.

Step 1: Install Nginx

Update packages and install Nginx:

pkg update && pkg upgrade -y
pkg install nginx -y

Step 2: Start Nginx

Run the server:

nginx

Verify it’s working:

curl http://localhost:8080

You should see the default Nginx welcome page.

⚠️ Note: Nginx runs on port 8080 in Termux (Android restricts ports below 1024).

Step 3: Access Your Website Locally

Open a browser and visit:

http://localhost:8080

Step 4: Replace Default Page with a Custom Website

  1. Navigate to Nginx’s web directory:
   cd $PREFIX/share/nginx/html/
  1. Remove the default files:
   rm -rf *
  1. Create a new index.html:
   nano index.html

Paste this sample HTML:

   <!DOCTYPE html>
   <html>
   <head>
       <title>My Termux Website!</title>
   </head>
   <body>
       <h1>🚀 Website Hosted on Termux!</h1>
       <p>Powered by <b>Nginx</b></p>
   </body>
   </html>

Save with Ctrl+O → Enter → Ctrl+X.

  1. Restart Nginx:
   nginx -s reload

Refresh http://localhost:8080 to see your site!


Option 2: Hosting a Website with Apache

Apache is another powerful web server with .htaccess support and modularity.

Step 1: Install Apache

Run:

pkg install apache2 -y

Step 2: Start Apache

apachectl start

Verify it’s running:

curl http://localhost:8080

You should see the Apache default page.

⚠️ Note: Apache also runs on port 8080 in Termux.

Step 3: Access Your Website Locally

Visit in a browser:

http://localhost:8080

Step 4: Customize Your Website

  1. Navigate to Apache’s web directory:
   cd $PREFIX/share/apache2/default-site/htdocs/
  1. Remove default files:
   rm -rf *
  1. Create a new index.html:
   nano index.html

Paste this sample HTML:

   <!DOCTYPE html>
   <html>
   <head>
       <title>Apache on Termux!</title>
   </head>
   <body>
       <h1>🔥 Website Hosted on Termux!</h1>
       <p>Powered by <b>Apache</b></p>
   </body>
   </html>

Save (Ctrl+O → Enter → Ctrl+X).

  1. Restart Apache:
   apachectl restart

Refresh http://localhost:8080 to see your new site!

Making Your Website Public

Want others to access your site? Here’s how:

Option 1: Local Network (LAN) Access

  1. Find your phone’s local IP:
   ifconfig

Look for wlan0 (Wi-Fi) and note the inet address (e.g., 192.168.x.x).

  1. Others on the same network can visit:
   http://[YOUR_LOCAL_IP]:8080

Option 2: Public Access with Ngrok (Best for Testing)

  1. Install Ngrok:
   pkg install wget -y
   wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip
   unzip ngrok-stable-linux-arm.zip
  1. Run Ngrok (requires Ngrok account):
   ./ngrok http 8080

You’ll get a public URL like https://xyz.ngrok.io.

Now, your website is accessible worldwide! 🌍

Stopping the Servers

When done, stop the servers:

For Nginx:

nginx -s stop

For Apache:

apachectl stop

Nginx vs. Apache in Termux: Which is Better?

FeatureNginxApache
PerformanceFaster, lower memory usageSlightly heavier, more features
ConfigSimpler configurationSupports .htaccess
Use CaseHigh-traffic, static sitesDynamic sites, PHP apps

Recommendation:

  • Use Nginx for speed and simplicity.
  • Use Apache if you need .htaccess or PHP support.

Bonus: Running PHP with Apache

Want to host PHP websites? Install PHP:

pkg install php -y

Then, restart Apache:

apachectl restart

Now, you can run PHP scripts in htdocs/!

Final Thoughts

You’ve now learned how to:
✔ Host a website in Termux using Nginx & Apache
✔ Customize your site with HTML
✔ Access it locally or publicly via Ngrok

🚀 Try it out and turn your Android into a web server today!

🔗 Follow Codelivly for more Termux & Cybersecurity guides!

Frequently Asked Questions

Can you host a website from an Android phone?
Yes. With Termux you can install Nginx or Apache, serve static or simple dynamic sites and expose them locally or publicly. Performance and uptime are limited compared with a real server.
How do I install Nginx in Termux?
Update packages with pkg update, then run pkg install nginx and start it with the nginx command. By default it serves files from a directory in Termux's prefix, which you can edit.
Is it safe to expose a Termux web server to the internet?
It carries risk because phones lack hardened server defaults. Keep software updated, limit open ports, avoid sensitive data and consider a tunnel or reverse proxy for exposure.

Related Articles

COMMENTS (0)

Sign in to post intel on this briefing.

NEW350+ rooms now have a live terminal, so you can learn by typing the commands, right in your browser.Learn in a live terminal. 350+ rooms.Try a labCodelivly is 100% free, no paywall. If it helped you, chip in to keep it running.100% free. Help keep it so.Support us