Problems with setting up mod_python and Apache

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Dean

    Problems with setting up mod_python and Apache

    Hi
    I have set up httpd.conf according to installation and configuration
    instructions in the mod_python documentation. Yet when I enter the following
    URL http://localhost/test.py all I get is an Apache view of my htdocs
    directory. They if I click on test.py and open file dialog pops up. If I
    give the file a cgi extension and enter the following URL
    http://locathost/test.cgi it runs fine. I just can't figure out what I am
    doing wrong.

    --
    Best Regards
    John
  • Dave Benjamin

    #2
    Re: Problems with setting up mod_python and Apache

    "John Dean" <john@rygannon. com> wrote in message
    news:3f5f6b41$0 $239$fa0fcedb@l ovejoy.zen.co.u k...[color=blue]
    > I have set up httpd.conf according to installation and configuration
    > instructions in the mod_python documentation. Yet when I enter the[/color]
    following[color=blue]
    > URL http://localhost/test.py all I get is an Apache view of my htdocs
    > directory. They if I click on test.py and open file dialog pops up. If I
    > give the file a cgi extension and enter the following URL
    > http://locathost/test.cgi it runs fine. I just can't figure out what I am
    > doing wrong.[/color]

    Sounds like a configuration problem. Can you post the relevant lines from
    your httpd.conf file? Are you trying to write handlers or are you using the
    publisher module?

    Dave


    Comment

    • Dave Benjamin

      #3
      Re: Problems with setting up mod_python and Apache

      Quoting John Dean:[color=blue]
      >
      > Here are the lines in my httpd.conf
      > LoadModule python_module /usr/lib/apache/mod_python.so
      >
      > AddModule mod_python.c
      >
      > <Directory "srv/www/htdocs">
      > .....
      > .....
      >
      > Addhandler python-program .py
      > PythonHandler test[/color]

      Looks right to me. Have you verified that:
      a) you are editing the right httpd.conf (hey, it happens...)
      b) you are affecting the directory you think you are (do other apache
      directives work properly?)

      Once things are working, you may also want to read up on and consider adding
      this:
      PythonInterpPer Directory on
      (hint: otherwise, if you have a test.py in another directory, you will get
      bizarre results)

      Good luck,
      Dave

      PS - Please keep replies to the list for the benefit of others. =)


      Comment

      • John Dean

        #4
        Re: Problems with setting up mod_python and Apache

        Hi Dave

        I have fixed my problem with mod_python. I have one small problem left to
        sort out. If I enter the URL http://localhost Apache just displays the
        contents of the htdocs directory, but if I enter the URL
        http://localhost/test.py everything works as it should. I guess this is
        somewhat off topic since it appears to be an Apache configuration problem so
        I hope you don't mind me asking you for your opinion on c.l.p.

        BTW What I am trying to do is to move away from PHP. Since I use Python as
        my primary scripting language for just about everything where you would use
        a scripting language, it seems to me to be a reasonable idea to use Python
        to provide dyanamic content for the web sites I look after.

        --
        Best Regards
        John

        Comment

        • Steve Holden

          #5
          Re: Problems with setting up mod_python and Apache

          "John Dean" <john@rygannon. com> wrote in message
          news:3f605bee$0 $199$fa0fcedb@l ovejoy.zen.co.u k...[color=blue]
          > Hi Dave
          >
          > I have fixed my problem with mod_python. I have one small problem left to
          > sort out. If I enter the URL http://localhost Apache just displays the
          > contents of the htdocs directory, but if I enter the URL
          > http://localhost/test.py everything works as it should. I guess this is
          > somewhat off topic since it appears to be an Apache configuration problem[/color]
          so[color=blue]
          > I hope you don't mind me asking you for your opinion on c.l.p.
          >[/color]
          Yes, you should condition your server not to give you a directory listing
          when the default documents aren't found - this is big-time information
          leakage, and gives an attacker leverage to start finding vulnerabilities .
          So, beofre you go into production, fix that! The config command you need is
          something like

          DirectoryIndex index.htm index.html index.html.var index.php

          You might want to include index.py there too!

          How did you solve your mod_python problem, by the way?
          [color=blue]
          > BTW What I am trying to do is to move away from PHP. Since I use Python as
          > my primary scripting language for just about everything where you would[/color]
          use[color=blue]
          > a scripting language, it seems to me to be a reasonable idea to use Python
          > to provide dyanamic content for the web sites I look after.
          >[/color]
          Nice. Just try to resist the temptation to replace working PHP with working
          Python - nobody's paying you for that! Translate to Python when upgrading,
          or for new functionality.

          still-from-Yorkshire-ly y'rs - steve
          --
          Steve Holden http://www.holdenweb.com/
          Python Web Programming http://pydish.holdenweb.com/pwp/



          Comment

          • John Dean

            #6
            Re: Problems with setting up mod_python and Apache

            Hi Steve
            Thank you very much for your reply
            Funnily enough I sorted out Apache problem before reading you post. Thanks
            all the same.
            I have mod_python working like a dream. So now in to the hard part. I hope
            you won't mind if I explain. The project I am working on, Rekall, contains
            serveral WSYWIG designers. Two of these designers are of particular interest
            for what I have in mind - the Form and Report Designers. Form and Report
            definitions are stored in XML format either as a file in the file system or
            in a SQL Database. The basic idea is to load a string object with the form
            or report definition. Then using Pythons XML DOM module build a HTML
            document plus the required SQL query string(s). If it is a form then we'll
            will need to build both the HTML data input form and the backend form
            processor. I guess this will need a publisher handler. I expect Reports to
            be a lot easier, but since I am talking about several report output during a
            single session I suppose I will need to get my head around dynamic handlers.
            Now that's frightening

            --
            Best Regards
            John

            Comment

            • Dave Benjamin

              #7
              Re: Problems with setting up mod_python and Apache

              "John Dean" <john@rygannon. com> wrote in message
              news:3f605bee$0 $199$fa0fcedb@l ovejoy.zen.co.u k...[color=blue]
              > I have fixed my problem with mod_python. I have one small problem left to
              > sort out. If I enter the URL http://localhost Apache just displays the
              > contents of the htdocs directory, but if I enter the URL
              > http://localhost/test.py everything works as it should. I guess this is
              > somewhat off topic since it appears to be an Apache configuration problem[/color]
              so[color=blue]
              > I hope you don't mind me asking you for your opinion on c.l.p.[/color]

              Well, I get around this problem by adding "index.py" to the DirectoryIndex
              directive. I use a modified version of the publisher module that comes with
              mod_python that handles this and related special cases. Here's the change
              that I make, if you're interested:

              < if not _req.subprocess _env.has_key("P ATH_INFO"):
              < raise apache.SERVER_R ETURN, apache.HTTP_NOT _FOUND
              <
              < func_path = _req.subprocess _env["PATH_INFO"][1:] # skip fist /
              < func_path = string.replace( func_path, "/", ".")
              ---[color=blue]
              > if _req.subprocess _env.has_key("P ATH_INFO"):
              > func_path = _req.subprocess _env["PATH_INFO"][1:] # skip first /
              > func_path = string.replace( func_path, "/", ".")
              >
              > # If no function is specified, assume "default".
              > if not len(func_path): func_path = "default"
              > else:
              > # If no module is specified either, assume "index".
              > func_path = "default"
              > module_name = "index"[/color]

              This has the result that "index" is always the default module, and "default"
              is the function within that module that gets called if no function is
              explicitly specified on the URL. This works like a charm.
              [color=blue]
              > BTW What I am trying to do is to move away from PHP. Since I use Python as
              > my primary scripting language for just about everything where you would[/color]
              use[color=blue]
              > a scripting language, it seems to me to be a reasonable idea to use Python
              > to provide dyanamic content for the web sites I look after.[/color]

              I did the same thing myself last year, after writing PHP for a couple of
              years. mod_python definitely makes Python a worthy substitute for writing
              Apache modules. The main drawbacks from my experience are the lack of
              built-in session handling and more sophisticated parameter passing (ie.
              PHP's ability to serialize hashes from a form submission). But I'm a little
              dated now, I'm still using mod_python 2 / apache 1.3 ...

              Have fun,
              Dave



              Comment

              Working...