Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Problem running python as cgi script

    Hi, I have a virtual dedicated server. And I am trying to run Python as CGI script.
    1. When I run "rpm -qa | grep python" I get following :

    2. I have installed Python3.2 from source in /opt/python3/

    3.Running "which python" gives me "/usr/bin/python"

    4. In my Apcahe's httpd.conf file, i have made following changes :
    i) AddHandler cgi-script .cgi .py .c
    ii) ScriptAlias /cgi-bin/ "/home/asn2012/public_html/cgi-bin/"
    iii) <Directory "/home/w34admin/public_html/cgi-bin/">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
    iv) <Directory /home/*/public_html/cgi-bin>
    Options ExecCGI
    SetHandler cgi-script

    5. There is not issue of uploading file in ASCII mode, since I have created the script on the server itself using vim.

    6. The file I want to run has got "chmod a+x filename"

    Now when I place the file within /home/asn2012/public_html/cgi-bin/ and point my browser to the file, it gives "Internal Server Error".

    When I tail the log file, it gives me

    [Fri Apr 20 00:43:02 2012] [notice] Digest: generating secret for digest authentication ...
    [Fri Apr 20 00:43:02 2012] [notice] Digest: done
    [Fri Apr 20 00:43:02 2012] [warn] No JkLogFile defined in httpd.conf. Using default /etc/httpd/logs/mod_jk.log
    [Fri Apr 20 00:43:02 2012] [warn] No JkShmFile defined in httpd.conf. Using default /etc/httpd/logs/jk-runtime-status
    [Fri Apr 20 00:43:02 2012] [notice] mod_python: Creating 4 session mutexes based on 50 max processes and 0 max threads.
    [Fri Apr 20 00:43:02 2012] [notice] Apache/2.2.3 (CentOS) configured -- resuming normal operations

    Please help me out to successfully run the script. Thanks in advance.

  2. #2
    some things to check:

    1. do you have the path to your python interpreter at the top of your script? e.g.:

    #!/usr/bin/env python
    2. are you sending the HTTP header before sending output, in the CGI script? e.g.:

    print "Content-Type: text/html"
    print ""
    print "Hello World!";
    3. have you tried to execute the python script on the command line, to make sure it is executing properly?

    4. does the user that is running apache have read rights to the directory where the CGI script lives (e.g., /home/asn2012)?

    5. are you sure you are looking at the right apache error log file? you should be seeing something. check also the access_log.

    also, i don't think you need the <Directory "/home/w34admin/public_html/cgi-bin/"> line in your httpd.conf file. at least for what you are trying to do here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts