If you wish to make your own web hosting Linux computer, you are at the right place to completely understand the process.
To make Linux based web hosting that you can run from home you would need the following
- A computer with Linux installed.
- Install Apache2 which is an open-source HTTP server.
- Install PHP and PHP SQLite components that will help you to interact with the backend database for your website.
- Install MySQL which will store your data in the tabular form.
- Install Ngrok
Let’s go through step by step procedure to make your own web hosting on Linux
How To Make Your Own Web Hosting Server On Linux Computer
Step #1. Install Apache2
Apache is an open-source web server program that helps you power your website. It is the most popular web-server being used worldwide.
It comes installed and configured on most of the Linux Systems. You must check if it is installed on your system or not.
You can use the following command in the terminal of Debian based Linux OS.
# apt-cache policy apache2
This command will return the following if apache web-server is already installed
*** 2.2.22-13 0
If you don’t get this output you can move ahead to install the apache2 on your system.
Open your terminal and type the following commands
To first update the Local Packages
sudo apt update
Then type this command to install apache2
sudo apt install apache2
After running these commands you will get the following screen that asks for confirmation.
After you confirm the system will automatically complete the installation.
Your web browser must open a page labelled “Apache2 Ubuntu Default Page” as shown in the image below. This would confirm the proper installation of apache2 on your system.
Step #2. Install MySQL
MySQL is a database management server program that helps you store and retrieve data in tables. Some Linux systems come with pre-installed MySQL.
So, you need to first check that by using the following command.
# whereis mysql
If MySQL is already installed it will return the location otherwise you can move ahead with installing it.
Open the terminal and use the following commands
To first update the Local Packages
sudo apt update
Then type this command to install MySQL
sudo apt install MySQL-server
After you give the confirmation on the following screen the system will automatically install MySQL.
After the installation is complete, the MySQL server should start automatically and you can check using the following command.
systemctl status mysql.service
This will return the status of the SQL server. If it is not running for some reason you can use the following command to start MySQL server
sudo systemctl start mysql
You can use the following command for securing your MySQL server by setting a Password.
This command will give you the option to set the password as shown below. You would need to give confirmation by typing “y” for setting a password.
Next, you will be asked for entering an 8-letter password that will secure your MySQL database from unauthorised access.
Step #3. Install PHP
PHP has multiple program libraries used for different needs. Php5-MySQL is one among them that you will use while making your own hosting.
You need to run the following command to install PHP for your hosting needs
$ sudo apt-get install php5 libapache2-mod-php5
The system will automatically install PHP after you give the necessary permissions.
Now you would need to restart your Apache to see the changes made and run PHP.
Use this command in the terminal to restart Apache
$ sudo service apache2 restart
And check the status of apache server by using
$ sudo service apache2 status
Now you need to check the installation of PHP
For that, you need to create a file called “info.php”
You can use this command
sudo vi /var/www/html/info.php
And then insert the following code in the file
Now, You can check whether PHP running properly by opening browser and opening this
You will get the following page that confirms the PHP installation.
Step #4. Using Ngrok
Now you need to set up an IP address for your Linux Web Server. As you might be aware that IP address keeps on changing and setting a Static IP address is one solution. But setting static IP has its own problems like IP conflict, Port forwarding that need expert understanding to troubleshoot.
You should rather use changing IPs with the webserver and allot a URL to access them. For that, you can use “ngrok” that will help you update new IP with the website.
Ngrok is the easiest wat to make localhost available online. Although it is a paid service you will get the basic services for free.
Ngrok creates a secure tunnel to your localhost that binds your IP with the URL. When someone visits your URL all the requests would be forwarded to your Localhost. If the IP address changes Ngrok will quickly update it on the website keeping your website up for the most time.
Now you need to create a free account on the Ngrok website and download the Ngrok client for Linux from here. You should download the 32-bit version or 64-bit version depending upon your system and requirement.
After you download, you need to unzip the files then you can use the following command in terminal to install Ngrok.
sudo snap install ngrok
Now you can connect your account. You can use this command to add your account’s authtoken to Ngrok.
./ngrok authtoken <YOUR_AUTHTOKEN>
Your authcode would be mentioned in your account on Ngrok website
Now you can use this command to create a tunnel to your localhost
./ngrok http 80
Now Ngrok will assign a URL to the localhost automatically. You can copy that use that in your browser to verify. To use your own custom domain you would need to use the paid version of Ngrok.
Now you have successfully hosted your own Linux website server on which you can now upload your websites for the world to see.
Now You can use your own web server hosting for testing your websites that you are making. But it is not recommended to use own web server for running a website with regular visitors. You can also install Content management systems like WordPress on this hosting to build a website.
By using Ngrok you can easily bypass the painful process of setting a working static IP. Using the paid version of Ngrok you can also set up multiple tunnels.