LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 06: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, 02:13 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,174
Blog Entries: 1

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
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, 03: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, 03:42 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,174
Blog Entries: 1

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
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, 09: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



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 04:41 AM
Apache2 - python file is downloadable instead of displayed Hewson Linux - Software 2 10-05-2008 01:35 PM
Setting up Python 2.5 on Apache2 in Debian Etch michux Linux - Server 3 09-10-2008 10:21 AM
mod python: What to use for PythonHandler in apache2.conf? BrianK Linux - Software 1 10-10-2007 05:24 PM
python and apache2 mindcry Linux - Software 0 12-09-2004 01:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:29 AM.

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
Open Source Consulting | Domain Registration