This article describes how to install a Python™ WSGI web application on the command line.
Python WSGI is a standardized web interface that runs Python applications.
If you need more information, please read the Python WSGI documentation.
Install a Python application
Before you start, make sure your hosting provider has installed the following EasyApache 4 packages on your server:
mod-passengerThis module disables Apache’s mod_userdir module.
mod-envWe also recommend that your hosting provider install the module
Also, your hosting provider must install the following packages:
- python-flask (or another framework)
We strongly recommend that you use a framework with Python WSGI.
The package name depends on your version of Python.
Install the application
Please follow these steps to install an application:
- Log in to the server via SSH as a cPanel user.
- Create an application directory relative to your home directory. Run the following command, where directoryname is the application directory:
- Change to the application’s directory. Run the following command, where directoryname is the application directory:
- Copy this application to your server.
- Create a passenger_wsgi.py file. Where pythonapp is your Python application and MyApp is the application function:
echo "from pythonapp import MyApp as application" > passenger_wsgi.py
- Install application dependencies. Create a pip requirements.txt file, after that run the following command:
pip install –user -r requirements.txtNote: Any dependencies also can install in the Ensure Dependencies section of cPanel’s Application Manager interface (cPanel » Home » Software » Application Manager).Warning:
- The version requirements of your dependency must match your version of Python. For example, a dependency that requires Python 2 or earlier will not work in an application that you run with Python 3.
- Some dependencies will change what your application requires to work. For example, Flask’s render_template dependency requires that you keep your index.html file in a templates folder.
Test the application
After installing the application, make sure that it is active.
- Run this command:
The output may resemble the following example:
- Open another terminal window and log in to the server via SSH as the same cPanel user.
- Run this command:
The output will be similar to the following example:
Register the application
Register the application after installing it. For this, use cPanel’s Application Manager interface (cPanel » Home » Software » Application Manager).
Then you can access the application in a web browser with the following URL:
Restart the application
To restart the application after editing it, create the restart.txt touch file. Create this file in the /tmp directory of the application. This file directs Phusion Passenger® to restart the application after changing it. This action applies your changes to the application