/
/
Flask installation in ispmanager 6

Flask installation in ispmanager 6

Why?

Setting up Flask framework on a website in ispmanager 6.

Instructions

In the Settings menu, navigate to Software configuration. Install Python.

 

In the user's settings, enable Can use Python and Shell access options. Click Save.

 

Navigate to Sites and create a new website and choose the Extended settings while setting up the website. Select the Handler with the option Path to server and Connection method. The server.py file and the Port are given as an example. Click Create.

 

In the site's settings, find the port number. Use this port number for server arguments. For the instance, runserver 20000. Click Save.

 

Open the site's directory in the Website files or File manager menu. Create the file passenger_wsgi.py.

 

Clean up the server.py file and add following code into the file:

from flask import Flask
application = Flask(__name__)
@application.route("/")
def hello():
   return "<h1 style='color:blue'>Hello There!</h1>"
if __name__ == "__main__":
   application.run(host='0.0.0.0', port=20000)

Set your own values for host and port parameters. Default values are 0.0.0.0 and 20000 respectively.

 

Then edit the file passenger_wsgi.py:

import sys
import os
INTERP = os.path.expanduser("/var/www/<user>/data/www/<website>/.venv/bin/<python>")
if sys.executable != INTERP:
   os.execl(INTERP, INTERP, *sys.argv)
sys.path.append(os.getcwd())
from hello import application

In the os.path.expanduser parameter set your own values for <user> (owner of the website), <website> (name of the website) and <python> (Python interpreter version, e.g. python3.12).

You can see the path to Python interpreter in the site's settings.

 

Navigate to the Browsing Python packages in the right side menu and install Flask.

 

The dependencies are set automatically. See details in the file requirements.txt.

You can also create new in the file requirements.txt and click Pip install on the right side menu.

As an example, «python-dotenv» and «watchdog» will not be installed automatically. But Flask will detect and use them.

Now the Flask is available at your website!

In this article