Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
litespeed_wiki:other-ext-apps:python-lsapi [2018/03/29 13:57]
Tihomir [Setting up the external application]
litespeed_wiki:other-ext-apps:python-lsapi [2020/08/14 18:38] (current)
Jackson Zhang [Setting up the External Application]
Line 1: Line 1:
 ====== Running a Python Application with LSAPI ====== ====== Running a Python Application with LSAPI ======
  
-LiteSpeed SAPI is the easiest and fastest way to run web applications with LiteSpeed Web Server. ​Recently, we've introduced ​LSAPI support ​for Python applications through WSGI. WSGI (Web Server Gateway Interface) is a low-level interface between web servers and web applications. It allows Python applications designed for WSGI to be used in a variety of settings. It is important to note that, while most Python applications are WSGI-compatible,​ not all are.+LiteSpeed SAPI is the easiest and fastest way to run web applications with LiteSpeed Web Server. ​LiteSpeed supports ​LSAPI for Python applications through WSGI. WSGI (Web Server Gateway Interface) is a low-level interface between web servers and web applications. It allows Python applications designed for WSGI to be used in a variety of settings. It is important to note that, while most Python applications are WSGI-compatible,​ not all are.
  
 This wiki will go over how to set up LSWS to run Python applications with LWSGI. This wiki assumes that you already have a working version of Python installed and virtual hosts set up to run it on. This wiki will go over how to set up LSWS to run Python applications with LWSGI. This wiki assumes that you already have a working version of Python installed and virtual hosts set up to run it on.
Line 9: Line 9:
 ==== Download the WSGI LSAPI module ==== ==== Download the WSGI LSAPI module ====
  
-The module can be downloaded from our site [[http://​www.litespeedtech.com/​packages/​lsapi/​wsgi-lsapi-1.1.tgz|here]].+The module can be downloaded from our site [[http://​www.litespeedtech.com/​packages/​lsapi/​wsgi-lsapi-1.6.tgz|here]].
  
-==== Compile Python with the module ​and prepare ​the executable ​====+==== Compile Python with the Module ​and Prepare ​the Executable ​====
  
-I have downloaded ​the module to my server root ''/​usr/​local/​lsws''​. To recompile Python, ​go into the module directory and run the following commands:+Download ​the module to your server root''/​usr/​local/​lsws''​. To recompile Python, go into the module directory and run the following commands:
  
-  cd /​usr/​local/​lsws/​wsgi-lsapi-1.1+  cd /​usr/​local/​lsws/​wsgi-lsapi-1.6
   python ./​configure.py   python ./​configure.py
   make   make
  
-I then copy the file ''​lswsgi''​ to ''/​usr/​local/​lsws/​fcgi-bin/''​. (This directory is where all your LSAPI executables go.)+Copy the file ''​lswsgi''​ to ''/​usr/​local/​lsws/​fcgi-bin/''​. (This directory is where all of your LSAPI executables go.)
  
   cp lswsgi /​usr/​local/​lsws/​fcgi-bin/​   cp lswsgi /​usr/​local/​lsws/​fcgi-bin/​
  
-Now my LSWSGI executable is ready for LiteSpeed Web Server.+Now your LSWSGI executable is ready for LiteSpeed Web Server.
  
-===== Set up an external application ​and script handler ​=====+===== Set up an External Application ​and Script Handler ​=====
  
-==== Setting up the external application ​====+==== Setting up the External Application ​====
  
 This process is the same as with any other LSAPI application,​ except with a different executable and suffix. This process is the same as with any other LSAPI application,​ except with a different executable and suffix.
  
-I 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.)+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.)
  
 {{litespeed_wiki:​python:​python_add_ext_app.png?​700}} {{litespeed_wiki:​python:​python_add_ext_app.png?​700}}
  
-I make the type ''​LSAPI App''​.+Select ​type ''​LSAPI App''​.
  
 {{litespeed_wiki:​python:​python_ext_app_type.png?​700}} {{litespeed_wiki:​python:​python_ext_app_type.png?​700}}
  
-I give it a name and a socket. Most importantly,​ for the Command setting, ​specify the location of my lswsgi executable: ''/​usr/​local/​lsws/​fcgi-bin/​lswsgi''​. (You also have to pick values for Max Connections,​ Initial Request Timeout, and Retry Timeout.)+Give it a name and a socket. Most importantly,​ for the Command setting, specify the location of your lswsgi executable: ''/​usr/​local/​lsws/​fcgi-bin/​lswsgi''​. (You also have to pick values for Max Connections,​ Initial Request Timeout, and Retry Timeout.)
  
 {{litespeed_wiki:​python:​python_ext_app_settings.png?​700}} {{litespeed_wiki:​python:​python_ext_app_settings.png?​700}}
