> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Installing and configuring Flask on a Linux shared hosting account

> Discover how to install and configure a Flask app on Linux shared hosting, enabling quick and easy website creation with this Python framework.

Flask is a Python-based framework that enables you to quickly and easily create web applications. This article demonstrates how to install Flask and configure it on a Linux shared hosting account that uses cPanel.

After completing the following procedures, you will have a functioning Flask application on your account that displays a simple web page.

<Warning>
  **Important**

  Although we have tested and run this Flask configuration on shared hosting accounts, it is not supported. You can use this configuration as a starting point for your own Flask projects, but we cannot help you troubleshoot or debug any custom configurations.
</Warning>

## Step 1: Create a Python application in cPanel

The first step is to create a Python application within cPanel that will host the Flask project. To do this, follow these steps:

1. Log in to cPanel.
   > 📘 Note
   >
   > If you do not know how to log in to your cPanel account, please see [this article](/docs/accessing-cpanel).

2. On the **Tools** page, in the **Software** section, click **Setup Python App**:\
   ![](https://static.hosting.com/kb/kb-cpanel-jupiter-software-setup-python-app-icon.png)

3. Click **CREATE APPLICATION**:\
   ![](https://static.hosting.com/kb/kb-cpanel-78-software-python-create-application.png)

   The application form appears:\
   ![](https://static.hosting.com/kb/kb-cpanel-78-software-python-create-application-form.png)

4. In the **Python version** list box, select the Python version you want to use. In this example, we use Python 3.7.3.

5. In the **Application root** text box, type `flaskapp`.

6. In the **Application URL** list box, select the domain, and then type `flaskapp`.

7. Leave the **Application startup file** text box and **Application Entry point** text box blank.

   > 📘 Note
   >
   > When these text boxes are blank, cPanel automatically creates a *passenger\_wsgi.py* startup file and default **application** object for you.

8. In the **Passenger log file** text box, you can optionally specify a log file for the application.

9. In the top right corner of the page, click **CREATE**:\
   ![](https://static.hosting.com/kb/kb-cpanel-78-software-python-create-button.png)

   cPanel creates the application and sets up the Python environment.

10. At the top of the page, next to **Enter to the virtual environment. To enter to virtual environment, run the command**, copy the command. You will need this information in the following procedure.

## Step 2: Configure the Flask project

After you create the Python application in cPanel, you are ready to do the following tasks at the command line:

* Install Flask.

* Configure Passenger to work with the Flask application.

To do this, follow these steps:

1. Log in to your account [using SSH](/docs/using-ssh-secure-shell).

2. Activate the virtual environment, using the command you noted in step 10 above. For example:

   ```bash theme={null}
   source /home/username/virtualenv/flaskapp/3.7/bin/activate && cd /home/username/flaskapp
   ```

   > 🚧 Important
   >
   > The command prompt now starts with **(flaskapp:3.7)** to indicate that you are working in the *flaskapp* virtual environment with Python 3.7. All of the following commands in this article assume that you are working in the Python virtual environment. If you log out of your SSH session (or deactivate the virtual environment by using the **deactivate** command), make sure you reactivate the virtual environment before following any of the steps below.

3. To install Flask, type the following command:

   ```bash theme={null}
   pip install flask
   ```

   > 👍 Tip
   >
   > To verify the version of Flask that is installed, type the following command:
   >
   > ```bash theme={null}
   > flask --version
   > ```

4. Use a text editor to open the *\~/flaskapp/passenger\_wsgi.py* file. Replace the file contents with the following changes:

   ```python theme={null}
   import os

   from flask import Flask, request, render_template, redirect, url_for

   project_root = os.path.dirname(os.path.realpath('__file__'))
   template_path = os.path.join(project_root, 'app/templates')
   static_path = os.path.join(project_root, 'app/static')
   app = Flask(__name__, template_folder=template_path, static_folder=static_path)

   @app.route('/')
   def index():
       return 'Hello from flask'

   application = app
   ```

5. In cPanel, restart the Python application:

   * Log in to cPanel.
     > 📘 Note
     >
     > If you do not know how to log in to your cPanel account, please see [this article](/docs/accessing-cpanel).

   * In the **SOFTWARE** section of the cPanel home screen, click **Setup Python App**.

   * Under **WEB APPLICATIONS**, locate the *flaskapp* application, and then click the **Restart** icon.

6. To test the Flask site, use your browser to go to *[http://www.example.com/flaskapp](http://www.example.com/flaskapp)*, where*example.com* represents your domain name. You should see the **Hello from flask** page.

   > 👍 Tip
   >
   > If the web page does not appear in your browser, try running the *passenger\_wsgi.py* file manually. To do this, type the following command:
   >
   > ```bash theme={null}
   > python ~/flaskapp/passenger_wsgi.py
   > ```
   >
   > There should not be any text output to the console when you run this file. If there are any errors, check the syntax in the file.

## More information

For more information about Flask, please visit [https://flask.palletsprojects.com](https://flask.palletsprojects.com).

## Related articles

* [Using virtualenv and pip](/docs/using-virtualenv-and-pip)

* [Installing and configuring Django on Linux shared hosting](/docs/installing-and-configuring-django-on-linux-shared-hosting)
