Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
Cannot get simple perl cgi script to work, after migration
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- Cannot get simple perl cgi script to work, after m...
Cannot get simple perl cgi script to work, after migration
30-03-2014 5:44 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I Cannot get simple perl cgi script to work - prior to trying to get anything else to work
The script is called test.pl
It consists of two lines:
#!/usr/bin/perl
print ("Hello test");
I've tried all sorts of combinations to get the file to execute - changing its location, renaming .htaccess, adding .htaccess to other folders.
It seems I should have had CGI-BIN in public. I actually had cgi-bin (unless that was my error). I've changed it to caps now.
On one occasion, I managed to get it to show the file contents, rather than execute it. But now cannot repeat it.
/cgi-bin is empty
I believe this is what should happen:
I place a perl file in public/CGI-BIN
Ensure it has 700 flag settings
ensure .htaccess is in the root (ie below 'public')
------ .htaccess content: -------
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^cgi-bin(/.*|)$ CGI-BIN$1 [L,NC]
Options +ExecCGI
AddHandler cgi-script .cgi .pl
------------------
When test.pl is called from a web browser (http://ccgi.xxxxxxxx.force9.co.uk/cgi-bin/test.pl) the file: public/CGI-BIN/test.pl should execute. (where xxxxxxxx is my username)
Is this correct ?
As it is, I'm getting an Internal Server Error. I've tried setting permissions for cgi-lib, CGI-LIB, .htaccess, public and test.pl to 755 to eliminate permissions as a cause.
The script is called test.pl
It consists of two lines:
#!/usr/bin/perl
print ("Hello test");
I've tried all sorts of combinations to get the file to execute - changing its location, renaming .htaccess, adding .htaccess to other folders.
It seems I should have had CGI-BIN in public. I actually had cgi-bin (unless that was my error). I've changed it to caps now.
On one occasion, I managed to get it to show the file contents, rather than execute it. But now cannot repeat it.
/cgi-bin is empty
I believe this is what should happen:
I place a perl file in public/CGI-BIN
Ensure it has 700 flag settings
ensure .htaccess is in the root (ie below 'public')
------ .htaccess content: -------
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^cgi-bin(/.*|)$ CGI-BIN$1 [L,NC]
Options +ExecCGI
AddHandler cgi-script .cgi .pl
------------------
When test.pl is called from a web browser (http://ccgi.xxxxxxxx.force9.co.uk/cgi-bin/test.pl) the file: public/CGI-BIN/test.pl should execute. (where xxxxxxxx is my username)
Is this correct ?
As it is, I'm getting an Internal Server Error. I've tried setting permissions for cgi-lib, CGI-LIB, .htaccess, public and test.pl to 755 to eliminate permissions as a cause.
Message 1 of 3
(2,155 Views)
2 REPLIES 2
Re: Cannot get simple perl cgi script to work, after migration
30-03-2014 5:54 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
I just had another thought. What if my script has an error ?
Indeed it does. I tried this as a test file.
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html><h1>Hello!</h1></html>\n";
And all works OK. My script needed to output an HTML header.
I'll now work through and reduce the permission levels until it fails again.
Indeed it does. I tried this as a test file.
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html><h1>Hello!</h1></html>\n";
And all works OK. My script needed to output an HTML header.

I'll now work through and reduce the permission levels until it fails again.
Message 2 of 3
(312 Views)
Re: Cannot get simple perl cgi script to work, after migration
30-03-2014 7:34 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Yes, for Perl scripts sending output to the browser it is essential to output the Content Type header first. Without that an Internal Server Error is generated
When developing Perl scripts including use CGI::Carp qw(fatalsToBrowser); will ensure fatal errors are notified, eg the message quoted above. You can provide the Content Type header directly as you did or import the 'standard' CGI functions and use the header() function as below:
Concerning where your files go. If /public/CGI-BIN is self-contained and contains only CGI files (.cgi and .pl) I suggest moving its contents to the root /cgi-bin and deleting /public/CGI-BIN. To activate /cgi-bin you need to disable the /.htacess file in / which rewrites references to /cgi-bin to /public/CGI-BIN. .cgi and .pl scripts need to be executable, chmod 700.
If you wish you can provide a /public/.htaccess containing the single line
if there is ever a need to include CGI scripts in /public.
David
Quote Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, or webmaster and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log
When developing Perl scripts including use CGI::Carp qw(fatalsToBrowser); will ensure fatal errors are notified, eg the message quoted above. You can provide the Content Type header directly as you did or import the 'standard' CGI functions and use the header() function as below:
#!/usr/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print header();
print ("Hello test");
Concerning where your files go. If /public/CGI-BIN is self-contained and contains only CGI files (.cgi and .pl) I suggest moving its contents to the root /cgi-bin and deleting /public/CGI-BIN. To activate /cgi-bin you need to disable the /.htacess file in / which rewrites references to /cgi-bin to /public/CGI-BIN. .cgi and .pl scripts need to be executable, chmod 700.
If you wish you can provide a /public/.htaccess containing the single line
AddHandler cgi-script .cgi .pl
if there is ever a need to include CGI scripts in /public.
David
David
Message 3 of 3
(312 Views)
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- Cannot get simple perl cgi script to work, after m...