Python

Sample Apache fastcgi config (alternative Common lab).

  • python hello.py (/www/pythonlab/htdocs/studentx/hello.py)
  • python fastcgi module (/www/pythonlab/htdocs/master/fastcgi.py)
  • Apache config (/www/pythonlab/conf/httpd.conf)
  • fastcgi config (/www/pythonlab/conf/fastcgi.conf)
====
python hello.py (/www/pythonlab/htdocs/studentx/hello.py)
====
[adc@oc7083008330 conf]$ cat ../master/hello.py 
# -------
# lesson 1 - hello world
# -------
print("Hello World!")

====
python fastcgi module (/www/pythonlab/htdocs/master/fastcgi.py)
====
[adc@oc7083008330 conf]$ cat ../master/fastcgi.py 
#!/QOpenSys/usr/bin/python3
# -------
# Flip flop PASE fastcgi module.
# http://myibmi:47042/studentx/hello.py
#   All print output hello.py captured,
#   output then sent to web browser.
# -------
import os
import sys
import flipflop
from flipflop import WSGIServer
from io import StringIO
def app(environ, start_response):
    """Simplest possible application object""" 
    status = '200 OK'
    response_headers = [('Content-type','text/html;charset=utf-8')]
    start_response(status, response_headers)
    fn = environ['DOCUMENT_ROOT'] + environ['SCRIPT_NAME']
    if os.path.isfile(fn):
      # capture lesson.py print  ...
      old_stdout = sys.stdout
      sys.stdout = mystdout = StringIO()
      exec(open(fn).read())
      sys.stdout = old_stdout
      # send capture print to web
      return [mystdout.getvalue()]
    else:
      return['File not found ' + fn]
    # return [str(environ)]
WSGIServer(app).run()

=======
Apache config (/www/pythonlab/conf/httpd.conf)
=======
[adc@oc7083008330 conf]$ cat httpd.conf 
# Apache Default server configuration
LoadModule proxy_module /QSYS.LIB/QHTTPSVR.LIB/QZSRCORE.SRVPGM
LoadModule proxy_http_module /QSYS.LIB/QHTTPSVR.LIB/QZSRCORE.SRVPGM
LoadModule proxy_connect_module /QSYS.LIB/QHTTPSVR.LIB/QZSRCORE.SRVPGM
LoadModule proxy_ftp_module /QSYS.LIB/QHTTPSVR.LIB/QZSRCORE.SRVPGM
LoadModule proxy_balancer_module /QSYS.LIB/QHTTPSVR.LIB/QZSRCORE.SRVPGM
LoadModule zend_enabler_module /QSYS.LIB/QHTTPSVR.LIB/QZFAST.SRVPGM

ProxyPreserveHost On
HotBackup Off
TimeOut 30000
KeepAlive Off
AddLanguage en .en
DefaultFsCCSID 37
CGIJobCCSID 37

Listen *:47042

DocumentRoot /www/pythonlab/htdocs

# FastCGIServerID ADC
DirectoryIndex index.html fastcgi.py

<Directory />       
  Order Deny,Allow 
  Deny From all     
</Directory>     

<Directory /www/pythonlab/htdocs>
  order allow,deny
  allow from all
</Directory>

<Directory /www/pythonlab/htdocs/master>
  #AuthType Basic
  #AuthName "IBMi OS User Profile"
  #Require valid-user
  #PasswdFile %%SYSTEM%%
  #UserID ADC
  order allow,deny
  allow from all
  AddType application/x-httpd-py0 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student1>
  order allow,deny
  allow from all
  AddType application/x-httpd-py1 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student2>
  order allow,deny
  allow from all
  AddType application/x-httpd-py2 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student3>
  order allow,deny
  allow from all
  AddType application/x-httpd-py3 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student4>
  order allow,deny
  allow from all
  AddType application/x-httpd-py4 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student5>
  order allow,deny
  allow from all
  AddType application/x-httpd-py5 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student6>
  order allow,deny
  allow from all
  AddType application/x-httpd-py6 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student7>
  order allow,deny
  allow from all
  AddType application/x-httpd-py7 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student8>
  order allow,deny
  allow from all
  AddType application/x-httpd-py8 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student9>
  order allow,deny
  allow from all
  AddType application/x-httpd-py9 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student10>
  order allow,deny
  allow from all
  AddType application/x-httpd-py10 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student11>
  order allow,deny
  allow from all
  AddType application/x-httpd-py11 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student12>
  order allow,deny
  allow from all
  AddType application/x-httpd-py12 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student13>
  order allow,deny
  allow from all
  AddType application/x-httpd-py13 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student14>
  order allow,deny
  allow from all
  AddType application/x-httpd-py14 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student15>
  order allow,deny
  allow from all
  AddType application/x-httpd-py15 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student16>
  order allow,deny
  allow from all
  AddType application/x-httpd-py16 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student17>
  order allow,deny
  allow from all
  AddType application/x-httpd-py17 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student18>
  order allow,deny
  allow from all
  AddType application/x-httpd-py18 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student19>
  order allow,deny
  allow from all
  AddType application/x-httpd-py19 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student20>
  order allow,deny
  allow from all
  AddType application/x-httpd-py20 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student21>
  order allow,deny
  allow from all
  AddType application/x-httpd-py21 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student22>
  order allow,deny
  allow from all
  AddType application/x-httpd-py22 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student23>
  order allow,deny
  allow from all
  AddType application/x-httpd-py23 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student24>
  order allow,deny
  allow from all
  AddType application/x-httpd-py24 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student25>
  order allow,deny
  allow from all
  AddType application/x-httpd-py25 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student26>
  order allow,deny
  allow from all
  AddType application/x-httpd-py26 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student27>
  order allow,deny
  allow from all
  AddType application/x-httpd-py27 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student28>
  order allow,deny
  allow from all
  AddType application/x-httpd-py28 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student29>
  order allow,deny
  allow from all
  AddType application/x-httpd-py29 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student30>
  order allow,deny
  allow from all
  AddType application/x-httpd-py30 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student31>
  order allow,deny
  allow from all
  AddType application/x-httpd-py31 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student32>
  order allow,deny
  allow from all
  AddType application/x-httpd-py32 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student33>
  order allow,deny
  allow from all
  AddType application/x-httpd-py33 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student34>
  order allow,deny
  allow from all
  AddType application/x-httpd-py34 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student35>
  order allow,deny
  allow from all
  AddType application/x-httpd-py35 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student36>
  order allow,deny
  allow from all
  AddType application/x-httpd-py36 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student37>
  order allow,deny
  allow from all
  AddType application/x-httpd-py37 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student38>
  order allow,deny
  allow from all
  AddType application/x-httpd-py38 .py
  AddHandler fastcgi-script .py
