Python LSAPI Installation⇑
- Download the module: Python LSAPI (WSGI LSAPI) can be downloaded here.
-
Run the following commands to compile the LSWSGI executable: (It has been assumed that
wsgi-lsapi-X.X
was downloaded to/usr/local/lsws/
)
cd /usr/local/lsws/wsgi-lsapi-1.1
python ./configure.py
make
-
Move the file
lswsgi
to/usr/local/lsws/fcgi-bin/
. This directory is where all your LSAPI executables go.
Python LSAPI Administration⇑
Using Apache Configurations
With the Python LSAPI module, LiteSpeed Web Server can automatically detect and utilize settings for existing Python applications using mod_wsgi. No change should be necessary to bring in an application from Apache.
Using Native LiteSpeed Configurations
Python applications can be set up with LSAPI using the same methods used with any other LSAPI application — by setting up an external application and script handler in the WebAdmin console.
Setting up an external application:
- Go to the External App tab (WebAdmin console > Configuration > External App) and add an external application. (This can be done at the server or virtual host level.)
- Set Type to "LSAPI App"
- Give your external application a name and a socket. Most importantly, for the Command setting, specify the location of the
lswsgi
executable: "/usr/local/lsws/fcgi-bin/lswsgi". (You also have to pick values for Max Connections, Initial Request Timeout, and Retry Timeout.)
Setting up a script handler:
A WSGI script handler will tell LSWS to send
.wsgi
scripts to the LSWSGI application.- Go to the Script Handler tab (WebAdmin console > Configuration > Script Handler) and click Add. (This, also, can be done at the server or virtual host level.)
- Set Suffix to ".wsgi" (the suffix of my WSGI Python apps). Set Handler Type to "LiteSpeed SAPI". For Handler Name, choose the LSWSGI external application just created.
Graceful restart to apply changes.
suEXEC
suEXEC is usually preferred in the shared hosting environment. LSWS will start a Python WSGI application in suEXEC mode (running as the same user ID as the site owner) when the PHP suEXEC setting is enabled (WebAdmin console > Configuration > General). It will follow the same security model used for PHP. For each account, the maximum concurrent processes follows the PHP suEXEC Max Conn setting (WebAdmin console > Configuration > General).
The default settings for the Python LSAPI, though, only set up suEXEC for for applications with the suffix .wsgi
. If you need Python LSAPI to run scripts with other suffixes in suEXEC, there are two ways to set this up:
- For Apache configurations: Create a script handler for the suffix
.wsgi
, then add the directiveAddType application/x-httpd-wsgi .yoursuffix
to this script handler. - For native LiteSpeed configurations: Add a comma and your suffix after ".wsgi" in step 2ii above. (Example: ".wsgi, .py") ".wsgi" must be the first suffix in order for this to work.
Python LSAPI Configuration⇑
Using Apache Settings
With the Python module, LSWS will automatically detect and use Apache mod_wsgi settings. The Python LSAPI module is compatible with the following mod_wsgi directives:
WSGIApplicationGroup
WSGICallableObject
WSGIScriptReloading
WSGIScriptAlias
WSGIScriptAliasMatch
Using LiteSpeed Native Settings
External Application Settings
LSAPI external application settings are explained in the LiteSpeed Web Server documentation. You can achieve the results of the Apache directives listed above by using script handlers and contexts in LSWS. These settings are also explained in the LSWS documentation.
Environment Variables
Python LSAPI applications can be further configured using the environment variables listed below:
LSAPI_CHILDREN (default: 0) |
LSAPI allows a variety of setups. Two of these setups, Worker and ProcessGroup can be set using this environment variable. (Note: In previous versions of this documentation, Worker was referred to as "server managed mode" and ProcessGroup referred to as "self managed mode".) Setting Setting |
LSAPI_AVOID_FORK (default: 0) |
When set to 0, the internal process manager will not try to avoid forking new processes. To save system resources, it will stop processes when they finish and only start child processes when they are needed. This is often preferred in shared hosting. When set to 1, the internal process manager will try to avoid frequently stopping and starting child processes. This might be preferred in a dedicated hosting environment because it may be faster to recycle existing processes, even if it means running processes when they are unused sometimes. |
LSAPI_EXTRA_CHILDREN (default: 1/3 of LSAPI_CHILDREN or 0) |
In ProcessGroup mode, |
LSAPI_MAX_REQS (default: 10000) |
In ProcessGroup mode, this controls how many requests each child process will handle before it exits automatically. This parameter can help reduce memory usage by leaky Python functions. |
LSAPI_MAX_IDLE (default: 300 seconds) |
In ProcessGroup mode, |
LSAPI_MAX_IDLE_CHILDREN (default: 1/3 of LSAPI_CHILDREN or LSAPI_CHILDREN) |
In ProcessGroup mode, |
LSAPI_MAX_PROCESS_TIME (default: 3600 seconds) |
In ProcessGroup mode, |
LSAPI_PGRP_MAX_IDLE (default: FOREVER ) |
In ProcessGroup mode, |
LSAPI_PPID_NO_CHECK |
By default, an LSAPI external application will exit automatically if the parent process dies. This is to reduce orphan processes when the web server is restarted. However, it may be desirable to disable this feature in situations such as when an LSAPI process was started manually from the command line. Adding the |
LSAPI_ALLOW_CORE_DUMP |
By default, an LSAPI application will not leave a core dump file when it crashes. If you want to have LSAPI dump a core file, you should add this environment variable and set to 1. If set, core files will be created under the current working directory, generally the directory of the Python script that crashed. To turn off this setting, remove the environment variable completely. |