Blacklab Hosting Website hosting made simple
Search for your domain name
Go to the Homepage
Hosting Packages
About Blacklab
Contact Us
Frequently Asked Questions
Terms & Conditions
Order Form
Other Utilities
Website Design Services
Member of Nominet
Powered bu Apache
Sun Microsystems

CGI's the ins and outs

FAQ: CGI's - the 'ins and outs'

Blacklab provides a number of common CGI applications within your CGI Bin. This page is intended for those who want to use these applications or their own specific applications. These include:

  • Formmail
  • OrderForm
  • Access counter
  • Guestbook
  • WWWBoard
  • Digital clock
  • Countdown
  • Random link generator
  • Random image picker

Useful scripts can be found at Matt's Script Archive

What is a CGI?
CGI, or Common Gateway Interface, allows interaction between a visitor and your website. A CGI application is a program made in a programming language (usually Perl or C) made to do just about anything its programmer intends it to. It could be a search engine, a shopping cart, a counter, a game, a message board, etc. There are thousands of CGI applications on the Internet, many available for free. We recommend you take a look around and add a few CGIs to your website to improve interactivity. It can definitely improve a visitor's experience to your website.

One of the best source for CGIs on the Internet is CGI-Resources.com.

Perl or C/C++?
Many people ask whether they should choose a CGI application made in Perl or C/C++. The answer to that is mostly performance. Perl is an interpreted language. For a Perl CGI to execute, the Perl interpreter must read, interpret the program and execute it. This process is slower, although the difference is not noticeable on Blacklab's fast servers. It only takes less than a second (or a second or two, depending on how complex the CGI program is) to execute the CGI application. A program made in C/C++ is faster. This is because C/C++ is not interpretated by another program before execution (like Perl does), it executes by itself. And since it is a "compiled" program (that is, the CGI application was converted to low-level computer code), it can "talk" faster to the server's CPU and operating system.

Where do I put my CGI applications?
CGI scripts can be executed on any directory of your account. However, it is safer to put your CGI scripts in the /cgi-bin/ directory, since no one can read files from there through the web. This is good specially if your scripts have files containing confidential information, such as usernames and passwords.

How do I make my CGI executable?
CGI needs to be made executable before it can be used by a website/webserver. On your account's shell (by using telnet), apply the command "chmod 755 cgi_name", where cgi_name is the name of the CGI program file. You can also do this if you are using an FTP program like CuteFTP by just right-clicking on the filename.

CHMOD What's that?
chmod is a UNIX-like command used to assign permissions to a file or directory. You can set read/write/execute permissions to a file so that you/your group/everyone can either read, write into the file or execute it.

chmod 755 allows everyone to execute a file, read it, but not to write (or delete) to it. chmod 751 allows the same as before, but no one can read it but you. Your account directory and all sub-directories created with your account are set to 751 type permission. We suggest you apply this permission to every directory you create so that no other user on the same server as your account can read the contents of your directories.

500 Internal server error?
So, what happens when a good CGI goes bad? You will see a "500: Internal Server Error" on your browser when you try to access your CGI. Contrary to what the message says, it is not a server error. It is a script error, and figuring out why is it happening can be quite annoying.

If your CGI application is coded in Perl, you can use the Perl interpreter to tell you what's wrong. On your account's shell, go to the directory where the CGI program is and just enter "perl cgi_name", where cgi_name is the name of the CGI. If there is an error, the perl interpreter will let you know.

Also, make sure that you upload a perl script in ASCII mode. If you don't, the script will not work. If your CGI application is coded in C/C++, make sure its permissions were set to executable (see above).

Also, make sure it was compiled correctly. Blacklab Hosting's webserver has SuEXEC installed. This module allows your CGIs to run with your ownership (not the webserver's ownership), which means that you DO NOT need to make directories with permission 777 to have your CGI write/read files on the server. In fact, if you have a directory with permission 777, the CGI will not work and will report an "Internal Server Error". But, the CGI *does* need executable permissions, like 755.

Another common mistake that can cause error 500 is doing a "print" command before sending text/html headers to the browser.

You can send the headers with a command like: print "Content-type: text/html\n\n";

Also, CGIs will not work if you try to execute them on a subaccount (mysite.co.uk/subaccount). But, they will work if you assign a subdomain to the subaccount (subaccount.mysite.com).

If none of that seems to work, contact the author of the CGI application. If you think the error is here, let us know and we'll investigate it.

Where is sendmail and perl?
Some CGIs might require the location of these two applications. The paths to both are:

/usr/sbin/sendmail
/usr/bin/perl

What is my site's directory path?
Your website's path is usually of the form:

/home/sites/mycompany.co.uk/web

Check the original "welcome" email we sent you when you opened your account with us. The path is specified there.


 

home | packages | about | contact | faq | terms | order | utilities | website design

Website design and hosting by Netsite