2.4.3.18. Perl or Python script not working
Perl and Python scripts can be run as CGI applications.
If you get an error while trying to execute the script «500 Internal server error», make sure the following conditions are met:
- The access rights to the directory where the script is placed must be
750
orrwxr-x—
. - The script permissions must be
750
orrwxr-x—
. - There should be no special characters after the path to the interpreter. Line feed must be in UNIX format -
\n
and not in Windows format -\r\n
. - At the beginning of the file, an interpreter must be specified that will process the script.
- If the script is supposed to output something to the browser, at the beginning of the script you need to insert a line that displays the title
Content-Type: text/html
and one blank line. - There must be an empty line at the end of the file.
For a Python script with the name
index.py
as an index file, you must either rename it to index.cgi
or add to .htaccess directive DirectoryIndex index.py
.
Sample Perl script
Sample Python 2 Script
#!/usr/bin/python print "Content-Type: text/html\n\n" msg = "Hello, World!" print """%s""" % msg
Sample Python 3 Script
#!/usr/bin/python3 print("Content-Type: text/html\n\n") msg = "Hello, World!" print("""%s""" % msg)