2.4.3.17. Perl or Python script not working

Perl and Python scripts can be run as CGI applications.

If an error "500 Internal server error" occurs when attempting to execute the script, ensure that the following conditions are met:

  1. Permissions to the directory where the script is located must be 750 or rwxr-x—.
  2. Permissions to the script should be 750 or rwxr-x—.
  3. There should be no special characters after the path to the interpreter. The line break should be in UNIX format — \n, not in Windows format — \r\n.
  4. At the beginning of the file, the interpreter that will process the script must be specified.
  5. If the script needs to output anything to the browser, at the beginning of the script, you should insert a line that outputs the header Content-Type: text/html followed by a blank line.
  6. There must be a blank line at the end of the file.
To run a Python script named index.py as an index file, you need to either rename it to index.cgi or add the directive DirectoryIndex index.py to the .htaccess file.
#!/usr/bin/perl
print "Content-type:text/html\n\n";
print "Hello, World!";
print " ";
#!/usr/bin/python
print "Content-Type: text/html\n\n"
msg = "Hello, World!"
print """%s""" % msg
#!/usr/bin/python3
print("Content-Type: text/html\n\n")
msg = "Hello, World!"
print("""%s""" % msg)
Content

    (3)