Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51383 > unrolled thread

Configuraion to run pyhton script on ubuntu 12.04

Started byJaiky <jaiprakashsingh213@gmail.com>
First post2013-07-28 03:32 -0700
Last post2013-07-29 03:44 -0700
Articles 4 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Configuraion to run pyhton script on ubuntu 12.04 Jaiky <jaiprakashsingh213@gmail.com> - 2013-07-28 03:32 -0700
    Re: Configuraion to run pyhton script on ubuntu 12.04 Pierre Jaury <pierre@jaury.eu> - 2013-07-28 13:34 +0200
      Re: Configuraion to run pyhton script on ubuntu 12.04 Jaiky <jaiprakashsingh213@gmail.com> - 2013-07-28 09:19 -0700
    Re: Configuraion to run pyhton script on ubuntu 12.04 Jaiky <jaiprakashsingh213@gmail.com> - 2013-07-29 03:44 -0700

#51383 — Configuraion to run pyhton script on ubuntu 12.04

FromJaiky <jaiprakashsingh213@gmail.com>
Date2013-07-28 03:32 -0700
SubjectConfiguraion to run pyhton script on ubuntu 12.04
Message-ID<2ebe3375-6aa6-45cd-b534-0241bd025eb3@googlegroups.com>
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)

[toc] | [next] | [standalone]


#51385

FromPierre Jaury <pierre@jaury.eu>
Date2013-07-28 13:34 +0200
Message-ID<87r4ei5358.fsf@silissia.kaiyou.fr>
In reply to#51383

[Multipart message — attachments visible in raw view] — view raw

Jaiky <jaiprakashsingh213@gmail.com> writes:

> 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)

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

[toc] | [prev] | [next] | [standalone]


#51387

FromJaiky <jaiprakashsingh213@gmail.com>
Date2013-07-28 09:19 -0700
Message-ID<b4cbe2d0-1df3-472a-b6ed-7361256c0ebc@googlegroups.com>
In reply to#51385
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

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

[toc] | [prev] | [next] | [standalone]


#51430

FromJaiky <jaiprakashsingh213@gmail.com>
Date2013-07-29 03:44 -0700
Message-ID<681351a1-5918-401e-96d0-b6a17c2dfcd9@googlegroups.com>
In reply to#51383
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>





[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web