Python Hosting with cPanel, Deploy and Manage Python App
Using the Setup Python App tool, deploying Python applications is now straightforward and uncomplicated thanks to cPanel’s Python hosting. Basically, this tutorial will cover step-by-step procedure to deploy and manage simple python application using various frameworks such as Django, Flask and FastAPI. While writing this example we used Python Hosting plan provided MediaStroke as it comes with Setup Python App tool. In case, you don’t have you can buy suitable plan from here.
Step By Step Procedure to Deploy and Manage Simple Python Application with Python Hosting
Deploying and managing your Python applications on Python Hosting is possible by following the instructions in this guide.
Here, basically 3 frameworks are provided for python hosting:
Flask
Django
FastAPI
Python Application Deployment
To create a python application following steps are involved:
Provide Login Credentials to cPanel.
Select Setup Python App under Software section of cPanel home screen.
Click on CREATE APPLICATION to begin the application setup on the Setup Python App page.
On the CREATE APPLICATION form, fill out the following fields:
Python version : Choose your preferred version from the drop-down list. Latest version is recommended.
Application root: It is for the location of application files in the file system. To form the full path to the application files in the cPanel home directory, the value will be appended to /home/<username>/ e.g. /home/<username>/<applicationroot>.Root names for applications can be flaskproject, djangoproject, fastapiproject, or any other name the user chooses.
Application URL: It is to form a web URL of the application.
Application startup file: The very first file that the application will process once it has been launched.
Application Entry Point: You can define the path along with the filename.
Passenger log file: You can define the path along with the filename e.g. /home/<username>/<applicationroot>logs/logs.log.
Click CREATE after finishing the form.
Flask Project initialization in Python Hosting in cPanel
Flask is lightweight microframework in python used for building web applications.
For creating the Flask application implement the following steps:
Create requirements.txt and app.py files
After creating the application go to the tools>> Files>> File Manager.
Go to the application root folder, create requirements.txt and app.py files.
Edit requirements.txt file
Select requirements.txt, click on edit and add following required Flask library.
from a2wsgi import ASGIMiddleware
from app import app
application = ASGIMiddleware(app)
Restart the application.
Your application will run.
Conclusion:
This article summing up covering step-by-step procedure to deploy and manage Python applications on server using cPanel with Python Hosting.This article is written considering simple Python applications of each framework as described above.
Leave a Reply