{"id":3030,"date":"2025-05-02T09:49:14","date_gmt":"2025-05-02T09:49:14","guid":{"rendered":"https:\/\/cybersecurityinfocus.com\/?p=3030"},"modified":"2025-05-02T09:49:14","modified_gmt":"2025-05-02T09:49:14","slug":"ultimate-guide-hosting-a-live-website-in-termux-with-nginx-apache-%f0%9f%9a%80","status":"publish","type":"post","link":"https:\/\/cybersecurityinfocus.com\/?p=3030","title":{"rendered":"Ultimate Guide: Hosting a Live Website in Termux with Nginx &amp; Apache! \ud83d\ude80"},"content":{"rendered":"<p>Do you want to turn your Android phone into a <strong>fully functional web server<\/strong>? With <strong>Termux<\/strong>, you can run <strong>Nginx<\/strong> or <strong>Apache<\/strong> to host a live website locally\u2014or even make it public! This in-depth guide will walk you through <strong>setting up both web servers<\/strong>, configuring custom websites, and exposing them to the internet.<\/p>\n<h2 class=\"wp-block-heading\"><strong>Why Use Termux for Web Hosting?<\/strong><\/h2>\n<p> <strong>Portable web server<\/strong> \u2013 Host websites directly from your phone.<br \/> <strong>Great for testing &amp; development<\/strong> \u2013 Perfect for web developers on the go.<br \/> <strong>Low-resource &amp; efficient<\/strong> \u2013 Nginx and Apache run smoothly on Android.<br \/> <strong>Public or local hosting<\/strong> \u2013 Share with others via LAN or the internet.<\/p>\n<h2 class=\"wp-block-heading\"><strong>Prerequisites<\/strong><\/h2>\n<p>Before we begin, ensure you have:<br \/> <strong>Termux<\/strong> installed (<a href=\"https:\/\/f-droid.org\/en\/packages\/com.termux\/\">Download from F-Droid<\/a>)<br \/> A stable internet connection<br \/> Basic knowledge of Linux commands<\/p>\n<h2 class=\"wp-block-heading\"><strong>Option 1: Hosting a Website with Nginx<\/strong><\/h2>\n<p>Nginx is a <strong>lightweight, high-performance<\/strong> web server perfect for Termux.<\/p>\n<h3 class=\"wp-block-heading\"><strong>Step 1: Install Nginx<\/strong><\/h3>\n<p>Update packages and install Nginx:<\/p>\n<p>pkg update &amp;&amp; pkg upgrade -y<br \/>\npkg install nginx -y<\/p>\n<h3 class=\"wp-block-heading\"><strong>Step 2: Start Nginx<\/strong><\/h3>\n<p>Run the server:<\/p>\n<p>nginx<\/p>\n<p>Verify it\u2019s working:<\/p>\n<p>curl http:\/\/localhost:8080<\/p>\n<p>You should see the <strong>default Nginx welcome page<\/strong>.<\/p>\n<p><strong> Note:<\/strong> Nginx runs on <strong>port 8080<\/strong> in Termux (Android restricts ports below 1024).<\/p>\n<h3 class=\"wp-block-heading\"><strong>Step 3: Access Your Website Locally<\/strong><\/h3>\n<p>Open a browser and visit:<\/p>\n<p>http:\/\/localhost:8080<\/p>\n<h3 class=\"wp-block-heading\"><strong>Step 4: Replace Default Page with a Custom Website<\/strong><\/h3>\n<p>Navigate to Nginx\u2019s web directory:<\/p>\n<p>   cd $PREFIX\/share\/nginx\/html\/<\/p>\n<p>Remove the default files:<\/p>\n<p>   rm -rf *<\/p>\n<p>Create a new index.html:<\/p>\n<p>   nano index.html<\/p>\n<p>Paste this sample HTML:<\/p>\n<p>   &lt;!DOCTYPE html&gt;<br \/>\n   &lt;html&gt;<br \/>\n   &lt;head&gt;<br \/>\n       &lt;title&gt;My Termux Website!&lt;\/title&gt;<br \/>\n   &lt;\/head&gt;<br \/>\n   &lt;body&gt;<br \/>\n       &lt;h1&gt;\ud83d\ude80 Website Hosted on Termux!&lt;\/h1&gt;<br \/>\n       &lt;p&gt;Powered by &lt;b&gt;Nginx&lt;\/b&gt;&lt;\/p&gt;<br \/>\n   &lt;\/body&gt;<br \/>\n   &lt;\/html&gt;<\/p>\n<p>Save with Ctrl+O \u2192 Enter \u2192 Ctrl+X.<\/p>\n<p>Restart Nginx:<\/p>\n<p>   nginx -s reload<\/p>\n<p>Refresh http:\/\/localhost:8080 to see your site!<\/p>\n<h2 class=\"wp-block-heading\"><strong>Option 2: Hosting a Website with Apache<\/strong><\/h2>\n<p>Apache is another powerful web server with <strong>.htaccess support<\/strong> and modularity.<\/p>\n<h3 class=\"wp-block-heading\"><strong>Step 1: Install Apache<\/strong><\/h3>\n<p>Run:<\/p>\n<p>pkg install apache2 -y<\/p>\n<h3 class=\"wp-block-heading\"><strong>Step 2: Start Apache<\/strong><\/h3>\n<p>apachectl start<\/p>\n<p>Verify it\u2019s running:<\/p>\n<p>curl http:\/\/localhost:8080<\/p>\n<p>You should see the <strong>Apache default page<\/strong>.<\/p>\n<p><strong> Note:<\/strong> Apache also runs on <strong>port 8080<\/strong> in Termux.<\/p>\n<h3 class=\"wp-block-heading\"><strong>Step 3: Access Your Website Locally<\/strong><\/h3>\n<p>Visit in a browser:<\/p>\n<p>http:\/\/localhost:8080<\/p>\n<h3 class=\"wp-block-heading\"><strong>Step 4: Customize Your Website<\/strong><\/h3>\n<p>Navigate to Apache\u2019s web directory:<\/p>\n<p>   cd $PREFIX\/share\/apache2\/default-site\/htdocs\/<\/p>\n<p>Remove default files:<\/p>\n<p>   rm -rf *<\/p>\n<p>Create a new index.html:<\/p>\n<p>   nano index.html<\/p>\n<p>Paste this sample HTML:<\/p>\n<p>   &lt;!DOCTYPE html&gt;<br \/>\n   &lt;html&gt;<br \/>\n   &lt;head&gt;<br \/>\n       &lt;title&gt;Apache on Termux!&lt;\/title&gt;<br \/>\n   &lt;\/head&gt;<br \/>\n   &lt;body&gt;<br \/>\n       &lt;h1&gt;\ud83d\udd25 Website Hosted on Termux!&lt;\/h1&gt;<br \/>\n       &lt;p&gt;Powered by &lt;b&gt;Apache&lt;\/b&gt;&lt;\/p&gt;<br \/>\n   &lt;\/body&gt;<br \/>\n   &lt;\/html&gt;<\/p>\n<p>Save (Ctrl+O \u2192 Enter \u2192 Ctrl+X).<\/p>\n<p>Restart Apache:<\/p>\n<p>   apachectl restart<\/p>\n<p>Refresh http:\/\/localhost:8080 to see your new site!<\/p>\n<h2 class=\"wp-block-heading\"><strong>Making Your Website Public<\/strong><\/h2>\n<p>Want others to access your site? Here\u2019s how:<\/p>\n<h3 class=\"wp-block-heading\"><strong>Option 1: Local Network (LAN) Access<\/strong><\/h3>\n<p>Find your phone\u2019s local IP:<\/p>\n<p>   ifconfig<\/p>\n<p>Look for wlan0 (Wi-Fi) and note the inet address (e.g., 192.168.x.x).<\/p>\n<p>Others on the same network can visit:<\/p>\n<p>   http:\/\/[YOUR_LOCAL_IP]:8080<\/p>\n<h3 class=\"wp-block-heading\"><strong>Option 2: Public Access with Ngrok (Best for Testing)<\/strong><\/h3>\n<p>Install Ngrok:<\/p>\n<p>   pkg install wget -y<br \/>\n   wget https:\/\/bin.equinox.io\/c\/4VmDzA7iaHb\/ngrok-stable-linux-arm.zip<br \/>\n   unzip ngrok-stable-linux-arm.zip<\/p>\n<p>Run Ngrok (requires <a href=\"https:\/\/ngrok.com\/\">Ngrok account<\/a>):<\/p>\n<p>   .\/ngrok http 8080<\/p>\n<p>You\u2019ll get a public URL like https:\/\/xyz.ngrok.io.<\/p>\n<p>Now, <strong>your website is accessible worldwide!<\/strong> <\/p>\n<h2 class=\"wp-block-heading\"><strong>Stopping the Servers<\/strong><\/h2>\n<p>When done, stop the servers:<\/p>\n<h3 class=\"wp-block-heading\"><strong>For Nginx:<\/strong><\/h3>\n<p>nginx -s stop<\/p>\n<h3 class=\"wp-block-heading\"><strong>For Apache:<\/strong><\/h3>\n<p>apachectl stop<\/p>\n<h2 class=\"wp-block-heading\"><strong>Nginx vs. Apache in Termux: Which is Better?<\/strong><\/h2>\n<p>FeatureNginxApache<strong>Performance<\/strong>Faster, lower memory usageSlightly heavier, more features<strong>Config<\/strong>Simpler configurationSupports .htaccess<strong>Use Case<\/strong>High-traffic, static sitesDynamic sites, PHP apps<\/p>\n<p><strong>Recommendation:<\/strong><\/p>\n<p>Use <strong>Nginx<\/strong> for speed and simplicity.<\/p>\n<p>Use <strong>Apache<\/strong> if you need .htaccess or PHP support.<\/p>\n<h2 class=\"wp-block-heading\"><strong>Bonus: Running PHP with Apache<\/strong><\/h2>\n<p>Want to host PHP websites? Install PHP:<\/p>\n<p>pkg install php -y<\/p>\n<p>Then, restart Apache:<\/p>\n<p>apachectl restart<\/p>\n<p>Now, you can run PHP scripts in htdocs\/!<\/p>\n<h2 class=\"wp-block-heading\"><strong>Final Thoughts<\/strong><\/h2>\n<p>You\u2019ve now learned how to:<br \/> <strong>Host a website in Termux using Nginx &amp; Apache<\/strong><br \/> <strong>Customize your site with HTML<\/strong><br \/> <strong>Access it locally or publicly via Ngrok<\/strong><\/p>\n<p> <strong>Try it out and turn your Android into a web server today!<\/strong><\/p>\n<p> <strong>Follow <a href=\"https:\/\/t.me\/codelivly\">Codelivly<\/a> for more Termux &amp; Cybersecurity guides!<\/strong><\/p>","protected":false},"excerpt":{"rendered":"<p>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\u2014or 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 [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3030","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=\/wp\/v2\/posts\/3030"}],"collection":[{"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3030"}],"version-history":[{"count":0,"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=\/wp\/v2\/posts\/3030\/revisions"}],"wp:attachment":[{"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}