Host a Website from your mobile

A common belief is that hosting a website requires a server, typically running on Linux or Windows. But, did you know you can host a website using an Android device? Yes, it's possible! Here's what you need:

  • Termux: This is an app that turns your Android device into a powerful terminal emulator, allowing you to execute commands just like you would on a computer.
  • Proper Internet Connection: Ensure your device is connected to the internet for your website to be accessible to users. With these two elements, you can host a website directly from your Android device.




What is the benefit or Advantage of a server?

Servers offer various advantages, primarily serving as hosts for websites and web applications. Additionally, they facilitate tasks like hacking by enabling actions such as sending malicious code or hosting phishing sites.

Setting Up and Configuring a Server:

To host a website, having a server is essential. Let's guide you through the process of installing an Apache server on an Android device using Termux:

1. Open Termux and update the package:

$ pkg update

2. Now install the Apache server using the following command:

pkg install apache2

It will take time to install all useful packages.

3. Configure the "index.html" file inside the apache2 directory using the following commands:

pwd
/data/data/com.termux/files/home
$ cd ..
$ ls
home usr
$ cd usr/share/apach2/default-site/htdocs
$ ls
index.html manual
nano index.html

To save hit CTRL + X and type y and hit enter.


Host website from Apache Server

Start the Apache server using the following command:

apachectl
AH00558: httpd: Could not reliably determine the server's fully qualified 
domain name, using 127.0.0.1. Set the 'ServerName' directive globally to 
suppress this message

Now you can access the website from the Browser:

access website

To check other commands for Apache2:

apachectl -h

Usage: /data/data/com.termux/files/usr/bin/httpd [-D name] [-d directory] [-f file]

                                                 [-C "directive"] [-c "directive"]

                                                 [-k start|restart|graceful|graceful-stop|stop]

                                                 [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]

Options:

  -D name            : define a name for use in <IfDefine name> directives

  -d directory       : specify an alternate initial ServerRoot                                        -f file            : specify an alternate ServerConfigFile

  -C "directive"     : process directive before reading config files

  -c "directive"     : process directive after reading config files

  -e level           : show startup errors of level (see LogLevel)

  -E file            : log startup errors to file

  -v                 : show version number

  -V                 : show compile settings

  -h                 : list available command line options (this page)

  -l                 : list compiled in modules

  -L                 : list available configuration directives

  -t -D DUMP_VHOSTS  : show parsed vhost settings

  -t -D DUMP_RUN_CFG : show parsed run settings

  -S                 : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG

  -t -D DUMP_MODULES : show all loaded modules

  -M                 : a synonym for -t -D DUMP_MODULES

  -t -D DUMP_INCLUDES: show all included configuration files

  -t                 : run syntax check for config files

  -T                 : start without DocumentRoot(s) check

  -X                 : debug mode (only one worker, do not detach)

~ $


Now Stop the Apache Server:

apachectl stop
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message

You can host your website from your mobile in this way.  But you can’t access it outside of your network.

 

Live Website with the Help of Port Forwarding

With the help of Port Forwarding, anyone can access your website from anywhere in the world. Follow these steps:

1. Download ngrok from the official download page:


Download Ngrok

Ngrok is a powerful tool that allows you to expose a local development server to the internet. This page provides information and links for downloading Ngrok based on your operating system. Ngrok is widely used for secure introspectable tunnels to localhost.


2. Copy to home and extract using the following command:

$ cp storage/download/ngrok-stable-linux-arm.zip .
ls
ngrok-stable-linux-arm.zip storage
$ unzip ngrok-stable-linux-arm.zip

3. To check whether ngrok working or not use the following command:

$ ./ngrok
~ $ ./ngrok
WARN[02-08|14:50:27] failed to get home directory, using $HOME instead err="user: Current not implemented on linux/arm" $HOME=/data/data/com.termux/files/home
NAME:
   ngrok - tunnel local ports to public URLs and inspect traffic

DESCRIPTION:
    ngrok exposes local networked services behinds NATs and firewalls to the
    public internet over a secure tunnel. Share local websites, build/test
    webhook consumers and self-host personal services.
    Detailed help for each command is available with 'ngrok help <command>'.
    Open http://localhost:4040 for ngrok's web interface to inspect traffic.

EXAMPLES:
    ngrok http 80                    # secure public URL for port 80 web server
    ngrok http -subdomain=baz 8080   # port 8080 available at baz.ngrok.io
    ngrok http foo.dev:80            # tunnel to host:port instead of localhost
    ngrok http https://localhost     # expose a local https server
    ngrok tcp 22                     # tunnel arbitrary TCP traffic to port 22
    ngrok tls -hostname=foo.com 443  # TLS traffic for foo.com to port 443
    ngrok start foo bar baz          # start tunnels from the configuration file

VERSION:
   2.3.35

AUTHOR:
  inconshreveable - <[email protected]>

COMMANDS:
   authtoken    save authtoken to configuration file
   credits      prints author and licensing information
   http         start an HTTP tunnel
   start        start tunnels by name from the configuration file
   tcp          start a TCP tunnel
   tls          start a TLS tunnel
   update       update ngrok to the latest version
   version      print the version string
   help         Shows a list of commands or help for one command
~ $

4. Now use the following command to live your server:

./ngrok http 8080

Now! You are live.


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!