Find the answer to your Linux question:
Results 1 to 2 of 2
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 : ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2004
    Posts
    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 :
    audit-libs-python-1.7.18-2.el5
    mod_python-3.2.8-3.1
    python-elementtree-1.2.6-5
    python-iniparse-0.2.3-4.el5
    python-urlgrabber-3.1.0-6.el5
    python-2.4.3-44.el5
    libselinux-python-1.33.4-5.7.el5
    libxml2-python-2.6.26-2.1.2.8.el5_5.1
    rpm-python-4.4.2.3-22.el5
    python-sqlite-1.1.7-1.2.1
    python-libs-2.4.3-44.el5

    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
    </Directory>
    iv) <Directory /home/*/public_html/cgi-bin>
    Options ExecCGI
    SetHandler cgi-script
    </Directory>

    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 demo.py 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
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    some things to check:

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

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

    Code:
    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
  •