How to Set Up and Run Python Applications (Django/Flask) in cPanel

63 views
Short answer: Open Setup Python App in cPanel, click 'Create Application', select Python version, establish project directory path, and leverage isolated virtual environment.

Deploy Python web applications, configure virtual environments, and run Django or Flask apps using CloudLinux Python Selector and WSGI.

Before you start: Back up your site files and database and download the backup to your own computer. How to take a full backup

Quick reference

Tool Location cPanel > Software > Setup Python App
Supported Python Versions Every version listed in Setup Python App
WSGI Handler passenger_wsgi.py
Virtualenv Automatically provisioned per application

Steps

  1. Create Application in cPanel:
    • Navigate to Software > Setup Python App.
    • Click Create Application.
    • Python Version: Choose the newest version your project supports.
    • Application Root: Path to project directory (e.g., python-app).
    • Application URL: Domain or subdomain for the app.
    • Application Startup File: passenger_wsgi.py.
    • Click Create.
  2. Activate Virtualenv in Terminal:
    • cPanel displays a command at the top: "Command for entering to the virtual environment".
    • Copy it (e.g. source /home/user/virtualenv/python-app/3.11/bin/activate).
    • Open Terminal in cPanel and paste that command.
  3. Install Packages: In the active virtualenv terminal, run:
    pip install -r requirements.txt
  4. Configure passenger_wsgi.py & Restart: Ensure passenger_wsgi.py exports application (e.g. from myproject.wsgi import application for Django). Click Restart in cPanel.

Troubleshooting and tips

  • ImportError in WSGI: Ensure that your project directory is added to sys.path inside passenger_wsgi.py:
    import sys, os sys.path.insert(0, os.path.dirname(__file__))
Need more help? If you run into an error while following these steps, open a ticket with technical support and our team will look into it. Open a ticket
Was this article helpful?
No, I need more help
Didn't find your answer?
Under 3 minutes
Submit Support Ticket