mod_python unter apache2 installieren



  • Hallo,
    ich verzweifel gerade an der Installation von mod_python unter apache2. Ich hab libapache2-mod-python 3.1.3 installiert (Ubuntu Linux) und apache2 2.0.53. Ich bin nach http://www.modpython.org/live/current/doc-html/inst-testing.html vorgegangen.

    In /etc/apache2/apache2.conf habe ich folgendes eingetragen

    <IfModule !mod_python.c>
        LoadModule python_module    extramodules/mod_python.so
    </IfModule>
    
    <Directory /var/www/python>
        AddHandler mod_python .py
        PythonHandler mptest
        PythonDebug On
    </Directory>
    

    Aber wenn ich nun localhost/python/mptest.py aufrufe, dann fragt mich der firefox, ob ich die Datei mptest.py speichern will. Die gespeicherte Datei enthält dann die Ausgabe des Skripts. Wie kann ich dafür sorgen, dass der firefox dies als text/html oder text/plain anerkennt?

    Andere Python Dateien werden gar nicht interpretiert. Wie kann ich mod_python nun einrichten, dass einfach alle Dateien mit .py-Endung als Python Skripte interpretiert werden?

    Im Zweifelsfall muss ich wohl die CGI Version installieren 😞



  • wie schon gesagt: ich musste für solche module noch eine location angeben
    sprich: einen "ordner" (wirklich per namen), in denen die skripte liegen

    beispiel:

    LoadModule lisp_module modules/mod_lisp.dll
      LoadModule hello_module modules/mod_hello.dll
    
    ....
    ....
    
      <Location /asp>
            SetHandler lisp-handler
        </Location>
    
    <Location /hello_demo>
            SetHandler hello
        </Location>
    

    also gibt es bei mir einen ordner asp im "www", in dem die lisp skripte interpretiert werden und einen hello_demo, in dem ich meine skripte für das selbstgeschriebene modul ablege.

    klingt mystisch. ging irgendwie nicht anders.

    vielleicht hilfts..



  • das sieht ganz "gescheit" aus:

    <IfDefine PYTHON>
      <IfModule !mod_python.c>
        LoadModule python_module    extramodules/mod_python.so
      </IfModule>
    </IfDefine>
    
    <IfModule mod_python.c>
    #
    # Mod_python is a module that embeds the Python language interpreter
    # within the server, allowing Apache handlers to be written in Python.
    #
    
    # This will cause files beneath /home/httpd/htdocs with the extension .spam
    # to be handled by the Python script /home/httpd/htdocs/eggs.py
    #
    #<Directory /home/httpd/htdocs>
    #    <IfModule mod_mime.c>
    #    AddHandler python-program .spam
    #    </IfModule>
    #    PythonHandler eggs
    #</Directory>
    
    # This will cause all requests to the /python heirachy of your
    # webserver to be handled by the python script /path/to/myhandler.py
    #
    #<Location /python>
    #    SetHandler python-program
    #    PythonPath "sys.path + ['/path/to']"
    #    PythonHandler myhandler
    #</Location>
    
    # This will cause all requests to the /python heirachy of your
    # webserver to be handled by mod_python's Publisher handler
    #
    #<Location /python>
    #    SetHandler python-program
    #    PythonHandler mod_python.publisher
    #</Location>
    
    </IfModule>
    

    aus:
    http://www.gtlib.cc.gatech.edu/pub/gentoo/gentoo-x86-portage/dev-python/mod_python/files/16_mod_python.conf



  • Ich hab Directory jetzt in Location umgeändert (also <Location /python>). Nun erhalte ich beim Aufruf von mptest.py folgenden Fehler:

    Mod_python error: "PythonHandler mptest"
    
    Traceback (most recent call last):
    
      File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 287, in HandlerDispatch
        log=debug)
    
      File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 454, in import_module
        f, p, d = imp.find_module(parts[i], path)
    
    ImportError: No module named mptest
    

    Ach ja und andere Scripte bietet der mir immer noch zum download an.



  • So hab das Problem nun lösen können.

    <Directory <pfad>>
    	AddHandler python-program .py
            PythonHandler cgi0
            PythonDebug On
            Order allow,deny
    	Allow from all
    </Directory>
    

    funktioniert jetzt


Anmelden zum Antworten