Cgi/perl stuff


I am playing around with cgi scripts on my site, but I can’t get any of them to execute.
I could write a script that simply prints ‘hello’, point a form toward it, and it should execute it, right?
All my scripts do is display their text contents in the web browser.



Do you give your scripts the correct extensions, [color=#CC0000].pl[/color] or [color=#CC0000].cgi[/color]? Do you print the correct header to the browser? If you want me to take a look, feel free to post a URL and I’ll see if I can help.


Here’s the url for my experimentation,
I’m very new to this, but my understanding of cgi is that it communicates between your browser and the program your running.
So the perl program could simply print “hello”, the cgi protocal would send that result back to the browser, which would print ‘hello’.
Is this the right way of thinking?

Thanks for the help,

Hi Elam

When trying the URi you gave me, I get a form come up. When trying to submit any information into the form, I get a 500 server error.

Can you look in your log files, in directory /logs/yourdomain.ext/ and tail the error_log for the last few lines to see what causes this program to churn up this error.

Most probably it will tell you that you have bad headers. If that is the case, can you provide me with a link to the source of the program (CGI program) so that I can look and analyze your code for you?

=> Did you upload your program in ASCII file transfer mode and is the permissions on the file OK? Try chmod your program to 755. <=

You are right in thinking that the browser communicates with the server via CGI. You might want to take a look at some learning resources on the web, to learn more about CGI and Perl. Try the following URi as a starter:


Howdy Wil,

I did get some of my other scripts working. Turns out I didn’t have my CGI fully enabled in my Dreamhost account.
I downloaded a script called web2mail, because I want to install it on another server so a friend of mine can get his completed web forms mailed to him.
His web hosting service doesn’t have any canned scripts, so I have to import them.
The source is here

The author of the script says you only have to do a few simple things: filling out the destination email address in the form itself, and pointing the script to sendmail on whatever server your’re using:

One thing that is confusing to me is the location of sendmail on my server. It’s in ‘/usr/sbin/sendmail’ I can’t simply execute it by typing ‘sendmail’ It has to be './sendmail"
Could that be the problem?
When I run the script directly through Telnet, it prints out the HTML code for “no email address given” which would make sense as the script is recieving no data through CGI. But it runs! I can’t get anywhere running it through my browser.
My error gives me the cryptic “Premature end of script header.”. Thanks for the link.

Hope I am making sense.



Just scanned through your message quickly. I will look more into it later. Just picked a few things you could try in the mean time:

Change the first line of your program to read:


(assuming this is hosted on a dreamhost server?)

To make sure that you are pointing to the latest version of Perl on the server.

You could also make double sure that you have uploaded the file in ASCII format and the permissions are OK. That is you have CHMOD the script to 755 (usually required).

About the location to sendmail, you need to write the full path in where required, that is:


However, as your hosting this on a different server, you may want to check the location to [color=#CC0000]sendmail[/color] (or it’s equivalent) on their server. They might be using a different program to handle their mail, or it might be in a different location.

Hope this helps. I will take a look over your script again and get back to you soon.

[color=#0000CC]Did you get the output of the error_log?[/color]


I reload the in ascii format and made it executable(chmod 755).
I also changed the path to perl, and the path to sendmail is correct.

My error log states “Premature end of script header.”




I downloaded your scripts and forms and uploaded them to my site (that’s hosted by dreamhost):

Fill in the form, and hit the Send Information button and it should send details to your email no problem. Let me know if this information does reach your inbox, btw?!

Now, the only line I changed was that in your initial form.html file. I changed the line:




Because the web2mail script can only handle forms that use the [color=#CC0000]POST[/color] method and can not handle [color=#CC0000]GET[/color].

Is this script being hosted by dreamhost? Or another service provider?

Feel free to try the above script out by the way… to see if it works as it should be. I’ve never tried this script before.


You’re a genius. Actually the problem it turns out for me was that I named my file instead of web2mail.cgi
I thought you could use a .pl extension.
Your’re email reached me just fine.

Yes, my website is hosted by Dreamhost.
Thanks a bunch. You’re a helpful dude.


you can definitely name the script with either extension. In fact the extension doesn’t matter at all. The important part is to set the permissions correctly and to have:
at the top of the script.
(#!/usr/local/bin/perl should work as well)


An extension of [color=#CC0000].pl[/color] should have worked as this is supported by Dreamhost. It must of been one of the other things I noticed that made the difference.

Still, glad that it works.