CGI script is invoked by HTTP server to process user’s input submitted through . It is stored in the cgi-bin and can be written in several language such as bash (.cgi), python, and perl.
I came across CGI when I was finding methods to run my python file. So far, php’s exec method didn’t work for me. Tried jQuery’s POST method to call the python file also didn’t work.
exec ("helloworld.py", $output);
I managed to run a simple python cgi code when directing the browser to http://localhost/cgi-bin/hellp.py. But before that, I had a hard time figuring out where exactly to put the python file. According to this tutorial, cgi-bin is under /var/www/. However I couldn’t find anything there. I had apache2 installed and there are some people who mentioned that cgi-bin by default is found under /usr/lib/ which turns out to be right. I created a simple cgi file using bash but it couldn’t display anything (Ref here). I tried my luck by modifying the codes to a python code and saved it as hello.py. And it works!
print '<h2>Hello World!!</h2>'
I continue reading about CGI for Python and realize that it actually isn’t too suitable for my case because I am not processing a form. I could have processed it easier with PHP and MySQL database.
Well then, time for lunch. After lunch, there are more things to research on (like jQuery AJAX) and probably to try CherryPy thoroughly again.