Configuraion to run pyhton script on ubuntu 12.04

J

Jaiky

want to run a python script which contains simple form of html on firefox browser , but dont know what should be the configuration on ubuntu 12.04 to run this script i.e cgi configuration



My code is
ubder
in /var/www/cgi-bin/forms__.py



#!/usr/bin/env python
import webapp2

form ="""
<form action="//www.google.com/search">
<input name="q">
<input type="submit">
</form>"""


class MainPage(webapp2.RequestHandler):
def get(self):
#self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write(form)

app = webapp2.WSGIApplication([('/', MainPage)],
debug=True)
 
P

Pierre Jaury

Jaiky said:
want to run a python script which contains simple form of html on firefoxbrowser , but dont know what should be the configuration on ubuntu 12.04 to run this script i.e cgi configuration



My code is
ubder
in /var/www/cgi-bin/forms__.py



#!/usr/bin/env python
import webapp2

form ="""
<form action="//www.google.com/search">
<input name="q">
<input type="submit">
</form>"""


class MainPage(webapp2.RequestHandler):
def get(self):
#self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write(form)

app = webapp2.WSGIApplication([('/', MainPage)],
debug=True)

In order for you app to run as cgi, you would have to call the webapp2
run() function. Otherwise, it is going to implement wsgi interfaces.

Have a look at:
http://webapp-improved.appspot.com/api/webapp2.html#webapp2.WSGIApplication..run

As well as:
http://httpd.apache.org/docs/current/mod/mod_alias.html#scriptalias

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (GNU/Linux)

iQEcBAEBAgAGBQJR9QHXAAoJEICpgMXoBPtgeX8H/R0YUPuzKmEsGhA2EgzBP4wm
UTBNqRzlpQ78pTLk/GFJZQzVz7Pp6ua/Bocw1VmKvkG8cK6C+uKvywkpme2TKVlB
DQmZe9S0gxIWCSviXk50TIWVMmlrGey091llMhU0rvsq0KCkS3KWutqIpN2A/Bqs
KUEeRDvYRTd6/MBT0/wqsUTIAmTZfqM8Ax3tQDJ82wLOx/66dAqKRZUn6+46+Scv
h2sXRuuV51NnxnlV5LAHBcNzvbtGilGuL93/sjoCElt31Bc21CtwRJZYFudSGfuq
MAS6QHFqisMvvuyCrAxSA57jCKXssH6TeIGhsx7WQRGOZfFjGz2aEowYT/Bvoqw=
=uafR
-----END PGP SIGNATURE-----
 
J

Jaiky

Sir i already tried this "Alias" concept

I did the following steps
===============================================================================
Step 1:
added
"ScriptAlias /cgi-bin/ /var/www/cgi-bin/"

in /etc/apache2/sites-available/default
============================================================================

step 2:-

added :-

def main():
app.run()

if __name__ == '__main__':
main()

in /var/www/cgi-bin/hello_world.py


================================================================================
Now my Configuration of /etc/apache2/sites-available/default in under



<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www

<Directory />
Options FollowSymLinks
AllowOverride None
AddHandler mod_python .py
PythonHandler mod_python.publisher | .py
AddHandler mod_python .psp .psp_
PythonHandler mod_python.psp | .psp .psp
</Directory>

ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin/">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride None
Order allow,deny
allow from all
AddHandler cgi-script cgi pl
</Directory>

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

ErrorLog ${APACHE_LOG_DIR}/error.log

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

CustomLog ${APACHE_LOG_DIR}/access.log combined


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


</VirtualHost>


===============================================================================

my code is under /var/www/cgi-bin/hello_world.py




import webapp2

class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, webapp World!')

app = webapp2.WSGIApplication([('/', MainPage)],
debug=True)


def main():
app.run()

if __name__ == '__main__':
main()
=============================================================================


extra thing i did

in /etc/apache2/mods-available/mod_python.conf
where i created the file "mod_python.conf"



<IfModule mod_python.c>
AddHandler mod_python .py .psp
PythonHandler mod_python.publisher | .py
PythonHandler mod_python.psp | .psp
</IfModule>

################################################################################


when i run localhost/cgi-bin/hello_world.py


error i get


Not Found

The requested URL /cgi-bin/hello_world.py was not found on this server.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80

#############################################################################
 
J

Jaiky

Problem solved regarding cgi configuration on ubuntu 12.04 lts


Concept:)
file used:)
/etc/apache2/httpd.conf
/etc/apache2/sites-available/default

############################################################################
steps done 1:)

in /etc/apache2/httpd.conf
added line


#########for link localhost/python2/hello.py
ScriptAlias /python2/ /var/www/python2/

<Directory "/var/www/python2/">
AllowOverride None
Options +Indexes FollowSymLinks +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
#######fro runing of python script
AddHandler cgi-script cgi pl mod_python .py
PythonHandler mod_python.publisher | .py
AddHandler mod_python .psp .psp_
PythonHandler mod_python.psp | .psp .psp
PythonDebug On
</Directory>

#########################################################################

step done 2:)

added line

#######fro runing of python script
AddHandler cgi-script cgi pl mod_python .py
PythonHandler mod_python.publisher | .py
AddHandler mod_python .psp .psp_
PythonHandler mod_python.psp | .psp .psp
PythonDebug On

between

<Directory "/var/www/">
-----------------
---------------
HERE I ADDED Line
-------------
-----------------
</Directory>


<Directory "/usr/lib/cgi-bin">
-----------------
---------------
HERE I ADDED Line
-------------
-----------------
</Directory>


############################################################################

Step Done 3:)

added line
in /etc/apache2/mods-available/mod_python.conf

######mod_python.conf i created


<IfModule mod_python.c>
AddHandler mod_python .py .psp
PythonHandler mod_python.publisher | .py
PythonHandler mod_python.psp | .psp
</IfModule>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top