I am trying to execute a basic hello world cgi script. However I keep getting 500 error. I tried changing the scriptsock setting in my httpd.conf file as well as file permissions and every other suggestion I could find on various postings.... I have reinstalled the OS and started from scratch. I am pretty new to linux however I have learned alot over the past 2 months..Any help would be so appreciated.

Izick

Which version of Apache are you running?

Thank you for replying so quickly...Redhat9

Oh sorry....Apache 2.0 (httpd 2.0.46)

RedHat 9 is the distribution of Linux that Apache is running on, not the Apache version. Do you know which version of Apache you have? I don't use RedHat, so I don't know which version it ships with. (Look at the bottom of the error page, and if you have the server signature turned on in httpd.conf, it'll say something like "Apache 1.3.27 at www.mydomain.com Port 80" or something similar.)

Heh.. you were reading my mind while I was posting that :P

Are you restarting httpd after making changes to httpd.conf ?
(apachectl start|stop|restart)

I originally uncommented the ScriptSocks log/cgisocks then rebooted the machine which httpd is set to restart on boot. It was recommended that I change the file group and owner to apache so i did that two and chmod all the files to 755.


Try commenting the line about ScriptSocks log/cgi and do:
apachectl restart

You don't have to reboot the box to restart Apache :) ...rebooting is for adding hardware :P

Ok...I will try it now. Thank you for your help. I will post in a few and let you know.
Quick question. It seems like I can only get ftp access outside of my /home/user folder if I change the ownership of the /var/www/ folder to owner-me so in other words when I try to upload directly to the /var/www/cgi-bin/ it will not transfer the file unless I make myself the owner. I have tried adding me to the root user accound under the user administration control panel but no luck. ANy suggestions

I commented the scriptsock changed all the group and owner properties to apache. Then chmod all files /var/ /www/ /cgi/ hello.cgi to 755 then restarted apache. still got 500 error. So I uncommented the scriptsock again and restarted, but still got error. :

Are you accessing this box from a Windows machine? If so, I highly recommend installing Samba. Once you have Samba installed, you can share your www directory, and map that shared directory as a drive on your Windows box and just copy the files to it.

If you're transferring the files from another *nix box using FTP, you need to give your Linux user +w access to that directory, or even chmod -R 777 /var/www/*

Also, check the section of httpd.conf where it deals with the cgi-bin directory, as it might be aliased to another directory - ensure the entry is pointing to the proper path for your cgi-bin directory.

Can you send me your hello.cgi file so I can check it on my server? If I can get it working on my 2.x server, I'll know what to tell you to look for/check on your server.

That is really helpful. I am tired of transfering things twice and even sicker of changing ownership rights. That you..I will map the drive for now that seems the easiest way. I have samba up and running. Here is the script.

#!/usr/bin/perl
# simple Hello World script
print "Content-type: text/plain\n\n";
print 'Hello World!';

I checked the scriptalias directive and it was pointing to /var/www/cgi-bin/ also I looked at the apache error logs and it says premature end of script header

OK, here's what I did to get it to work:

Once you transfer it to your Linux box, re-edit the file (using a text editor such as vi or pico on your Linux box) to make sure there's no ^M characters at the line ends, then chmod 755 hello.cgi

Have a look: http://www.geekis-kahn.net/cgi-bin/hello.cgi

Did that help?

The "premature end of script header" was in my httpd-errors.log before I edited the script and removed the ^M characters from the line ends. After I did that and chmod 777 it worked fine.

I did not make any changes to the file..I opened it in a text editor and it did not change compared to the text i sent over to you. so I just chmod's it to 775 and changed the ownership and group to apache apache. However still get error.

When I am looking for the ^M will it look exactly like "^M" I dont see anything other than the ; at the end. I am just using the default editor when I " gedit hello.cgi " from the termial. I changed to 777, also when I run the script from the command line it runs just fine.

You don't have to change the owner/group of the file, just the permissions. httpd (the process/daemon) is recommended to RUN as apache for security reasons, but the entire .../www/ directory doesn't need to be chown to anyone in particular. In fact, my entire directory (+ contents + subdirs) is owned by my normal user account, and all files are 755 as far as permissions go.

Is this on a public site so I can check it from an outside IP?

As I said, the only thing I did to get your script to work on my server was to remove the ^M characters from the line ends (I created the file with Editpad under Windows and copied it to a samba share) and chmod 755 hello.cgi.

If you did that, then we have to assume to problem lies in your httpd.conf somewhere. Can you mail me your httpd.conf file? I have a spare Apache 2.x server I can test it on to see if I can get it to work, if you want...

sure. Thank you so much for your help. I have been going out of my mind with this..

If you edited the file under Linux (or in a term session) you shouldn't see the "^M" characters - these are created under Windows only, and are inserted by a Win32 text editor to indicate a line break/return. Linux/UNIX doesn't recognize that, and therefor doesn't process those characters, which adds the error line in httpd-errors.log regarding the "premature end of script header."

Either something within your httpd.conf is misconfigured, or there's a problem with the directory structure/permissions on directories that are preventing the script from being executed, and unless I had access to that box, it would be difficult for me to tell.

Try running one of the included .cgi scripts to see if they work (if any were included), or save your httpd.conf and reinstall Apache (replacing your saved httpd.conf file and dropping in your script) to see if it works. Either way, I don't think the problem is with your script.

Sorry I wasn't able to get it working for you, but your script DOES work (at least on my server :)

Ok, thanks for your help I will keep playing with the permissions, and then try to reinstall it..Talk to you later.

Rename your existing httpd.conf to httpd.conf.bak and replace it with this one I've edited for you. The changes I made are:

Renamed:
ServerName dns1.xxxxxxx.com
To:
ServerName www.xxxxxxx.com

(dns1 indicates a DNS server. www is used for a normal http server)

Changed Listen *:80 to Listen 80

In fact, I'm editing your httpd.conf and will send it back to you to try out.

Do you have a file named .htaccess in your web directory?

What directory are your files residing in? /var/www/ or /var/www/html/ ?

I sent you the edited file back with notes in the e-mail message. Please let me know if it works.

I sent you the edited file back with notes in the e-mail message. Please let me know if it works.

Thanks for following up with me..My files are in /var/www/html and /var/www/cgi-bin/

No htaccess file right now.


I reinstalled the origional verson of redhat where everthing worked fine.

Still get the error.

I will replace the conf file now..

Make sure you have:

AddHandler cgi-script .cgi

in your httpd.conf or they won't be executed properly, which is happening in this case. I believe I already checked for that in the httpd.conf I modified for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.