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?
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:
2. Now install the Apache server using the following command:
It will take time to install all useful packages.
3. Configure the "index.html" file inside the apache2 directory using the following commands:
To save hit CTRL + X and type y and hit enter.
Host website from Apache Server
Start the Apache server using the following command:
Now you can access the website from the Browser:
To check other commands for Apache2:
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:
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:
3. To check whether ngrok working or not use the following command:
4. Now use the following command to live your server:
Now! You are live.