How To Configure HTTP Based File Server On CentOS 8

We can configure the HTTP apache based file server on Linux using the python. Let’s see, how to configure HTTP based file server on CentOS 8.

Check Out: How To Install Linux Mint Cinnamon On VmWare Workstation

How To Configure HTTP Based File Server On CentOS 8

We can configure httpd base file server on CentOS 8/7. you just need to have the python installed on the Linux. Use the command to install different versions like python36, python, python2, etc. 

sudo yum install python38 -y

Once the python is installed, check the python version using python3 –version command. 

[root@fileserver ~]# python3 --version
Python 3.8.0

We will create a few sample files and stored them into a directory. Use the following commands. 

[root@fileserver ~]# mkdir httpfile
[root@fileserver ~]# touch file{1,2,3,4}
[root@fileserver ~]# mv file* httpfile/
[root@fileserver ~]# ls httpfile/
file1 file2 file3 file4

Open the port 8000 in the firewall rules.

[root@fileserver ~]# firewall-cmd --permanent --add-port=8000/tcp
[root@fileserver ~]# firewall-cmd --reload

Check Out: How To Configure Static IP Address On Ubuntu and CentOS 8

Method 1:

Using the python:

You have to install a simplehttpdserver module on Linux using the following commands according to your python version.

[root@fileserver ~]# cd httpfile/
[root@fileserver httpfile]# python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/)

Note: Use http.server for python 3 version and SimpleHTTPServer for python or python 2 versions.

python -m SimpleHTTPSever  or python2 -m SimpleHTTPSever

As you can see the HTTP file server has started on port 8000 and you can access the directory with any IP address by using the port number. This will only list the data.

You can also use the different ports to set up the HTTP file server using the below command. we can also bind the specific IP address. 

python3 -m http.server 8080                                                ## use different port
python3 -m http.server 8080 --bind 127.0.0.1

Check Out: How To Install and Enable RepoForge Repository On Linux

Method 2:

File Server Using Ruby:

We can also set up the file server using the ruby. you must have installed Ruby on your machine. 

sudo yum install ruby -y

Check the ruby version using the below command. 

[root@fileserver ~]# ruby -v
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]

Use the below command to create a ruby based HTTP server with port 8000.  

[root@fileserver httpfile]# ruby -run -ehttpd . -p8000
[2020-09-05 02:20:55] INFO WEBrick 1.4.2
[2020-09-05 02:20:55] INFO ruby 2.5.5 (2019-03-15) [x86_64-linux]
[2020-09-05 02:20:55] INFO WEBrick::HTTPServer#start: pid=2482 port=8000

You can access the file server using the URL http://ip:8000

http file server linux

Check Out: How To Install Numix Circle Icon Theme On Ubuntu 20.04

Method 3:

File Server Using HTTP-Server(Nodejs):

We have another method for file server using nodejs. you need to install nodejs on your machine.  

sudo yum install nodejs -y

Once the nodejs is installed, we need to install the http-server package with the below command. 

[root@fileserver httpfile]# npm install -g http-server
/usr/local/bin/http-server -> /usr/local/lib/node_modules/http-server/bin/http-server
/usr/local/bin/hs -> /usr/local/lib/node_modules/http-server/bin/http-server
+ http-server@0.12.3
added 23 packages from 35 contributors in 8.396s

Start the file server using the below command with port 8000. 

[root@fileserver]# cd httpfile
[root@fileserver httpfile]# http-server -p 8000
Starting up http-server, serving ./
Available on:
http://127.0.0.1:8000
http://192.168.185.147:8000
Hit CTRL-C to stop the server

Check the URL with http://ip:8000 

We’ve successfully shown you how to create https based file server with apache on Linux.

That’s it.

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment