How to host web app backend processing in Python using a rental server subdomain

This is a method of hosting the backend processing of the web application in Python using the subdomain added to the original domain by Xserver. I think that the method of hosting in the cloud such as GCP and AWS is common these days, but this time I will do it with Xserver in consideration of cost and performance.

There are already a number of excellent articles about the details, and even if you describe it, it will be a deteriorated copy, so I will omit it, but since there was no particular part about creating an API with a subdomain, I will focus on the flow here. I will describe it. It's like my own memo, so I don't know.

It is assumed that the Xserver's own domain already exists.

What you want to do in the end

(In my case) already https://np-sys.com/ Add a subdomain to https://APIs.np-sys.com/ Folder name to store API / Slug of URL defined in Flask (end) Let's run the backend processing in the form of. Of course, you can use your favorite domain.

Tools to use

Python that I put in the Xserver Python Flask library

flow

--Install python on Xserver --Create a subdomain on the server panel of Xserver, and create a folder name to store the API in public_html. For example, create a folder called functions --Run python scripts with cgi

is.

Install python on Xserver

I have Python originally included in the Xserver, but due to permissions I can't install any libraries with the pip command. Therefore, you need to include your own Python. The following was easy to understand for the detailed method. This is quite a burden. https://note.com/coeeff/n/neab8acfde97e https://qiita.com/kusumoto-t/items/b262b8878ccdfd137fa3

Create a subdomain

Create a subdomain in the server panel of the Xserver. https://www.xserver.ne.jp/login_server.php

You can go with the touch of a button. スクリーンショット 2020-10-12 9.58.42.jpg

Then connect to the top of that subdomain by FTP or ssh and create a folder to put the script. This time I chose functions. Please do not think that the characters of the subdomain are not in consideration of security because they do not describe the actual ones.

スクリーンショット 2020-10-12 10.17.52.jpg

Make cgi run python scripts

After that, let's run python with cgi. This was the easiest to understand. https://neko-py.com/xserver-web-application

Note that don't forget to change the permissions and specify the Python path as an absolute path at the beginning of index.cgi (#! /home/Myname/.linuxbrew/bin/python3 worked, but #! It didn't work with ~ / .linuxbrew / bin / python3), but be careful about installing Flask properly.

Then https://apis.np-sys.com/functions/ It works with the URL corresponding to.

スクリーンショット 2020-10-12 10.34.11.jpg

It seems easier to understand if you manage the folder name created at the top of the subdomain for each application.

Recommended Posts

How to host web app backend processing in Python using a rental server subdomain
How to execute a command using subprocess in Python
How to get a stacktrace in python
How to generate a new loggroup in CloudWatch using python within Lambda
How to get a value from a parameter store in lambda (using python)
Set up a local web server in 30 seconds using python 3's http.server
How to open a web browser from python
How to embed a variable in a python string
How to create a JSON file in Python
Steps to develop a web application in Python
How to notify a Discord channel in Python
How to take multiple arguments when doing parallel processing using multiprocessing in python
[Python] How to create a local web server environment with SimpleHTTPServer and CGIHTTPServer
How to convert / restore a string with [] in python
How to set up a Python environment using pyenv
How to measure processing time in Python or Java
(Python) Try to develop a web application using Django
[Python] How to expand variables in a character string
How to make a Python package using VS Code
How to exit when using Python in Terminal (Mac)
Write code to Unit Test a Python web app
How to retrieve multiple arrays using slice in python.
How to unit test a function containing the current time using freezegun in python
How to develop in Python
Using Python mode in Processing
How to deploy a web app made with Flask to Heroku
How to slice a block multiple array from a multiple array in Python
A story about how to specify a relative path in python.
How to use the __call__ method in a Python class
How to launch AWS Batch from a python client app
How to import a file anywhere you like in Python
How to specify a public directory Python simple HTTP server
How to transpose a 2D array using only python [Note]
How to define multiple variables in a python for statement
I tried "How to get a method decorated in Python"
How to develop in a virtual environment of Python [Memo]
How to generate a query using the IN operator in Django
To return char * in a callback function using ctypes in Python
How to get the last (last) value in a list in Python
How to get a list of built-in exceptions in python
I tried to make a stopwatch using tkinter in python
To receive multiple return values ​​from a function executed using parallel processing (Pool) in Python
How to start a simple WEB server that can execute cgi of php and python
How to create an instance of a particular class from dict using __new__ () in python
[Question] How to get data of textarea data in real time using Python web framework bottle
How to install python using anaconda
Turn your Android Smart Phone into a Web Server using python.
How to write a Python class
Run the output code on the local web server as "A, pretending to be B" in python
[Python] How to do PCA in Python
How to determine the existence of a selenium element in Python
How to pass arguments to a Python script in SPSS Modeler Batch
Python: Introduction to Flask: Creating a number identification app using MNIST
How to make a string into an array or an array into a string in Python
How to collect images in Python
[Introduction to Python] How to output a character string in a Print statement
How to use SQLite in Python
How to check the memory size of a variable in Python
How to get a string from a command line argument in python
How to create a heatmap with an arbitrary domain in Python
[Introduction to Python] How to use the in operator in a for statement?