</Directory>

<Directory /www/pythonlab/htdocs/student39>
  order allow,deny
  allow from all
  AddType application/x-httpd-py39 .py
  AddHandler fastcgi-script .py
</Directory>

=====
fastcgi config (/www/pythonlab/conf/fastcgi.conf)
=====
[adc@oc7083008330 conf]$ cat fastcgi.conf 
; python flipflop fastcgi server
Server type="application/x-httpd-py0" CommandLine="/www/pythonlab/htdocs/master/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py1" CommandLine="/www/pythonlab/htdocs/student1/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py2" CommandLine="/www/pythonlab/htdocs/student2/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py3" CommandLine="/www/pythonlab/htdocs/student3/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py4" CommandLine="/www/pythonlab/htdocs/student4/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py5" CommandLine="/www/pythonlab/htdocs/student5/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py6" CommandLine="/www/pythonlab/htdocs/student6/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py7" CommandLine="/www/pythonlab/htdocs/student7/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py8" CommandLine="/www/pythonlab/htdocs/student8/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py9" CommandLine="/www/pythonlab/htdocs/student9/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py10" CommandLine="/www/pythonlab/htdocs/student10/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py11" CommandLine="/www/pythonlab/htdocs/student11/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py12" CommandLine="/www/pythonlab/htdocs/student12/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py13" CommandLine="/www/pythonlab/htdocs/student13/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py14" CommandLine="/www/pythonlab/htdocs/student14/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py15" CommandLine="/www/pythonlab/htdocs/student15/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py16" CommandLine="/www/pythonlab/htdocs/student16/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py17" CommandLine="/www/pythonlab/htdocs/student17/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py18" CommandLine="/www/pythonlab/htdocs/student18/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py19" CommandLine="/www/pythonlab/htdocs/student19/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py20" CommandLine="/www/pythonlab/htdocs/student20/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py21" CommandLine="/www/pythonlab/htdocs/student21/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py22" CommandLine="/www/pythonlab/htdocs/student22/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py23" CommandLine="/www/pythonlab/htdocs/student23/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py24" CommandLine="/www/pythonlab/htdocs/student24/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py25" CommandLine="/www/pythonlab/htdocs/student25/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py26" CommandLine="/www/pythonlab/htdocs/student26/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py27" CommandLine="/www/pythonlab/htdocs/student27/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py28" CommandLine="/www/pythonlab/htdocs/student28/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py29" CommandLine="/www/pythonlab/htdocs/student29/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py30" CommandLine="/www/pythonlab/htdocs/student30/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py31" CommandLine="/www/pythonlab/htdocs/student31/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py32" CommandLine="/www/pythonlab/htdocs/student32/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py33" CommandLine="/www/pythonlab/htdocs/student33/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py34" CommandLine="/www/pythonlab/htdocs/student34/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py35" CommandLine="/www/pythonlab/htdocs/student35/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py36" CommandLine="/www/pythonlab/htdocs/student36/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py37" CommandLine="/www/pythonlab/htdocs/student37/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py38" CommandLine="/www/pythonlab/htdocs/student38/fastcgi.py" StartProcesses="1"
Server type="application/x-httpd-py39" CommandLine="/www/pythonlab/htdocs/student39/fastcgi.py" StartProcesses="1"

; Where to place socket files
IpcDir /www/pythonlab/logs
IpcPublic *RWX
[adc@oc7083008330 conf]$