Deploy Python server in one minute

in How to

How to install python3 on Linux and Set up a Development Server

Most of the Linux comes with Python version 2.x preinstalled.
Different Linux Distros comes with different version of Python version(2.5.1 or earlier ).
you might want to upgrade or install the latest version of python?

There are two ways to install python on linux distros

1. Build python from source
2. install using package manger, some distros come with GUI package manger as well.
3. Setup simple server using python3

1. Build From source – don’t panic its not rocket science

Download Python3.8 source tar ball

Python3.8

tar xzf Python-3.8.0.tar.xz
cd Python-3.8.0
sudo apt-get install build-essential libsqlite3-dev
./configure
make
make install

2. install using package manger

#simply enter these command in Terminal 
#Debain based distros like UBUNTU/MINT
sudo apt install python3
#Arch based Distros like Manjaro 
sudo pacman -S python3
3. Setup Simple Server Using Python
First create a Index.html file and paste below code into it
<html>
    <head>
        <title>Testing Server!</title>
    </head>
    <body>
        <h1>Testing Server</h1>
        <p>Hello Thegeekflux</p>
    </body>
</html>
Now open terminal and enter command
python -m http.server 8080

By default, this server will be listening on all interfaces and on port 8080.
If you want to listen to a specific interface, do the following:

python -m http.server 8080 --bind 127.0.0.1

also you can use the –directory flag to serve files from a directory that is not necessarily the current directory.

Is it Helpful? leave a comment below 🙂

Write a Comment

Comment