Issue
http://www.tutorialspoint.com/python/python_cgi_programming.htm
#!/usr/bin/python
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>'
What is the significance of #!/usr/bin/python
It says to save file as hello.py
and save it to /var/www/cgi-bin
directory but I don't have this directory, should I create one?
Before running your CGI program, make sure you have change mode of file using chmod 755 hello.py UNIX command to make file executable.
but where to (how to) execute this chmod
command? should I include $chmod 755 "/location of hello(.py).../"
in hello.py
?
Solution
You have to include the #!/usr/bin/python
line on *nix systems to tell the shell how to interpret this script and where your interpreter is in the system. This is called the shebang line.
The chmod 755 hello.py
command is a unix shell command to change the permissionson of the file and make it executable. Doing this you can run the script without having to do python hello.py
but instead ./hello.py
.
From my understanding you are a windows user. In this case, you don't have to do all of this. Just save the file as hello.py
and that's it.
This post on tutorialspoint.com implies that you already have an HTTP server running that supports cgi and has a default web directory of /var/www/
Answered By - Azwr Answer Checked By - Clifford M. (WPSolving Volunteer)