LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-29-2012, 07:38 AM   #1
gaurav2772727
LQ Newbie
 
Registered: Apr 2011
Posts: 18

Rep: Reputation: 0
runing python on my apache2 server


As i want to run python script that was called by "action" command in html form ..


my html file(hello.html) is

<html><body>
<form method="get" action="process_form.cgi">
Name: <input type="text" name="name">
<input type="submit" value="Submit">
</form>
</body></html>

and python script(process_form.cgi) is
-----------
#!/usr/bin/python
import cgi
form = cgi.FieldStorage() # instantiate only once!
name = form.getfirst('name', 'empty')

# Avoid script injection escaping the user input
name = cgi.escape(name)

print """\
Content-Type: text/html\n
<html><body>
<p>The submitted name was "%s"</p>
</body></html>
""" ------
All these files are store in var/www/ folder and using http://localhost/hello.html form in displayed and entering something and submitting it then whole cgi file is displayed (if i use .py extension rather then .cgi then it will just open for downloading)
 
Old 03-30-2012, 03:13 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,520

Rep: Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501
Hi,

You should put your script into the apache cgi-bin directory and use
Code:
...
<form method="get" action="/cgi-bin/process_form.cgi">
...
to access it.
If you want to run .py scripts, you should add that extension to the AddHandler directive
Code:
AddHandler cgi-script .cgi .pl .py
Or you can use the mod_python apache module (mind that it's outdated)

Regards
 
Old 03-30-2012, 04:19 AM   #3
gaurav2772727
LQ Newbie
 
Registered: Apr 2011
Posts: 18

Original Poster
Rep: Reputation: 0
hello sir , thanks for reply

sir, i am unable to find this directory (using ubuntu directory structure) , i found this only /var/run/apache2/cgisock..(file) , /var/log/apache2/mod_disk_cache(directory) , but cgi bin (folder) not their ..
 
Old 03-30-2012, 04:42 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,520

Rep: Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501
Hi,

The default apache cgi-bin directory in ubuntu is /usr/lib/cgi-bin

Regards
 
1 members found this post helpful.
Old 03-30-2012, 10:18 AM   #5
gaurav2772727
LQ Newbie
 
Registered: Apr 2011
Posts: 18

Original Poster
Rep: Reputation: 0
thanks sir now its working , and sir pls add me
 
  


Reply


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
[SOLVED] Tomcat Server is runing but web-page is not coming . roshan.s Linux - Software 2 07-14-2011 05:41 AM
Apache2 - python file is downloadable instead of displayed Hewson Linux - Software 2 10-05-2008 02:35 PM
Setting up Python 2.5 on Apache2 in Debian Etch michux Linux - Server 3 09-10-2008 11:21 AM
mod python: What to use for PythonHandler in apache2.conf? BrianK Linux - Software 1 10-10-2007 06:24 PM
python and apache2 mindcry Linux - Software 0 12-09-2004 02:36 PM


All times are GMT -5. The time now is 09:12 PM.

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