Tuesday 30 June 2015

Enable parsing of python code in Web browser with Lighttp server in Ubuntu Mate


python

For a couple of days I am trying to run python script in Web browser. For that I need to enable cgi for web browser, so that it enable to parse .py script. I am using lighttpd (light weight http daemon on my Ubuntu mate). After I installed lighttpd with sudo apt-get install lighttpd, I opened /var/etc/lighttpd/lighttpd.conf.




At the begining of the file it has this lines where "mod_cgi" is being commented.
So I uncommented the  "mod_cgi"

server.modules = (
    "mod_access",
    "mod_alias",
    "mod_compress",
     "mod_redirect",
        "mod_rewrite",
        "mod_cgi"
)
 

if you don't like to uncomment "mod_cgi" there is another option to enable cgi module. Go to terminal and type "lighty-enable-mod cgi".

But I recommend the first option.

After you uncomment the line go to the bottom of the file and add this line.

$HTTP["url"] =~ "^/cgi-bin/" {
        cgi.assign = ( ".py" => "/usr/bin/python" ).


 Close the file and create a directory named cgi-bin on /var/www/.
You can also create it in /var/www/html, but you have to change the path in lighttpd.conf :

server.document-root        = "/var/www/html", 
which is by default server.document-root        = "/var/www/"

After you make this changes restart lighttp daemon. Make sure you put all your python script in the folder cgi-bin in /var/www/html.


 

#python #pythonscript #pythonprogramming #webserver

No comments: