python-django-plesk-hosting-deploy-python-app-on-plesk

Hosting Python on Plesk: A Step-by-Step Guide to Deploying Django & Flask Apps

If you come from the world of PHP or WordPress, moving to Python can feel like a shock. You can’t just upload a file and expect it to work.

Python applications (like Django or Flask) run as continuous processes. They need a WSGI server (like Gunicorn), a reverse proxy (like Nginx), and a virtual environment to manage libraries. Setting this up manually via the command line takes hours and requires advanced Linux knowledge.

But with VPSPioneer’s Plesk-powered hosting, it takes minutes.

Whether you are building a simple API with Flask or a complex CMS with Django, our Web Hosting and VPS plans include the Plesk Python Manager. It automates the entire “DevOps” process for you.

In this guide, we will walk you through deploying a Python app from scratch.


Prerequisites

Before we begin, ensure you have:

  1. A VPSPioneer Account with Plesk access.
  2. Your Python project files ready (with a requirements.txt file).
  3. The “Python Support” extension enabled in your account (Contact support if you don’t see it).

Step 1: Prepare Your Project for the Web

Plesk needs to know two things: What libraries to install, and where your app starts.

  1. requirements.txt: Ensure your project root has this file listing all your dependencies (e.g., flask, django, requests).
  2. The Entry Point:
    • For Flask: Usually app.py.
    • For Django: It’s wsgi.py inside your inner project folder, but Plesk uses a special hook called passenger_wsgi.py (we will cover this below).

Step 2: Upload Your Code

You can use FTP, the File Manager, or the best method: Git.

  1. Log in to Plesk.
  2. Go to Websites & Domains -> Git.
  3. Connect your GitHub or GitLab repository.
  4. Plesk will pull your code into the httpdocs directory.

Pro Tip: Using Git allows you to update your live site simply by pushing code to GitHub and clicking “Pull Updates” in Plesk.


Step 3: Configure the Python Manager

This is where the magic happens.

  1. Go to Websites & Domains and click the Python icon.
  2. Enable Python: Switch it on.
  3. Python Version: Select the version you used to write your code (e.g., 3.9.18 or 3.10.x).
  4. App Root: Point this to where your requirements.txt is (usually /httpdocs).
  5. Application Startup File:
    • For Flask: app.py
    • For Django: passenger_wsgi.py (See Step 5).
  6. Application Mode: Set to “Production”.

Step 4: Install Dependencies (The “Pip Install” Button)

Forget about SSH-ing into your server to create virtual environments.

  1. In the Python Manager interface, look for your requirements.txt file listed.
  2. Click the “Run Pip Install” button.
  3. Plesk will create a virtual environment, download all your libraries, and install them safely.

Step 5: The “Passenger” Hook (Crucial for Django)

Plesk uses Phusion Passenger to bridge the gap between Nginx and Python. While Flask works almost out of the box, Django needs a tiny bridge file.

Create a file named passenger_wsgi.py in your httpdocs folder and paste this code:

import sys, os

# Point to your Django project folder
sys.path.append(os.getcwd())

# Import the standard Django WSGI application
from my_project_name.wsgi import application

Replace my_project_name with the actual name of your Django project folder.


Step 6: Running Commands (Migrations & Static Files)

If you use Django, you need to set up your database and collect static CSS/JS files.

You can do this directly from the Plesk interface without a terminal:

  1. In the Python Manager, look for the “Run Script” section.
  2. Type manage.py in the script name.
  3. Type migrate in the arguments.
  4. Click Run.
  5. Repeat for collectstatic.

Alternatively, you can SSH into your server (Ref: SSH Guide) and run these commands manually in the virtual environment.


Step 7: Restart and Launch

Click the “Restart Application” button in Plesk.

Visit your domain. You should see your live Python application! If you see a “Phusion Passenger” error page, check the Logs tab in Plesk to debug syntax errors.


Why VPSPioneer is the Best Home for Python

Python applications are resource-intensive. They consume more RAM and CPU than a standard HTML website.

Running Python on cheap, overcrowded hosting results in “502 Bad Gateway” errors.

  • Dedicated RAM: Our VPS Plans guarantee your RAM is yours. Your app won’t crash just because a neighbor is busy.
  • NVMe Storage: Python loads hundreds of small library files on startup. NVMe drives make your app boot instantly.
  • Scalability: Start on Web Hosting, and when your app goes viral, upgrade to a VPS seamlessly with the Plesk Migrator.

Frequently Asked Questions (FAQ)

Q: Can I schedule tasks (Cron Jobs) for my Python app? A: Yes! Plesk has a “Scheduled Tasks” menu. You can point it to the python executable inside your virtual environment to run scripts like daily_report.py.

Q: My static files (CSS/Images) are not loading in Django? A: Django doesn’t serve static files in production securely. You must run collectstatic. Also, ensure in Plesk “Apache & Nginx Settings” that you are serving static files directly by Nginx.

Q: Do I need a VPS, or can I use Web Hosting? A: For small Flask apps or student projects, our Web Hosting is sufficient. For heavy Django apps or commercial projects, we strongly recommend a VPS for better performance and isolation.