Difference between revisions of "CGI help"

From XMission Wiki
Jump to: navigation, search
(No difference)

Revision as of 18:00, 7 March 2008

Common Gateway Interface (CGI) services are typically scripts or programs that can be executed in conjunction with web pages. They are often used to process data entered by a visitor.

While HTML is a static language that mainly controls page layout, CGI (Common Gateway Interface) opens up many possibilities for dynamic web pages. XMission encourages our subscribers to explore what CGI can do for them.


Naming & Placement

CGI on XMission requires no interaction from administration. You can set up your own CGI scripts in your public_html directory simply by naming them with a filename ending in ".cgi". There is no need to put your scripts in a cgi-bin directory. (This is also the same with ".php" and ".php3".)


Permissions

The file should be set to allow the web server execute permissions. Assuming the group on the file is "www", issuing the command "chmod g+x filename.cgi" (using your XMission shell account) would give the web server permission to execute the file.


SSI (Server Side Includes)

If you wish to include your script as a part of an HTML file, you will want to use Server Side Includes (SSI) with the Apache web server. The syntax is very simple. You simply need to give your file the ".shtml" extension instead of just ".html" and use the following tag within the file where you'd like to include the script: "".


WWW Services

WWW services can be invoked by using a URL such as "http://www.xmission.com/cgi-bin/servicename", where "servicename" is the name of the service you're invoking.


cgiemail

This is a powerful WWW-to-email gateway that can be configured for your specific needs. By default, you have a simple cgiemail form in your public_html directory. It comes in two parts: mail.html and mail.txt. Refer to our [cgi-email cgiemail help page] for details.


post-query

This is a debugging aid for CGI script writers. It shows the data delivered by a form using the POST method.


query

This is a debugging aid for CGI script writers. It shows the data delivered by an ISINDEX query.


showrawenv

This is a debugging aid for CGI script writers. It shows the entire environment available to the CGI script. This is handy for examining the default command search path, for instance.


test-cgi

This is a debugging aid for CGI script writers. It shows CGI related information (i.e., command line arguments and related environment variables).

Perl Modules

Our webhosting servers have a limited selection of Perl modules installed by default. We are happy to consider installing modules server-wide upon request, but only for versions considered to be stable by the Debian or Ubuntu package repositories. If you have code that needs a later version of code than we have, or if you need code that's not normally packaged, consider using CPAN.

CPAN

You can maintain your own CPAN repository, start with this link: http://www.digitalramble.com/2006/06/14/39/ Once you have your local CPAN repository setup, you can type 'cpan' at a shell on shell.xmission.com and install whatever modules you need ('install DBIx::Class', for example). To utilize your local repository in your CGI scripts, add the following at the top:

 use lib "$ENV{HOME}/perl/lib"; # or whatever the path to your local repository is

We'd also recommend you add this use line:

 use CGI::Carp qw(fatalsToBrowser); 

This allows for any error messages that may result for module discrepancies to be printed to the browser instead of the servers error.log (which you don't have access to unless you've asked us to redirect it somewhere for you).