Ispmanager 6 lite, pro, host documentation

Working with Python

 

 

Python – a general-purpose programming language that can be integrated to run websites and applications.

To add a Python project, follow these steps:

Before importing users with Python, make sure that the target server has all the correct versions of Python installed.

Install Python

Note!
In order to add the ability to install Python to the ispmanager control panel, you must first install Nginx web server. Note that installing Nginx will change the configuration of the web servers. If you have already configured sites in ispmanager using the Nginx+Apache bundle, it is recommended to contact the developer of the sites to clarify the possibility of correct operation after Nginx installation.

To enable:

  1. In the Main menu select Settings.
  2. From the drop-down list select Software configuration.
  3. On the form that opens, select Python from the list and click on Install.

Once the installation is complete, Python will become available as a handler when you create the site.

Enable Python

1. Python is disabled for users by default after installation.

2. To enable, go to Users  Edit.

3. On the Access tab, enable Can use Python.

4. Set the default Python version in Default values tab.

5. Press Save.

Note!
Default Python version can be configured in user templates.

Users with the ability to create Python websites are indicated by a green icon in the Status column.

 

Disable Python


1. Open Users  Edit.

2. On the Access tab, disable Can use Python checkbox.

3. Click Save.

Note!
This feature cannot be disabled if a user has sites that use Python.

Add a Python project

Add your Python project to the created site by doing the following:

  1. In the Main menu select Sites.
  2. Select the required site and click on the Website files button.
  3. On the File Manager form that opens, click Upload.
  4. Select where you want to upload the files from:
    • Local computer file – click on Choose file or move the necessary files to the drag-and-drop area;
    • File URL on remote server:
      • URL – a link to the file to be uploaded, for example, http://example.com/dir/file.html;
      • File name – the name of the file to be saved with in the current directory. If you leave this field blank, the file name will be extracted from the URL.
  5. Specify the required packages in the requirements.txt file.
  6. Click on Back to the list of websites arrow.
  7. Click on ““ and select Installing Python packages.
    Python will install all the specified packages of your project. The installation process is indicated by a gray Python icon in the Parameters column.
  8. After installation is complete, click on the ““ button and select Restart (Python).
    The project will be restarted; the Python icon will turn green, which means the project is working properly.
If you have installed a Python package that requires Web server configuration:
  1. Configure the website by clicking Edit.
  2. Navigate to the Handler section and fill in the fields for Python web server.
  3. After filling in the fields, click on the Save button.
  4. If necessary, configure the installed Python package.

Functional check

To check if it works:

  • If the Unix family OS is installed on the PC, add the following entry to the /etc/hosts file:
    1.1.1.1 example.com
    Where:
    • 1.1.1.1 — is the IP-address of your server;
    • example.com — the website name;
  • If Windows OS is installed on the PC, add the following entry to the C:\windows\system32\drivers\etc\hosts file:
    1.1.1.1 example.com
    Where:
    • 1.1.1.1 — is the IP-address of your server;
    • example.ru — the website name.

Enter the name of the website in your browser to check if it was created correctly.

Configure user

Once Python is installed on the panel, add usage rights to the user under which Python projects will be added, to do this:

  1. In the Main menu select Users.
  2. Select the appropriate user and click on Edit.
  3. On the form that opens, find the Access section.
  4. Enable the Python checkbox and click the Save button.

After saving, a Python icon will be displayed in the user Status column.

Create a website for a project with Python

Now you need to create a site with a Python handler, to do this:

  1. In the Main menu select Sites.
  2. On the form that opens click Create website.
  3. Select the Extended settings tab (for a detailed description of the settings, see Add a website) and fill in the required fields. Below are the important fields when creating a website with a Python project:
    • Main settings section:
      • Domain name – the domain name;
      • Website directory – the path to the website directory that is relative to the owner's home directory;
      • Website aliases – the names of the aliases you want to add to your website (optional field);
      • Handler – select Python;
      • SSL certificate – select an SSL certificate that will be used for this website. You can specify the existing certificate or create a new self-signed certificate;
      • IP address – a list of IP addresses assigned to the website;
      • Website owner – select the website owner;
      • Default website (checkbox) – if the website is marked as default, it will process a request by the domain name which is not registered on this webserver (including requests by IP) to any IP address assigned to this website;
    • Handler (Python) section:
      • Application mode:
        • CGI (Apache + Python) – Python interpreter is called by Apache2, the code will be executed by accessing the file directly;
        • Python web server– some Python packages need server configuration (for example, Django). Configure after the appropriate package is installed:
          • Path to server – the path to the application server file relative to the home directory of the website;
          • Server arguments – list of arguments that will be passed to the server at startup;
          • Connection method (method selection is only available when Python Web Server mode is selected):
            • Port – free unprivileged port will be assigned to the website;
            • Socket file – the website will work via a socket.
        • Python version – select the required Python version.
  4. Click on Create.

On the Sites page, the created website will be added with the Python icon in the Parameters column.

Edit website

1. Change the Python version. You can change the version of Python used for your web project depending on your requirements and compatibility.

2. Change the CGI mode (Apache + Python). Switching between CGI and Python execution modes in Apache environment and vice versa provides flexibility in web application management.

3. Switch the application mode from socket to port and vice versa. The ability to switch between socket and port operation ensures application optimization and efficiency depending on project requirements.

4. Change the handler to PHP, Node.js or disable it. You can change the handler to PHP, Node.js or disable it completely depending on your development needs and preferences.

Disable website

To turn off the site, go to the Sites section and click the Off button. The user will see a stub. If the application was running in server mode, the Python server process will be shut down. It is important to note that no site data is modified or deleted during the shutdown process.

It is important to note that no site data is changed or deleted during the disconnect process.

Enable website

To activate the site, go to the Sites section and click the On button. After that, if the application is running in server mode, the Python process for the site will be started..

Relaunch of website

After making changes to the content of a site, if the application is running in server mode, you must restart the application for the changes to take effect. To restart, select Restart (Python) from the context menu of the desired site. Only the site process will be restarted.

Install packages

The command allows you to install the packages specified in the requirements.txt file located in the root directory of the site. To run the command, click on the desired site and select Install Python packages.

View packages

To view the installed packages for a site, click on the site and select Browsing Python packages. Clicking on the button will open a list of installed dependencies, containing buttons on the toolbar:

  • Install - installs dependencies. Simultaneous installation of multiple dependencies of specified versions is supported;;
  • Delete - removes the selected dependency.

Shell client

Shell client provides the ability to run additional Python, pip and other commands in the terminal. Shellinaboxd is started under the site owner. When the terminal is opened, the following actions are performed:

  • Navigation to the website's home directory;
  • The path to the virtual environment for the selected site is added to the PATHvariable.

To launch the shell client, press the Shell client button in the context menu of the chosen site.