LWD Internet ... connecting business ... cutting costs ...Accept Credit Card Payments From Your Website
 Home | Domain Names | Web Hosting | E-commerce | Support | Web Design

Perl (CGI) on Linux web hosting accounts

This page provides information about using Perl (CGI) scripting on our Linux servers. If you have a Windows web hosting account, you should read the Windows Perl page instead.

Introduction to Perl
Perl was originally a UNIX scripting language, but has now been ported to Linux. There are many free Perl / CGI scripts available to download and use these with very few or even no changes to the code.

Every Linux hosting account comes with it's own cgi-bin directory. Although authors may recommend that you place your scripts in the cgi-bin, you should be able to run your scripts from any directory on your account. You may also rename the cgi-bin to something else, such as myscripts.

Please note that it is your responsibility to create and install your scripts and to debug them. If you have difficulty with your scripting, we can recommend a web developer that can create your scripts for you.

Version
The version of Perl installed on the servers is Perl 5.005. This is freely available and can be downloaded from http://www.perl.com, along with extensive documentation. If you wish to test your scripts offline on a Windows based computer, you will need to download ActiveState Perl. See also Offline Development and Testing below.

Editing Scripts
Ensure you are using a text editor that saves files in plain text format with correct Unix style line endings. These line endings are usually invisible in text editors. Using a Windows program may save the file with Windows style line endings and may cause your script to fail. If you are writing your scripts on a Windows PC, try using WordPad and using Save As and selecting Text. If you would prefer a text editor with more features, try a search on Google.

Offline Development and Testing
If you download and install ActiveState Perl, then you can build and test scripts offline using a Windows computer, saving yourself a lot of time and trouble. To test a script offline on a Windows computer, open an MSDOS window, change to the directory containing your script, and type in code similar to the following:-

perl -w myscript.pl email=me@mydomain.com message=hello >output.html

In the above example, myscript.pl will be the name of your script, email=me@mydomain.com message=hello are two name=value pairs that will be read as parameters by your script, and >output.html will create an html file called output.html, which can be viewed in your browser.

You can also set up Personal Web Server in Windows 98+, which will then allow you to test scripts from web pages as if the scripts and pages were on a real Internet server. Building and testing in this manner overcomes a lot of problems quickly and easily.

Please note that there are differences between Perl for Linux and Perl for Windows. If you have developed and tested a script offline on a Windows system, you will need to modify it prior to use on your Linux hosting account. See the Perl for Windows page for these differences.

Path to Perl
All Perl scripts on Unix / Linux servers require you to give the path to Perl on the first line of the script. On our Linux hosting accounts, this will be #!/usr/bin/perl

File Extensions
UNIX Perl scripts normally use the .cgi file extension. Perl scripts on our Linux hosting accounts can use either the .pl or the .cgi extension.

File Permissions
When uploading scripts, you need to ensure you set the correct permissions (CHMOD). As a general guide, use the following permissions:
755 rwxr-xr-x for scripts and executables
711 rwx--x--x for the cgi-bin and directories beneath it
644 rw-r--r-- for data file or configuration files used by the CGI script.

You can use your FTP client to set these permissions. See the FTP page for instructions on uploading files and setting permissions with your FTP client. You can also set file permissions from the File Manager within the control panel. Login

Using Downloaded Scripts
You should be able to download and use most Perl / CGI scripts available from scripting resource sites such as HotScripts.com. Follow the instructions provided very carefully and make any changes necessary. If you have any difficulty using the script, contact the script author or check the website that you downloaded the script from for support information.

Please be aware that there are issues with some ready to use scripts such as older versions of Matt Wright's Formmail. Spammers use automated tools to search websites for Formmail so that they can relay email through this script. If you need to use Matt Wright's Formmail script, please ensure you are using the latest version (v1.9 or above) and that you have configured "referers" correctly to prevent spamming. Please also rename the script to something obscure and place it in a different directory, not the cgi-bin. You can run CGI scripts in any directory within httpdocs.

It is also a wise idea to take similar precautions with other downloaded scripts just in case there are issues you may not know about. Where possible, rename the script and place it in a different directory. Always use the latest versions of any code, and check back every now and then for updated versions.

Sendmail
Unix / Linux scripts often require you to provide the path to Sendmail in order to allow a script to send an email. On our servers, the path to Sendmail is /usr/sbin/sendmail. The line you need to modify in your code may look like this:
$mailprog = '/usr/lib/sendmail';

Troubleshooting and Debugging
If you are not careful, your CGI script will fail. Common errors are "File not found" or "500 Internal Server Error".If you receive one of these errors, use the following checklist first:
Did you save the file correctly?
Did you upload the file in ASCII mode?
Did you upload to the correct directory?
Did you set the correct permissions on the file?
Did you set the correct permissions on the directory?
Did you use the correct path to Perl?
Did you use the correct path to Sendmail?
Have you used the correct filename? Remember that filenames on Linux are case sensitive, so XYZ.cgi is different to xyz.cgi.

The above checklist should cure most problems quickly and easily. If you have done everything correctly as above, it is likely there is an error in your script. Check that you have used semi-colons at the end of statements, that you have declared all variables and that there are no other obvious errors or omissions.

If your script is still not working after checking all of the above, then you haven't checked all of the above properly or your code is wrong in another way. Check code very throughly. Sooner or later you will find the error that is causing you so many problems.

More Information
You can find more information about Perl together with some useful scripts and tutorials by following the links in our useful websites page.