Manage cookies that are used for advertising, such as ad personalization, remarketing, and ad effectiveness analysis.
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:
- Permissions to the directory where the script is located must be
750orrwxr-x—. - Permissions to the script should be
750orrwxr-x—. - 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. - At the beginning of the file, the interpreter that will process the script must be specified.
- 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/htmlfollowed by a blank line. - 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.
Example of Perl script
#!/usr/bin/perl
print "Content-type:text/html\n\n";
print "Hello, World!";
print " ";
Example of Python 2 script
#!/usr/bin/python
print "Content-Type: text/html\n\n"
msg = "Hello, World!"
print """%s""" % msg
Example of Python 3 script
#!/usr/bin/python3
print("Content-Type: text/html\n\n")
msg = "Hello, World!"
print("""%s""" % msg)
(3)