Perl, PHP, CGI Scripts Information
Contents:
- General Information
- More Technical Information
- Server Side Includes
- Troubleshooting
- Links to Other Resources
Our servers have the capability to run PHP and CGI scripts based on Perl, Unix SH, BASH, KSH, CSH, and C/C++ languages. Perl and PHP are languages of choice for most applications. C/C++ code must be compiled on our web servers prior to use.*
If you have a custom CGI script that you need to use, simply upload it to your "cgibin." Scripts can be installed in any directory and are not limited to the cgi-bin.
- Permissions must be properly set. Most 500 server errors are due to permission problems. We have two FAQ's on file permissions in different styles,
please choose the one appropriate for your level:
Long Winded
Really Long Winded
- Upload in ASCII transfer mode (and NOT BINARY mode). Scripts may run partially or not at all when uploaded in BINARY mode. Be sure to set your FTP software to "ascii". Mac users should choose "text" mode.
- Files can be placed anywhere in your site but we recommend placing them in your local cgi-bin directory to consolidate them.
- "sendmail" on our system is at /usr/sbin/sendmail.
- The default directory for Perl is at /usr/local/bin/perl. The Perl version is typically the most current available. If you require a specific earlier version, contact us.
- Scripts that are to respond to the calling browser with a complete HTML page must have the Content Type tag as the first line of output:
print "Content-type: text/html\n\n";
Otherwise, they must be named with the nph- prefix. The nph- stands for non-parsed-headers. For example, let's say date.cgi returns the date as an SSI. So date.cgi becomes nph-date.cgi so it doesn't mess up the rest of the page.
- <!-- Server Side includes --> only work in files with the .shtml or .shtm extension. The cgi file must have its execute and read public bits on to be run from a browser. The file that contains the include only needs to be readable. Try these commands:
chmod 755 file.cgi
chmod 644 file.shtml
- While you can use a .htaccess file to have the server parse all .htm or .html pages in a directory (and its sub-directories), this will slow the server as it will be parsing some files that do not have SSI's in them. We recommend being very selective if you use this technique. The contents of the .htaccess file would be:
AddType text/x-server-parsed-html .htm .html
- You can name your home page index.shtml to use PARSE(Server Side includes) within it or index.cgi to use a script that creates the home page on the fly. Using an index.cgi to read incoming request headers for browser-type is a good use for this technique. If your index.cgi serves pages based on the HTTP_HOST variable, it may be in violation of our parked domain policy.
- <!--#exec cgi="mycgi.cgi" --> is a cool way to output the result of a simple cgi script into the middle of somefile.shtml .
- More detailed information on SSI's can be found at:
http://www.apache.org/docs/mod/mod_include.html
- If you can't figure out why it doesn't work, run it from the command line via secure shell, or rename it to nph-Scriptname. You'll see more error messages. Running it with the perl w flag will give even more error messages:
perl -w file.cgi
- The three most common cause for errors are permissions, permissions and permissions.
- CGI is programming, don't be mistaken into thinking it is as easy as HTML. It isn't.
- If you are going to use perl, buy a Perl book, please.
- If you can't figure it out, ask us, we will help you by email on an "as time permits basis".
The CGI Resource
- The #1 source for CGI and Perl scripts and information. It is a directory of many publishers and writers that allow for one-stop shopping/ Many are free.
The PHP Resource
- The #1 source for PHP scripts and information. It is a directory of many publishers and writers that allow for one-stop shopping/ Many are free.
Perl.org
- This is the home site for the perl scripting language. Here you can get copies of the perl modules that you can run on your computer to help test your programs before uploading them to the server. A great resource.