Skip to main content

Python App Deployment Step-by-Step Video Guide

Deploying any Python-based Aplication with WebHostMost is a straightforward and quick process thanks to the Python Application integration. This tool allows you to install a Python project in just a few clicks, providing an easy way to manage your application and Python version directly via Web Control Panel.


How to Deploy a Python Application

Quick Intro

Python is a versatile programming language that powers everything from simple scripts to complex web applications. With Python, you can build robust and scalable applications, including web frameworks like Django and Flask.

Important To Know Before You Begin

Each domain on WebHostMost has a default index.html file located in the document root directory: File Manager > domains/yourdomain.com/public_html. This file is automatically created when the domain is assigned to the Web Control Pabnel, and must be manually deleted before deploying a Python application. The creation of a Python app does not remove this file, and it can interfere with your app if not deleted.

warning

Important: Deleting the Python app via the Web Control Panel does not remove the files from the File Manager. You must manually delete these files if they are no longer needed. Additionally, you do not need to configure any ports for your Python application; the server automatically handles port assignments.

Setting Up Your Python Environment

Access the Python App Selector

  • Navigate to Web Control Panel > Website Management > Python App in your Web Control Panel.
GIF

Create a New Python Application

  • Click on Create Application.
  • Fill in the following details:
    • Python Version: Choose the version of Python that your project requires.
    • Application Root: It is a physical address to your application on a server. Set the directory to: public_html (it'll automatically change after you perform the initial creation).
    • Application URL: Select the domain name from the dropdown you want to apply the installation for. Leave the text field empty. However you can add an extra path, if required (e.g: /new-path/).
    • Application Startup File: Leave it empty, the system will automatically create a proper file for your project. In some cases, you can assign the exact name, if you are sure what you are doing (e.g: app.py or wsgi.py for web frameworks).
    • Application Entry Point: Leave it empty, the system will automatically fill this field as necessary (usually with the following parameter: application).
  • Click Create to set up the environment.

Uploading Your Python Project Files

Now, when you've set the Python App environment as shown above, it's time to upload project files.

  • You can upload your project files using the Drag and Drop feature in the File Manager, with the SCP command via Terminal, or Git. Ensure all necessary files are uploaded to the document root directory you specified earlier (public_html of your specific domain name).

If you uploaded an archive, unarchive it and make sure all of its files are located inside of the public_html. If you unarchived a singe folder that contains project files inside of it (e.g: mytestblog), make sure to move them all out of that folder to the main public_html folder of your domain name.

Access Python Virtual Environment

  • After creating the Python application, a link to the virtual environment is provided at the top of the Python App page in the Web Control Panel. This virtual environment must be activated before you can install packages or run commands via the terminal.
GIF

Install Python Project Dependencies

  • Access your server via SSH or use the Web Terminal in the Web Control Panel.
  • Activate the virtual environment by running the command provided in the Python App section of the Web Control Panel.
  • Once the virtual environment is activated, you can install your project’s dependencies:
    pip install -r requirements.txt
tip

Make sure your requirements.txt file correctly lists all dependencies needed to run your application. If you encounter errors during the requirements installation, read carefully the Web Terminal's reply, and replace incompatible modules in your requirements.txt with the one that Terminal is offering you.

Configuring the Python Startup File

Python Startup File For Django (passenger_wsgi.py)

import sys
import os

# Define path to the project
sys.path.insert(0, '/home/webhostmostsystemusername/domains/yourdomain.com/public_html')

# Define variable for the Django project
os.environ['DJANGO_SETTINGS_MODULE'] = 'folder.settings'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Explanation Of The (passenger_wsgi.py) Startup File

  1. Path to the project
  • The path shown in the example must be modified to meet your project requirements. Instead of the /webhostmostsystemusername/ you must type your server account's username. It can be found inside of your Web Control Panel or inside of your current service plan on the Client Area's page.

  • The yourdomain.com must be replaced with your actual domai name your are working on.

  1. Variable for the Django project
  • instead of folder.settings you must type your own parameter where the setting file is located for this project. For example, if you have a folder called (blog), and inside of that folder you have settings.py, than your variable must look like: blog.settings.
tip

After each change, you must restart the Python application from the Web Control Panel under Python App > Manage Applications > Restart for the changes to apply.

tip

Python web applications typically use ports like 5000 for Flask or 8000 for Django. However, on a shared hosting environment, the system assigns an internal port 80. The Python selector will manage this for you, so you don't need to worry about configuring the port.

warning

Important: Ensure your application listens to 127.0.0.1 instead of 0.0.0.0. This prevents unauthorized external access to your app.

Testing Your Python Application

  • Access Your Python Application:
    • Open your browser and navigate to the domain or subdomain where your Python app is deployed. Ensure everything works as expected.
    • If problems occur with your Python project and you see the debug screen, read it carefuly and perform necessary adjustments to fix the issue.

Troubleshooting Common Issues

  • Application Not Starting: Check the startup file and ensure it’s correctly defined in the Web Control Panel. Also, check for errors in your code or missing dependencies.
  • Error 500:
    • Make sure all the project files are located inside of the public_html folder of your specific domain.
    • Make sure all the variables are correct in your project's settings file.
    • Make sure you have enough disk space for the project.
    • Make sure the Python App has successfully started.

Conclusion

Deploying a Python project on WebHostMost is seamless and efficient using the tools provided in the Web Control Panel. By following the steps outlined above, you can have your Python application up and running in no time. For further assistance, don’t hesitate to contact our support team.


Deploy your Python apps with confidence using WebHostMost's powerful and flexible Web Control Panel.