Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-03-2008, 09:46 PM   #1
Registered: Feb 2007
Location: /home
Distribution: Kubuntu and CentOS
Posts: 214

Rep: Reputation: 32
Apache2 - python file is downloadable instead of displayed

Hello all,

I can't figure this one out. I want to use python as a CGI handler. aka not the mod_python way.

I have python installed.
I have the python file I am attempting to view set as executable for owner, group, and everyone.
Below is my /etc/apache2/sites-enabled/000-default file.

When I try to view the file in my browser, the browser trys to download it. I have set this up correctly on one box, and attempted to duplicate the configuration on a 2nd box. The second box is not working correctly.

Typically apache forces you to download files when it does not know what to do with them. I have my 'AddHandler' directive so I'm not quiet sure what the problem is.

/var/log/apache2/error.log does not have any hints for me.

NameVirtualHost *
<VirtualHost *>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/
        <Directory />
                Options FollowSymLinks +ExecCGI
                AllowOverride None
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews +ExecCGI
                AddHandler cgi-script .cgi .php .py
                AllowOverride None
                Order allow,deny
                allow from all

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined
        ServerSignature On

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from ::1/128

Old 10-03-2008, 11:16 PM   #2
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 125Reputation: 125
Does your python script start with a proper shebang line? (e.g., #!/usr/bin/python)
Old 10-05-2008, 02:35 PM   #3
Registered: Feb 2007
Location: /home
Distribution: Kubuntu and CentOS
Posts: 214

Original Poster
Rep: Reputation: 32
This is my file:
print "conent-type: text/html\n"
print "<html><body>hello python-friendly world!</body></html>"
and /usr/bin/python is there:
scattaneo@wintermute:/var/www$ /usr/bin/python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting up Python 2.5 on Apache2 in Debian Etch michux Linux - Server 3 09-10-2008 11:21 AM
[Python] 'None' being displayed after adding feature LinuxCrayon Programming 3 03-28-2008 12:10 AM
mod python: What to use for PythonHandler in apache2.conf? BrianK Linux - Software 1 10-10-2007 06:24 PM
Downloadable ISO / file of LQ forum ? markraem LQ Suggestions & Feedback 3 06-06-2006 10:10 AM
python and apache2 mindcry Linux - Software 0 12-09-2004 02:36 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:56 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration