
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
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
- Navigate to Nginx’s web directory:
cd $PREFIX/share/nginx/html/
- Remove the default files:
rm -rf *
- 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.
- 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
- Navigate to Apache’s web directory:
cd $PREFIX/share/apache2/default-site/htdocs/
- Remove default files:
rm -rf *
- 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).
- 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
- Find your phone’s local IP:
ifconfig
Look for wlan0 (Wi-Fi) and note the inet address (e.g., 192.168.x.x).
- Others on the same network can visit:
http://[YOUR_LOCAL_IP]:8080
Option 2: Public Access with Ngrok (Best for Testing)
- Install Ngrok:
pkg install wget -y
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip
unzip ngrok-stable-linux-arm.zip
- 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?
| Feature | Nginx | Apache |
|---|---|---|
| Performance | Faster, lower memory usage | Slightly heavier, more features |
| Config | Simpler configuration | Supports .htaccess |
| Use Case | High-traffic, static sites | Dynamic sites, PHP apps |
Recommendation:
- Use Nginx for speed and simplicity.
- Use Apache if you need
.htaccessor 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!
Related Articles
Best Beginner JavaScript Projects for Hacking (2026 Guide)
If you want to break into web security, building the best beginner JavaScript projects for hacking is the most effective
How To Install Kali Nethunter in Termux
Kali Nethunter is a custom Android ROM that was developed specifically for penetration testing and security assessments.
Learn Cybersecurity: Essential Skills for Beginners
In today's digital age, cybersecurity is more important than ever. With increasing cyber threats, the demand for skilled
Why Tool Collectors Fail at Pentesting
Here is the real talk: your giant GitHub folder of 500 tools, your Kali box, loaded with all the extra packages, and you
How to Get Into Cybersecurity and Carve a Career Path (Without Lying to Yourself)
Let’s start with the hard truth you already suspect: most advice about starting a cybersecurity career is garbage. It’s
Setting up your bug bounty scripts with Python and Bash
Bug bounty programs have become increasingly popular in recent years, with companies offering rewards to hackers and sec
COMMENTS (0)
Sign in to post intel on this briefing.