Link to home
Start Free TrialLog in
Avatar of linxcelent
linxcelent

asked on

Perl Script: Server Error 500

I have problem with "pass.pl" perl script. This Perl script is to verify the username and password from a client browser.

1. If the user input an incorect username or password it  will direct the user to the page with reject massege.

2. If you a user input the correct username and password it will direct user to the secured page.

Currently the script "pass.pl" is locate in the /usr/www/cgi-bin directory.

Here is the error message when I tried to submit the form:
--->
Server error!
The server encountered an internal error and was unable to complete your request.

Error message:
   Premature end of script headers: pass.pl
   If you think this is a server error, please contact the webmaster
   Error 500
   rmc-lnxsrv
   Tue 04 Mar 2003 01:23:33 PM EST
   Apache/2.0.40 (Red Hat Linux)
-->

Is there anyone can help me with this I greatly appreciate your help.
Avatar of buyboy
buyboy

Normally you get this error when it isn't uploaded in ASCII mode or when your script is corrupted (while editing). You can change the upload mode in your FTP program.
Avatar of periwinkle
500 is a generic Apache error code that means a CGI script has failed.  

Buyboy has good first things to check - make certain that the script was uploaded as ascii, and that you've set the permissions properly to 755 (see http://toto.com/tips-cgi1.html for a discussion on setting file permissions if you are not familiar with them).

You should also check the error_log for the web server, to see if more information is available - often, more information will be given there.
Hi!

Make sure you have this at the top of perl script:
print "Content-type: text/html\n\n";

Next thing to check is:
Don't have cgi-bin group or world writeable.
pass.pl isn't group or world writeable.

pass.pl is executable.

Confirm that pass.pl works, by running it in shell environment.

Make sure pass.pl has same group belonging as web server is running as.

Regards
/Hans - Erik Skyttberg
Avatar of linxcelent

ASKER

Thank you Buyboy, Periwinkle, and Heskyttberg for your help. I will work on it tomorrow, because my script is running under my Intranet Server at my work. I can't access it at the moment.

I am greatly appreciate your help!
I am still getting the same error message after I did the change you asked me to do. I re-upload again with ASCII option. Is there any command in Linux I can use to check to see if the file I upload is an ASCII type? What can I do next step. Please help!
Did you check the error_log for the server??  Generally, there will be more information there.

Do you have access to a Linux shell?  If so, try to run pass.pl from the command line and report back what happens!
This is the error message I get when I run #perl /var/www/cgi-bin/pass.pl

--->
Can't locate cgi-lib.pl in @INC (@INC contains: /usr/lib/perl5/5.8.0/i386-linux-
thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thre
ad-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/
vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/
lib/perl5/vendor_perl .) at /var/www/cgi-bin/pass.pl line 3.
--->

#=================== Script starts ==================
#!/usr/bin/perl
require ("cgi-lib.pl");
&ReadParse(*form);
$user = $form{'user'};
$pass = $form{'pass'};

####################################################################
#Start here to edit the 5 variables that may need to be changed    #
####################################################################

# Edit Variable #1 of 5
#Set #!/usr/bin/perl at the top line 1 to point to your Perl interpretor
#Usually #!/usr/bin/perl or #!/usr/local/bin/perl

# Edit Variable #2 of 5
#Replace "california" on next line with your own username  
$myusername = "username";

# Edit Variable #3 of 5
#Replace "raisins" on next line with your own password
$mypassword = "123";

# Edit Variable #4 of 5
#Replace "granted.txt" on next line with your own file to be displayed when user/pass is correct
$protectedfile = "http://lnxsrv/~username";

# Edit Variable #5 of 5
#Replace "denied.txt" on next line with your own file to be displayed when user/pass is incorrect      
$accessdeniedfile = "http://lnxsrv/~username/error.html";

#That's it for this file Install Step #2. Now go to Install Step #3 on the readme.txt file.

####################################################################
#End of variable selection DO NOT edit below this line             #
####################################################################

if ($mypassword eq $pass && $myusername eq $user)
{
     print "Location: $protectedfile\n\n";
}
else
{
     print "Location: $accessdeniedfile\n\n";
}
#================== Script ends =====================

I do have the "cgi-lib.pl" within the /var/www/cgi-bin directory. What did I do wrong here? Help!
try using a full path to cgi-lib.pl, like:

require "/home/yourhost/var/www/cgi-bin/cgi-lib.pl";
How can I check the error_log? Yes, I have access to a Linux shell.

I've been trying many ways:
changed the path within the "form" to "/var/www/cgi-bin/pass.pl"
===> Error 404
Object Not Found!

changed the path within the "form" to "/cgi-bin/pass.pl"
===> Error 500
Server Error!
The server encountered an internal error and was unable to complete your request.
Error message:
Premature end of script headers: pass.pl

--------------------------------------------------------
I checked the httpd.conf file to see if anything I can do to make cgi-script executable. This is what I found in the httpd.conf file:

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
AddHandler cgi-script .cgi .pl

<Directory "/var/www/cgi-bin/">
    AllowOverride None
    options +ExecCGI
    Order Allow deny
    allow from all
</Directory>

Do you think I have problem with my httpd.conf file? What change do I have to make for cgi-script to be execute?

PS. I am greatly appreciate your help!


are you on a shared server, or is it a server entirely for your own use?  If it is shared, the full path probably is something like:

/home/yourname/var/www/cgi-bin ...

You could run a utility script such as PerlDiver (free version located at:

http://www.scriptsolutions.com/programs/free/perldiver/     

This would tell you what your home environment was, and the full path to the scripts...

Look for the access_log and error_log for your server - probably in /var/log/httpd or /var/log or where your apache source is... then you can use a command like:

tail -100 error_log | more

to look at the last few entries...

Hi!

This error:
--->
Can't locate cgi-lib.pl in @INC (@INC contains: /usr/lib/perl5/5.8.0/i386-linux-
thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thre
ad-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/
vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/
lib/perl5/vendor_perl .) at /var/www/cgi-bin/pass.pl line 3.
--->

Is because you don't have cgi-lib.pl in your cgi-bin dir.

Regards
/Hans - Erik Skyttberg
Hi!

So just put cgi-lib.pl in your cgi-bin dir and run the original pass.pl.

Regards
/Hans - Erik Skyttberg
Thank you heskyttberg for the reply.

I do have both "cgi-lib.pl" and "pass.pl" in my /var/www/cgi-bin/ directory. I am suspecting that something is doesn't work right within my httpd.conf configure file.

If you refer to my above comment above about my "ScriptAlias" path and the "Directory" path. Do you think this setting is right?

Any advice?
Thank you for your help, heskyttberg.
ASKER CERTIFIED SOLUTION
Avatar of heskyttberg
heskyttberg

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Erik,

I tried the configuration in your commend above, still no luck. I tried everything you told me and everything I posibly know still no luck :(

Here is my Linux Server functions. I have my Linux Server running as Samba Server sharing files with my internal Windows NT 4.0 domain, and as secondary DHCP server. Everything working quite well.

Now I want to have it running as an Intranet Apache Server. My httpd.conf file was configured to host my local web sites. It works find with "http://localhost/~username" but when I tried to run the "CGI" script It gives an error message "Server Error !". I read the menual about CGI script, they told me to make change to the httpd.conf configuration file, the same thing as you recommended me above. I tried that... Still no luck :(

Any other ways you think I can try? Thank you Soooo much for your help!

   
Linxcelent,
Are you running apache on windows? If so, you may have to add this line in Sections 1: Global environment of your httpd.conf file.

ScriptInterpreterSource registry

So that your script will look something like this:

### Section 1: Global Environment
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests it can handle or where it
# can find its configuration files.
#

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the LockFile documentation (available
# at <URL:http://httpd.apache.org/docs-2.0/mod/mpm_common.html#lockfile>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
ServerRoot "path/to/your/server"

ScriptInterpreterSource registry    <---- That is needed!!

#
# ScoreBoardFile: File used to store internal server process information.
# If unspecified (the default), the scoreboard will be stored in an
# anonymous shared memory segment, and will be unavailable to third-party
# applications.
# If specified, ensure that no two invocations of Apache share the same
# scoreboard file. The scoreboard file MUST BE STORED ON A LOCAL DISK.
#
ScoreBoardFile logs/apache_runtime_status
OH! I forgot, your running Linux..

Make sure you uncomment this:

# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
AddHandler cgi-script .cgi  <-- You can change that to .pl also.


Have you tried to run the file as a .cgi?
I find that sometimes when you get that error, you can change the extension to .cgi and chmod the file to 755 and run it that way..

Hope that helps.