LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 06-05-2006, 05:33 AM   #1
CauticaL
LQ Newbie
 
Registered: Jun 2006
Location: 127.0.0.1
Distribution: FC4, FC5, Gentoo, Free/OpenBSD, RHE9, XP SP2, CentOS 4
Posts: 4

Rep: Reputation: 0
Apache CGI/Perl Internal Server Error


I've been at this problem for a few hours and it's been very frustrating. However before I get started I just want to thank everyone who can help me out or give some good advice. Thanks

So, I've spent the last half hour searching through this forum alone. I've spent over an hour going through google and other various forums as well. I've seen a lot of solutions already and tried them as well, and so far nothing so I'll try to list everything I have tried. So here goes.

My problem is with CGI/Perl scripts. For some reason even after httpd configuration and restarts and various other modifications to make this work...it just hasn't.

When I go to the script in my browser, I get the notorious "500 Internal Server Error" Which says:

Quote:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, <myemail@site.com> 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.


--------------------------------------------------------------------------------

Apache/2.0.46 (Red Hat) Server at <mysite> Port 80
So naturally, I check the log and I find an error (time stamps and specifics removed):

Quote:
"(2)No such file or directory: exec of '/home/<myuser>/public_html/first.pl' failed, referrer: <a URL>"

"Premature end of script headers: first.pl, referer: <a URL>"
The first thing I do is check the permissions on first.pl,

Quote:
[root@localhostRH]# ls -l first.pl
-rwxrwxrwx 1 root root 76 Jun 5:04 first.pl
I had already tried chmod 775, 777, just to make sure.

So permissions didn't work so I headed over to my httpd.conf to make sure I had the correct settings configured there. I need CGI/Perl access to each user's directory (public_html). Each user has a virtual host config setup, and they all work.

