cee oh em gee tee - "commgitt"
Login to access.
User: pw: ?


programming language

Practical Extraction and Report Language

Problems and Solutions

Problem: Seeing source code of script - no execution

Solution: Make sure Perl is fully supported in the web server environment.
  By default, Perl scripts are only allowed to execute in specific directory (server/cgi-bin/). To enable other locations, see Enable Execution Anywhere below.

Problem: Getting 'Internal Server Error' Message

Solution: Problem can be caused by multiple different reasons - make sure script meets all requirements below.
  1. Text-file type: UNIX or DOS linefeed style and NOT Macintosh (Mac-formatted text files doesn't seem to work that well...)
  2. Execution flags set? chmod a+x <file>
  3. Appropriate first line, including correct path to the Perl interpreter?
    more likely: #!/usr/bin/perl
    and not: #!/usr/local/bin/perl
  4. Note: #!/usr/bin/perl -wT with -wT works on Mac but fails on 1&1 server.
  5. Mac OS X 10.5: Got use diagnostics;? Remove or comment away...

Easy troubleshooting: try to execute script manually in a terminal window, e.g. % ./

Problem: Getting 'Forbidden' Message

Solution: This message may be a bit misleading (as at least we've seen it for all-together missing file... #1 below).
  1. Make sure file really exist in the location, and name is correct.
  2. You do have AddHandler cgi-script in server configuration but with IncludesNOEXEC, - missing or instead of ExecCGI. Check your server configuration including virtual hosts if applicable.

Testing Scripts

Click to see how the web server handles different potential issues, details that may differ on different servers. All opens in a separate window (or tab).

Script Description Expected result
on Mac DOS-style linebreaks Ok Mac-style linebreaks Failure (Internal Server Error) Unix-style linebreaks Ok With use diagnostics;statement Failure (Internal Server Error) Assumes perl in /local/, #!/usr/local/bin/perl -wT. Failure (Internal Server Error) No execution flags, only read and write Failure (Internal Server Error)

See all scripts above plus more executed with runtime results.

Two Scripts Compared - w/ Potential Problems and 'Safer'

Script w/ potential problems Safer
#!/usr/local/bin/perl       #1
use strict;
use diagnostics;            #2
print "Content-Type: text/html\n\n";
print "<html><head>\n";
print "<title>Print World Script</title>\n";
print "</head>\n";
print "<body>\n";
print "<p>Hello, World!</p>\n";
print "</body></html>\n";
use strict;
# use diagnostics;
print "Content-Type: text/html\n\n";
print "<html><head>\n";
print "<title>Print World Script</title>\n";
print "</head>\n";
print "<body>\n";
print "<p>Hello, World!</p>\n";
print "</body></html>\n";

#1 Expects Perl interpreter in /usr/local/...
#2 Using diagnostics; fails in Mac OS X 10.5 (10.5.2)



Macintosh Notes

Perl-scripts, .pl, are by default only executable in <webserver>/cgi-bin/ - directories and the actual scrips must be physically placed in /Library/WebServer/CGI-Executables/ on the Mac. I.e. when developing scripts this can be a bit confusing and a cause for mishaps.

  Location Comments
1.file /Users/johan/Sites/comgt/inuse/cgi-bin/ originals, where coded
1.web <none>  
2.file /Library/WebServer/CGI-Executables/ where script from 1.file must be copied to be accessible via <stdApacheServer>/cgi-bin/
2.web access to files in 2.file, /Library/....

<hosting servers' customer path to web site>, e.g.:


where files are uploaded to when publishing to Internet
3.web published and released, accessible on Internet

x.file: where file is located in file system; x.web: how file is accessible via web server

Default /etc/apache2/httpd.conf (== /private/etc/apache2/httpd.conf)
<IfModule alias_module>
    # Redirect: Allows you to tell clients about documents that used to 
    # exist in your server's namespace, but do not anymore. The client 
    # will make a new request for the document at its new location.
    # Example:
    # Redirect permanent /foo
    # Alias: Maps web paths into filesystem paths and is used to
    # access content that does not live under the DocumentRoot.
    # Example:
    # Alias /webpath /full/filesystem/path
    # If you include a trailing / on /webpath then the server will
    # require it to be present in the URL. You will also likely
    # need to provide a <Directory> section to allow access to
    # the filesystem path.
    # ScriptAlias: This controls which directories contain server scripts. 
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the target directory are treated as applications and
    # run by the server when requested rather than as documents sent to the
    # client. The same rules about trailing "/" apply to ScriptAlias
    # directives as to Alias.
    ScriptAliasMatch ^/cgi-bin/((?!(?i:webobjects)).*$) "/Library/WebServer/CGI-Executables/$1"

# "/Library/WebServer/CGI-Executables" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
<Directory "/Library/WebServer/CGI-Executables">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all

more on why like this...:

Re: Perl Testing
Posted: Mar 11, 2008 1:54 PM in response to: B Real

Perl is enabled, but Perl is a little more difficult to use. There is no real reason for this, it is just "the way things were done".

You will need to put your Perl scripts into your CGI-bin directory, wherever that happens to be. You could modify your Apache configuration to run Perl from any directory, but that is not commonly done.

Basically, Perl suffers in this aspect just because it was first and that is the way CGIs were done then. PHP came along and the default setting allowed PHP scripts to run from any directory. That is the only difference - the default setting.

Just find your CGI bin directory and put your perl scripts in there and they should work via Apache's cgi-bin alias, whatever that happens to be.


Enable Execution Anywhere

Two steps to configure in httpd.conf or (recommended) users/<somefile>, e.g. users/virtual.conf:

  1. 'AddHandler cgi-script ...' in mod_mime.c section
  2. ExecCGI in Options statement(s)

1. AddHandler:

<IfModule mod_mime.c>
    # AddHandler allows you to map certain file extensions to "handlers",
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action command (see below)
    # If you want to use server side includes, or CGI outside
    # ScriptAliased directories, uncomment the following lines.
    # To use CGI scripts:
    #AddHandler cgi-script .cgi
    # 2008-03-18 Tue 16:08 JAS adding the following line
    AddHandler cgi-script .cgi .pl

2. For every virtual host - make sure to have ExecCGI, e.g.:

<VirtualHost *>
    ServerAlias *
    DocumentRoot /Users/johan/Sites/comgt/inuse/
    <Directory /Users/johan/Sites/comgt/inuse/>
       # Options Indexes FollowSymLinks MultiViews IncludesNOEXEC
         Options Indexes FollowSymLinks MultiViews IncludesNOEXEC ExecCGI

Enable - Handling

If want to allow default directory index file named, include something similar to web server configuration:

<IfModule mod_dir.c>
   # DirectoryIndex index.html 
   # DirectoryIndex index.html index.shtml 
   DirectoryIndex index.html index.shtml



Updated 2008-08-25