Page tree
Skip to end of metadata
Go to start of metadata

Overview

This document describes how to install a Python WSGI web application on the command line. Python WSGI is a standardized web interface that allows you to run Python applications.

Warning:

  • cPanel Technical Support does not provide assistance with the steps in this document.
  • We are not responsible for any data loss.

Note:

  • We recommend that you perform the steps in this document via the command line as a cPanel user unless otherwise specified.
  • You can also perform these steps in cPanel's Terminal interface (cPanel >> Home >> Advanced >> Terminal).
  • In this document, pythonapp represents the application's name.


For more information, read the Python WSGI documentation.

Install a Python application


Pre-installation settings.

Before you begin, make certain that your hosting provider installed the following EasyApache 4 RPMs on your server:

  • ea-ruby24-mod_passenger

    Note:

    This module disables Apache's mod_userdir module.

  • ea-apache24-mod_env

    Note:

    We also recommend that your hosting provider install the ea-ruby24-ruby-devel module.

Your hosting provider must also install the following packages:

  • python-flask (or another framework)

    Note:

    We strongly recommend that you use a framework with Python WSGI.

  • pip

    Note:

    The package name will vary depending on your python version.




Install the application.

To install an application, perform the following steps:

  1. Log in to the server via SSH as a cPanel user.
  2. Create the application's directory, relative to your home directory. To do this, run the following command, where directoryname represents the application's directory:

    mkdir directoryname
  3. Change to the application's directory. To do this, run the following command, where directoryname represents the application's directory:

    cd directoryname
  4. Copy the application to your server.

  5. Create the passenger_wsgi.py file. In this example, pythonapp represents your python application and MyApp represents an application function:

    echo "from pythonapp import MyApp as application" > passenger_wsgi.py
  6. Install the application's dependencies. To do this, run the following command:

    pip install --user -r requirements.txt

    Note:

    You can also install any dependencies with the Ensure Dependencies function in cPanel's Application Manager interface (cPanel >> Home >> Software >> Application Manager).




Register the application.

After you install the application, register it. To do this, use cPanel's Application Manager  interface (cPanel >> Home >> Software >> Application Manager).

You can then access the application in a web browser with the following url:

http://example.com/pythonapp





Test the application.

After you install the application, we recommend that you confirm that it's active.

  1. Run the following command:

    python pythonapp.py

    The output might resemble the following example:

    <!DOCTYPE html>
    		…
    		  <section class="main">
    		    <h1>Hello world!</h1>
    		    <p>Welcome to the example app.</p>
    		  </section>
    		</body>
    		</html>
  2. Open another terminal window and log in to the server via SSH as the same cPanel user.

  3. Run the following command:

    curl http://localhost:5000 {curl}

    The output will resemble the following example:

    Hello, World!{curl}


Restart the application.

To restart your application after you edit it, create the restart.txt touch file. Create this file in the application's /tmp directory. This file directs Phusion Passenger® to restart the application after you modify it. This action applies your changes to the application.

Important:

Passenger will only restart the application if you touch the restart.txt touch file.


Additional documentation

There is no content with the specified labels

There is no content with the specified labels