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
- Log in to cPanel.
- Go to Software > Setup Python App.
- 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
- In the Python App Manager, use the Run Pip Install option.
- Or via SSH:
bash
source /home/username/virtualenv/myflaskapp/3.11/bin/activate
pip install -r requirements.txtStep 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 applicationFor 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
- In the Python App Manager, find Environment Variables.
- Add variables (e.g., `
FLASK_ENV=production,SECRET_KEY=...`). - 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.
Related Articles
Need help? Contact our support team at {{SUPPORT_URL}}/client/support.