Quote:
<Directory /home/*/public_html>
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
After checking this out I decided to have a look to make sure perl is actually in /usr/bin/perl and writable.

Quote:
[root@localhostRH]# which perl
/usr/bin/perl
[root@localhostRH]# ls -l /usr/bin/perl
-rwxrwxr-x 2 root root 16422 Dec 13 15:43 /usr/bin/perl
It is. Next, I went to test the actual script on my shell. Here is what first.pl is:

Quote:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, World.";
When I run it:

Quote:
[root@localhostRH]# ./first.pl
Content-type: text/html

Hello, World.
Yet, I still get the Internal Server Error when I go to it with the browser (Windows XP - IE v6 SP2).

Around this time I'm searching through google to find a solution, and one common problem was Suexec. I went ahead and found it in /usr/sbin/suexec and following the instruction on Apache website docs renamed it.

Keep in mind after each change in configuration I restarted httpd, even after this...no luck.

SELinux is not installed. It's a fresh install of RedHat Enterprise 9. I also want to mention that this _exact_ setup I have in my httpd.conf is working on my FC5 machine.

So now you know what I have done and haven't done. And again thank you all for your time and help. <3
 
Old 06-05-2006, 05:44 AM   #2
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,895

Rep: Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322
Quote:
AddHandler cgi-script .cgi
Since your script is named first.pl, add the .pl extension above:
Code:
AddHandler cgi-script .cgi .pl
 
Old 06-05-2006, 05:54 AM   #3
CauticaL
LQ Newbie
 
Registered: Jun 2006
Location: 127.0.0.1
Distribution: FC4, FC5, Gentoo, Free/OpenBSD, RHE9, XP SP2, CentOS 4
Posts: 4

Original Poster
Rep: Reputation: 0
Hey thanks for your reply!

I did try that earlier with no luck...including setting it specifically to a directory in a user's public_html directory.

Although, I must say that even without the .pl extension set in the httpd.conf setting, it works fine for other *.pl files on my FC5 box which has the same httpd.conf setup.
 
Old 06-05-2006, 07:04 AM   #4
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,895

Rep: Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322
What is the path to the perl script? Is it: /home/<myuser>/public_html/first.pl, i.e. there are "<" and ">" in the path, or you just used <myuser> to replace your actual username?
 
Old 06-05-2006, 05:28 PM   #5
CauticaL
LQ Newbie
 
Registered: Jun 2006
Location: 127.0.0.1
Distribution: FC4, FC5, Gentoo, Free/OpenBSD, RHE9, XP SP2, CentOS 4
Posts: 4

Original Poster
Rep: Reputation: 0
I used "<myuser>" (without quotes) to replace my actual username. So, no, "<" and ">" are not in the actual path.
 
Old 06-05-2006, 08:43 PM   #6
CauticaL
LQ Newbie
 
Registered: Jun 2006
Location: 127.0.0.1
Distribution: FC4, FC5, Gentoo, Free/OpenBSD, RHE9, XP SP2, CentOS 4
Posts: 4

Original Poster
Rep: Reputation: 0
Ok, so I've finally gotten something to work.

I added -w to #!/usr/bin/perl, so now it's: #!/usr/bin/perl -w

The scripts appear to have no problems running on Apache now! However, without the -w option, they don't work at all and I get an Internal Server Error. Right now the logs are spitting out a lot of errors however everything seems to be working just fine on the web end.

Any thoughts or advice here?
 
Old 06-06-2006, 02:50 AM   #7
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,895

Rep: Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322Reputation: 1322
One last thought is that you created the script in windows using notepad or something like that and then you ftp'ed the file to your linux box using binary mode. So there are control characters (^M) from windows at the end of any line. Use
Code:
vi -b first.pl or
vim -C first.pl
to see if that's the case, because plain vi or vim or other editors do not show the control characters.
I could not think of anything else since your apache config and the script look OK.

Regards
 
Old 07-10-2006, 03:22 PM   #8
craig467
Member
 
Registered: Jun 2005
Location: Maine
Distribution: Red Hat 9
Posts: 65

Rep: Reputation: 15
I am not sure if this will help you or not but I am learning CGI/Perl from the beginning and have been fighting the same issues that you have specified above. I got the same error and spent days working on my httpd.conf file trying to make it bend to my will but the computer won.

I am one of those kinds of people who believes in commenting everything I write, but this scripting language caught me at my own game. I wanted to write a comment describing what a bang statement was at the head of the file, above the actual bang statement. What I found out was that by placing a comment at the head of the file (INSTEAD OF THE BANG STATMENT -
Code:
#!/usr/bin/perl
) I got a similar error to yours, eventhough the script ran fine in the shell and it even said that the syntax was ok after running "perl -w first.cgi"

I figured that a comment would always be ignored but I was wrong and now my script runs fine.

I am using Red Hat Linux 9 and the book "CGI/Perl" by Diane Zak and the configuration settings she talks about are as follows:

***************************************
1. Remove # symbol from the line
Code:
ServerName localhost
line.
2. Change the
Code:
DocumentRoot "/var/www/html"
line to
Code:
DocumentRoot "/home/craig/public_html"
. "craig" in the previous statement is the username I have for this exercise - you replace it with your own.
3. Insert the line
Code:
Alias /public_html/ "/home/craig/public_html/"
in the aliases section
4. Change
Code:
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
to
Code:
ScriptAlias /cgi-bin/ "/home/craig/cgi-bin/"
5. Change
Code:
<Directory "/var/www/cgi-bin">
to
Code:
<Directory "/home/craig/cgi-bin">
6. If you need to, remove the # symbol from the beginning of the line
Code:
AddHandler cgi-script .cgi
line.
7. Insert the line
Code:
AddType application/x-httpd-cgi .cgi
in the AddType section of the file.

Save the file
make sure that the home directory (craig in my case), the public_html directory, the cgi-bin directory, and all files within the directories and subdirectories within those directories have permissions set to 755.
*****************************************

I hope this helps. I had such trouble getting this to work like you but it is now working. Keep trying, you will get it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache Error (Internal Server Error) dwarf007 Linux - Software 1 07-17-2005 01:16 PM
Perl: Internal Server Error! Jake_B Linux - Software 0 12-26-2004 01:37 PM
HELP! CGI problem : HTTP 500 - Internal server error eech55 Programming 2 10-11-2004 11:27 AM
CGI / Perl Internal Server Error newuser455 Linux - General 10 09-26-2004 02:50 AM
CGI Internal server error newuser455 Linux - General 2 06-10-2004 09:39 PM


All times are GMT -5. The time now is 05:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration