How to write first Hello World program using CGI programming in Python?

PythonServer Side ProgrammingProgrammingCGI

First CGI Program

A CGI script called is kept in /var/www/cgi-bin directory and it has following content. Before running the CGI program, we make sure we change the mode of file using chmod 755 UNIX command to make file executable.


print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello Word - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my first CGI program</h2>'
print '</body>'
print '</html>'


If you click, then this produces the following output −

Hello Word! This is my first CGI program
Published on 31-Jan-2018 11:46:07