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:python:lswsgi [2013/08/07 18:23]
Michael
— (current)
Line 1: Line 1:
-====== 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...) is an API for .... It is important to note that, while almost all Python applications in wide use on the Internet are WSGI-compatible,​ Python applications are not necessarily WSGI-compatible. 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. 
- 
-===== Compile Python with LSWSGI ===== 
- 
-==== Download the WSGI LSAPI module ==== 
- 
-The module can be downloaded from our site [[http://​www.litespeedtech.com/​packages/​lsapi/​wsgi-lsapi-1.0.tgz|here]]. 
- 
-==== Compile Python with the module and prepare the executable ==== 
- 
-I have downloaded the module to my server root ''/​usr/​local/​lsws''​. To recompile Python, I go into the module directory and run the following commands: 
- 
-  cd /​usr/​local/​lsws/​wsgi-lsapi-1.0 
-  python ./​configure.py 
-  make 
- 
-I then copy the file ''​lswsgi''​ to ''/​usr/​local/​lsws/​fcgi-bin/''​. (This directory is where all your LSAPI executables go.) 
- 
-  cp lswsgi /​usr/​local/​lsws/​fcgi-bin/​ 
- 
-Now my LSWSGI executable is ready for LiteSpeed Web Server. 
- 
-===== Set up an external application and script handler ===== 
- 
-==== Setting up the external application ==== 
- 
-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.) 
- 
-{{litespeed_wiki:​python:​python_add_ext_app.png?​600}} 
- 
-I make the type ''​LSAPI App''​. 
- 
- 
- 
-I give it a name and a socket. Most importantly,​ for the Command setting, I specify the location of my lswsgi executable: ''/​usr/​local/​lsws/​fcgi-bin/​lswsgi''​. (You also have to pick values for Max Connections,​ Initial Rquest Timeout, and Retry Timeout.) 
- 
- 
- 
- 
-Now I have an LSWSGI external application. ​ 
- 
- 
- 
- 
-==== 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.) 
- 
- 
- 
-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 I just created. (If you want scripts other than ''​.wsgi''​ to use Python, you can make extra script handlers to handle those scripts.) 
- 
- 
- 
- 
- 
-Now my LSWS can handle ''​.wsgi''​ scripts and knows where to send them. 
- 
-==== Graceful restart to apply changes ==== 
- 
-===== Test ===== 
- 
-To test this I'm putting the simple hello world script below: 
- 
-<code python> 
-def application(environ,​ start_response):​ 
-  start_response('​200 OK', [('​Content-Type',​ '​text/​plain'​)]) 
-  return ['​Hello World!\n'​] 
-</​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. 
- 
-Now, when I point my browser to ''​localhost:​8088/​hello.wsgi'',​ I see the correct output displayed. It works! 
  
  • Admin
  • Last modified: 2013/08/07 18:23
  • by Michael