Plesk can host Python web applications such as Flask and Django using Phusion Passenger as the application server. Setup requires some server-side configuration, but once done your app runs directly from the Plesk interface.
Prerequisites
- Phusion Passenger and Python must be installed on the server. If the Python option is not available, contact your hosting provider.
- Your application files ready with a
requirements.txtlisting all dependencies. - SSH access may be required for installing Python packages.
Step 1: Upload your application
- Log in to Plesk.
- Go to Websites & Domains and find your domain.
- Upload your Python app files to the domain directory using File Manager, FTP, or the Git extension.
- Make sure
requirements.txtis in the application root directory.
Step 2: Configure the Python application
- Go to Websites & Domains and click the Python icon on your domain card.
- Click Enable Python.
- Set the Python Version to match the version your app was built with.
- Set the Application Root to the directory containing your app files (e.g.
/httpdocs). - Set the Application Startup File:
- For Flask:
app.py(or whatever file contains your Flask app) - For Django:
passenger_wsgi.py(see Step 3)
- For Flask:
- Set Application Mode to Production when your app is ready to go live.
Step 3: Create passenger_wsgi.py (Django only)
Django applications need a bridge file for Phusion Passenger. Create a file called passenger_wsgi.py in your application root with the following content:
import sys, os
sys.path.append(os.getcwd())
from myproject.wsgi import application
Replace myproject with your actual Django project folder name.
Step 4: Install dependencies
- In the Python application settings, click Run Pip Install. Plesk creates a virtual environment and installs everything from
requirements.txt. - Alternatively, SSH into your server and run:
cd /var/www/vhosts/yourdomain.com/httpdocs && pip install -r requirements.txt
Step 5: Run database migrations (Django)
In the Python settings, use Run Script with:
- Script name:
manage.py - Arguments:
migrate
Repeat with collectstatic to gather static files.
Step 6: Restart and verify
- Click Restart Application in the Python settings.
- Visit your domain in a browser to verify the app is running.
Troubleshooting
- Phusion Passenger error page: Check the Logs tab on your domain card for Python traceback errors.
- Module not found errors: Run Pip Install again or verify your
requirements.txtis complete. - Static files not loading (Django): Make sure you ran
collectstaticand yourSTATIC_ROOTis configured in settings. - App not restarting: Create a
tmpdirectory in your app root and runtouch tmp/restart.txtvia SSH to force a restart.