Line 45: Line 45:
 In the Environment field put: In the Environment field put:
  
-LSAPI_CHILDREN=35+  ​LSAPI_CHILDREN=35
  
-For instance put 1.+Set **Instance** to ''​1''​.
  
 +You now have an LSWSGI external application. ​
  
 +{{litespeed_wiki:​python:​python_ext_app_success.png?​700}}
  
-Now I have an LSWSGI external application. ​ +The configuration looks like: 
- +    <​extProcessor>​ 
-{{litespeed_wiki:python:​python_ext_app_success.png?700}}+      <​type>​lsapi</​type>​ 
 +      <​name>​wsgiapp</​name>​ 
 +      <​address>​uds://​tmp/​lshttpd/​lswsgi.sock</​address>​ 
 +      <​maxConns>​35</​maxConns>​ 
 +      <​env>​LSAPI_CHILDREN=35</​env>​ 
 +      <​initTimeout>​60</​initTimeout>​ 
 +      <​retryTimeout>​0</​retryTimeout>​ 
 +      <​respBuffer>​0</​respBuffer>​ 
 +      <​autoStart>​1</​autoStart>​ 
 +      <​path>/​usr/​local/​lsws/​fcgi-bin/​lswsgi</​path>​ 
 +      <​instances>​1</​instances>​ 
 +    </​extProcessor>​
  
-==== Setting up the script handler ​====+==== Setting up the Script Handler ​====
  
-Now I need to create a WSGI script handler to tell LSWS to send ''​.wsgi''​ scripts to my LSWSGI application. ​I 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.)+You'​ll ​need to create a WSGI script handler to tell LSWS to send ''​.wsgi''​ scripts to your 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.)
  
 {{litespeed_wiki:​python:​python_add_script_handler.png?​700}} {{litespeed_wiki:​python:​python_add_script_handler.png?​700}}
  
-I stipulate ​''​wsgi''​ as the suffix of my WSGI Python apps. I pick Handler Type ''​LiteSpeed SAPI''​ and, for Handler Name, choose the LSWSGI external application ​just created. (If you want scripts other than ''​.wsgi''​ to use Python, you can make extra script handlers to handle those scripts.)+Stipulate ​''​wsgi''​ as the suffix of your WSGI Python apps. Pick Handler Type ''​LiteSpeed SAPI''​ and, for **Handler Name**, choose the LSWSGI external application ​you just created. (If you want scripts other than ''​.wsgi''​ to use Python, you can make extra script handlers to handle those scripts.)
  
 {{litespeed_wiki:​python:​python_script_handler_settings.png?​700}} {{litespeed_wiki:​python:​python_script_handler_settings.png?​700}}
  
-Now my LSWS can handle ''​.wsgi''​ scripts and knows where to send them.+Now your LSWS can handle ''​.wsgi''​ scripts and knows where to send them.
  
-==== Graceful ​restart ​to apply changes ​====+==== Graceful ​Restart ​to Apply Changes ​====
  
 ===== Test ===== ===== Test =====
  
-To test this I'm using the simple hello world script below:+To test this, use the simple hello world script below:
  
 <code python> <code python>
Line 79: Line 92:
 </​code>​ </​code>​
  
-I name my file ''​hello.wsgi''​ and save it to ''/​usr/​local/​lsws/​DEFAULT/​html''​. This is the document root for LSWS's default vhost, Example.+Name your file ''​hello.wsgi''​ and save it to ''/​usr/​local/​lsws/​DEFAULT/​html''​. This is the document root for LSWS's default vhost, ​"Example."
  
-Now, when point my browser to ''​localhost:​8088/​hello.wsgi'', ​see the correct output displayed. It works!+Now, when you point your browser to ''​localhost:​8088/​hello.wsgi'', ​you will see the correct output displayed. It works!
  
 {{litespeed_wiki:​python:​python_hello_world_success.png?​700}} {{litespeed_wiki:​python:​python_hello_world_success.png?​700}}
  • Admin
  • Last modified: 2018/03/29 13:57
  • by Tihomir