Apache and Python and Ubuntu

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • msuemnig@jjhill.org

    #1

    Apache and Python and Ubuntu

    I've create an Ubuntu Linux box, which comes pre-installed with Python
    (I've added the libapache2-mod-python throught the app manager). I've
    created .cgi and .py simple programs in the www root of apache.

    The problem is the programs just dump the contents to the browser in
    plain text. Or, in the case of the .py files, I am prompted to
    download the .py file. How can I get apache to recognize that it
    should execute the .cgi script?

    Is there any special thing I need to do to apache to get it to know
    that the python interpreter should be used for all .cgi files?

    Thanx all for your help in advance!
    pen

  • grahamd@dscpl.com.au

    #2
    Re: Apache and Python and Ubuntu


    msuem...@jjhill .org wrote:[color=blue]
    > I've create an Ubuntu Linux box, which comes pre-installed with Python
    > (I've added the libapache2-mod-python throught the app manager). I've
    > created .cgi and .py simple programs in the www root of apache.
    >
    > The problem is the programs just dump the contents to the browser in
    > plain text. Or, in the case of the .py files, I am prompted to
    > download the .py file. How can I get apache to recognize that it
    > should execute the .cgi script?
    >
    > Is there any special thing I need to do to apache to get it to know
    > that the python interpreter should be used for all .cgi files?[/color]

    You do not need mod_python if you want to use Python in traditional
    CGI scripts. Simply follow the Apache instructions for setting up
    CGI scripts and ignore mod_python all together.

    If you really did want to use mod_python, consider reading:



    It provides more detailed instructions on getting a first test handler
    running.

    Graham

    Comment

    • Jorge Godoy

      #3
      Re: Apache and Python and Ubuntu

      msuemnig@jjhill .org writes:
      [color=blue]
      > The problem is the programs just dump the contents to the browser in
      > plain text. Or, in the case of the .py files, I am prompted to
      > download the .py file. How can I get apache to recognize that it
      > should execute the .cgi script?
      >
      > Is there any special thing I need to do to apache to get it to know
      > that the python interpreter should be used for all .cgi files?[/color]

      You should configure your Apache:

      - http://httpd.apache.org/docs/2.2/
      - http://httpd.apache.org/docs/2.2/howto/cgi.html


      --
      Jorge Godoy <godoy@ieee.org >

      "Quidquid latine dictum sit, altum sonatur."
      - Qualquer coisa dita em latim soa profundo.
      - Anything said in Latin sounds smart.

      Comment

      • msuemnig@jjhill.org

        #4
        Re: Apache and Python and Ubuntu

        Thanx a lot for your input and advice. I went through the
        documentation on httpd.apache.or g/docs/2.2/howto/cgi.html and added the
        following:
        AddModule cgi-script .cgi .py
        <DIRECTORY /var/www/>
        Options +ExecCGI
        </DIRECTORY>

        It now gives me a 403 forbidden. When I check the error logs, it still
        says that Options ExecCGI is not turned on in /var/www/

        Is there a special place inside of apache2.conf I'm supposed to have
        the <Directory..> tag? and/or AddModule line?

        I also double checked to make sure owner/group/other all have execute
        and it does.

        Comment

        • Paul Boddie

          #5
          Re: Apache and Python and Ubuntu

          msuemnig@jjhill .org wrote:[color=blue]
          > Thanx a lot for your input and advice. I went through the
          > documentation on httpd.apache.or g/docs/2.2/howto/cgi.html and added the
          > following:
          > AddModule cgi-script .cgi .py
          > <DIRECTORY /var/www/>
          > Options +ExecCGI
          > </DIRECTORY>[/color]

          Does Apache actually support "DIRECTORY" as opposed to "Directory" ? The
          configuration file isn't "old-school HTML", and I'd recommend following
          the conventions in the documentation as closely as possible until you
          have something working.
          [color=blue]
          > It now gives me a 403 forbidden. When I check the error logs, it still
          > says that Options ExecCGI is not turned on in /var/www/
          >
          > Is there a special place inside of apache2.conf I'm supposed to have
          > the <Directory..> tag? and/or AddModule line?[/color]

          I would imagine that you're not supposed to be editing apache2.conf
          unless the changes are fairly important and change the global
          configuration of the server. On Debian/Ubuntu, you're supposed to add
          files to the /etc/apache2/sites-available directory and then use the
          a2ensite program to enable the new site.
          [color=blue]
          > I also double checked to make sure owner/group/other all have execute
          > and it does.[/color]

          You could also investigate the ScriptAlias directive to permit access
          to a particular file or directory as a CGI program (or a collection of
          CGI programs) at (or under) a specified location; I've found that to be
          much more convenient.

          Paul

          Comment

          • msuemnig@jjhill.org

            #6
            Re: Apache and Python and Ubuntu

            Paul,

            thank you so much for your information and help! That was exactly the
            issue.

            I added ExecCGI and addHandler cgi-script .cgi to the
            sites-available/default file and bounce the service and it's working!

            Thanx again!

            Comment

            Working...