StarDomain

How to Deploy Python App on Shared Hosting

How to Deploy Python App on Shared Hosting

Run Python (Django, Flask) applications on {{COMPANY_NAME}} shared hosting using the built-in Python Application Manager. No VPS needed.

Setting Up a Python Application in cPanel

Step 1: Create the Application

  1. Log in to cPanel.
  2. Go to Software > Setup Python App.
  3. Click Create Application.

Step 2: Configure

  • Python Version: select the version (3.8, 3.9, 3.10, 3.11, 3.12).
  • Application Root: folder for your code (e.g., `myflaskapp`).
  • Application URL: the domain/path.
  • Application Startup File: your WSGI entry point (e.g., `passenger_wsgi.py`).
  • Application Entry Point: typically `application`.

Step 3: Upload Code

Use File Manager, FTP, or SSH to upload your Python application files.

Step 4: Install Dependencies

  1. In the Python App Manager, use the Run Pip Install option.
  2. Or via SSH:
bash
source /home/username/virtualenv/myflaskapp/3.11/bin/activate
pip install -r requirements.txt

Step 5: Configure WSGI

Create a `passenger_wsgi.py` file in your application root:

For Flask:

python
import sys
sys.path.insert(0, '/home/username/myflaskapp')
from app import app as application

For Django:

python
import sys
import os
sys.path.insert(0, '/home/username/mydjangoproj')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Step 6: Restart

Click Restart in the Python App Manager. Visit your URL to verify.

Environment Variables

  1. In the Python App Manager, find Environment Variables.
  2. Add variables (e.g., `FLASK_ENV=production, SECRET_KEY=...`).
  3. Save and restart.

Troubleshooting

"Application Error" on Visit

  • Check passenger_wsgi.py syntax.
  • Verify all dependencies are installed in the virtual environment.
  • Check error logs.

Module Not Found

  • Ensure you installed packages in the correct virtual environment.
  • Use the full activation command provided by the Python App Manager.

Need help? Contact our support team at {{SUPPORT_URL}}/client/support.