User Tools

Site Tools


doc:appunti:linux:sa:libapache2-mod-python

This is an old revision of the document!


mod_python per Apache

Si installa il pacchetto Debian libapache2-mod-python, quindi in un VirtualHost si abilita l'esecuzione del Python:

    <Location />
        SetHandler mod_python
        PythonPath "sys.path+['/etc/apache2/']"
        #PythonHandler mod_python.testhandler
        PythonHandler mptest
        PythonDebug On
    </Location>

Con SetHandler si dice di passare ogni richiesta al Python, se si desidera passare solo le richieste di file .py si può usare la direttiva AddHandler. L'handler predefinito è contenuto nel file /etc/apache2/mptest.py, il cui percorso è stato aggiunto alla sys.path con la direttiva PythonPath. Eventuali errory Python saranno mostrati nel browser grazie alla direttiva PythonDebug.

Per verificare le impostazioni si può attivare provvisoriamente l'handler mod_python.testhandler.

Questo è un esempio di handler mptest.py:

from mod_python import apache
 
def handler(req):
    req.content_type = 'text/plain'
    req.write("Hello World!")
    return apache.OK
doc/appunti/linux/sa/libapache2-mod-python.1457039837.txt.gz · Last modified: 2016/03/03 22:17 by niccolo