What is the best server for Python?


Python is a universal programming language and is often used to create web applications of various levels: simple blogs, complex systems with non-standard logic, and others. Typically, Python sites are built using Django or Flask frameworks. Therefore, it is best to place such projects on a hosting with native support for this language; torent a dedicated server seems to be the best option.

For ready-to-launch projects, you can use regular virtual hosting, and for loaded resources with prospects for improvement think about VPS/VDS like this one https://deltahost.com/dedicated.html and rent dedicated server.

Rent dedicated server

Python is a universal language and is often used to create web applications of various levels, from a simple blog to fairly complex systems with non-standard logic. Usually python sites are built on Django or Flask frameworks.

Should I rent dedicated server to run Python?

When choosing a hosting for Python, one should proceed from the tasks of the project and the peculiarities of its development. If you are making a complex loaded resource, then it is better to choose a VPS / VDS server and have full control over the system. If you already have a project completely ready to launch, and it does not imply intensive revision and extreme loads are not foreseen, then you can use virtual hosting with Python installed.

Preparing the server for publishing web-app in Python

First of all, after connecting as a root user, you should create a new user with administrator rights (this is not necessary, but at least good form):

adduser developer
passwd developer

Here you will need to enter and confirm the user's password

usermod -aG wheel developer

Add a user to the local administrators group

su - developer

Switch to the newly created user. Now we are preparing the environment:

sudo yum install -y epel-release
sudo yum install -y python3 python3-pip python3-devel nginx gcc
sudo yum update -y python36 python2
sudo yum groupinstall -y "Development Tools" "Development Libraries"
sudo yum install -y python3-devel python36-virtualenv

I would like to draw your attention to the penultimate line - "Development Tools" and "Development Libraries" are necessary for the correct launch of the virtual environment. We use the -y flag to execute the command without asking for confirmation.

Now you can start creating your working directory:

sudo mkdir / opt / myproject && cd / opt / myproject
sudo chown -R developer / opt /
python3 -m venv myprojectenv
source myprojectenv / bin / activate

pip3 install --upgrade pip
pip3 install uwsgi flask
The best server for Python

Now let's prepare the entry point to the web application:

vi /opt/myproject/wsgi.py (hereinafter I will use the vi editor, but this is a matter of taste)

def application (environ, start_response):
    start_response ('200 OK', [('Content-Type', 'text / html')])
    return ["

Testing Success!

This code, after running, will allow us to verify that all the previous steps were successful. For testing, let's start the service:
uwsgi --socket --protocol = http -w wsgi

With a physical ljcnegt or rdp connection, the result can be checked in the browser at With an SSH connection, open a new session and test with curl:

curl -v

The -v flag will allow you to see the complete output.

After testing is complete, you should terminate the service by pressing CTRL + C (otherwise you will have to search for the process and kill it with kill. Also an exit, but definitely less convenient).

Now you can make the main web application:

vi /opt/myproject/myproject.py

from flask import Flask
application = Flask (__ name__)

@ application.route ("/")
def hello ():
   return "

Hello There!

" if __name__ == "__main__": application.run (host = '')

The testing process is quite similar to the previous one - we launch the application using the python3 /opt/myproject/myproject.py command and check. the result should be the same.

Now let's edit the entry point so that when it is called, our application starts:

vi /opt/myproject/wsgi.py
from myproject import application
if __name__ == "__main__":
   application.run ()

Now comes the most difficult and interesting part. It's time to make a service out of this application that will work automatically and in the background... That will be the topic of our next article.

Get Solution for free from DataCamp guru