How to host a http server on your linux computer to share files

Utpal Kumar   2 minute read   
   visitor badge  

Is the signal denoising using a wavelet effective? We will implement the wavelet-based signal denoising using the MATLAB

In this post, we will see how we can create a http webserver using Python 3. There are so many applications for such servers. One of them is the quick way to share your files to someone, or host your website or blog. You can also use paramiko module in Python to securely send files from one computer to another.

If you host your website or blog locally then you don’t need to pay hosting fee to any agent and everything will be in your reach. However, there are other benefits of hosting your website through a good web-hosting platform. I will not go into that details in this post.

The module we will we using for hosting a http server comes by default on your Python3 installation - http.server. It is also super easy to run. Let us go through two examples.

Host your files on the http server

Let us create a directory called mywebserver. This will serve as our root of the server. THen we create two more sub-directories inside mywebserver directory.

mkdir mywebserver
cd mywebserver/
mkdir importantFiles notSoImportantFiles
Create directories
Create directories

Then we create some files in each subdirectories:

touch importantFiles/myFile{1..5}
touch notSoImportantFiles/myFile{1..5}
Create files
Create files

Now, we have enough to serve our server. So, let’s not delay anymore and start our server.

python -m http.server
HTTP Server Running
HTTP Server Running

And, we have our server serving at the ip_address:port. To check the ip address of your system, you can type:

ip addr

That’s it. It is as easy as this to host your personal web server using Python. Please note that in some cases, your server may not be accessible from the remote computer. This may probably be because of your system’s firewall. You can stop the firewall temporarily using:

sudo systemctl stop firewalld

Host a blog

Now, we will create a very simple blog, and host it on our personal server. I will copy the html and css codes from the w3schools.com.

mkdir mypersonalBlog
cd mypersonalBlog/
touch index.html
Creating and running a blog locally
Creating and running a blog locally

Now open the index.html page and copy and paste the codes from w3schools.com.

Next, you can start your server.

python -m http.server
The blog as seen from another computer
The blog as seen from another computer

Disclaimer of liability

The information provided by the Earth Inversion is made available for educational purposes only.

Whilst we endeavor to keep the information up-to-date and correct. Earth Inversion makes no representations or warranties of any kind, express or implied about the completeness, accuracy, reliability, suitability or availability with respect to the website or the information, products, services or related graphics content on the website for any purpose.

UNDER NO CIRCUMSTANCE SHALL WE HAVE ANY LIABILITY TO YOU FOR ANY LOSS OR DAMAGE OF ANY KIND INCURRED AS A RESULT OF THE USE OF THE SITE OR RELIANCE ON ANY INFORMATION PROVIDED ON THE SITE. ANY RELIANCE YOU PLACED ON SUCH MATERIAL IS THEREFORE STRICTLY AT YOUR OWN RISK.


Leave a comment