FAQ – CGI & Perl
- Can you explain permissions?
- What file permissions do I need for my CGI scripts?
- CGI-BIN and Perl scripts not working on my domain?
- Where do I put my CGI or PERL scripts?
- Do my CGI scripts need to be in the “cgi-bin” folder?
- I am having a problem with my CGI script. What do you advise before logging a support ticket?
- I uploaded my CGI script. How do I execute the script?
- Scripts Banned on our servers.
- What is SSI? and how do I use it?
- Where can I find server paths used in my CGI or PERL scripts?
- Which script i need to use for my Formail application?
- Why am I getting the “Internal Server Error (500)” message?
A – Owner = the files users (you)
Group = the files group
Others = Others
r = read access
x = execute access
w = write access
r = 4
w = 2
x = 1
You will come to recognize, if you do not already, Chmod is a word used for changing Permissions from within Telnet or your FTP client. Some scripts will tell you to chmod 775 (for example). When using the numeric system, the code for permissions is as follows:
4 + 2 + 1 (rwx) = 7
The first number applies to Owner, the second number applies to Group, and the third number applies to Others. Therefore the first 7 of the chmod 775 tells Unix to change the Owner’s permissions to rxw (because r=4 + w=2 + x=1 adds up to 7, this giving the Owner Read, Write, and Execute Permission. The second 7 applies to the group, this giving the Group Read, Write, and Execute Permission, and the last number 5, refers to Others (4 + 1= 5), giving Others only Read and Execute Permission. The permissions for chmod 775 look like this:
Permissions are always broken up into three groups of letters, however if there is a dash, this dash simply means that Permission weren’t given for that particular function. For example, in the chmod 775, Permission to Write was not given to Others.
Remember: the first 3 letters always apply to Owner, the second 3 apply to Group, and the third 3 apply to Others.
A – CGI scripts must be set with executable file permissions, otherwise requests for the script from the web server will result in an “Internal Server Error”.
Scripts that need to be executable should have their permissions set at chmod 755.
This sets the file’s permissions so that the file’s owner may read, write, and execute the file, and anyone else can only read and execute it.
A – There are lot of reasons for cgi and perl scripts to not work.
You can do small tests on your cgi-bin.
Please see below steps:
1) Create a test.pl file in notepad or any text editor with following code:
print “Content-Type: text/html\n\n”;
print “Cgi-bin and perl test “;
2) Upload the script to the cgi-bin folder in ASCII mode
3) Set the test.pl permissions to 755
4) Type http://www.yourdomain.co.za/cgi-bin/test.pl to test the script.
If you can see the message “Cgi-bin and perl test” then your cgi-bin and perl scripts are working fine on your domain.
You need to check your scripts, permissions and upload mode. All these are very important to run successful scripts.
If you are still getting errors then please log a support ticket at http://www.dothehosting.com/contact-us
A – All .cgi and .pl can only be executed in “cgi-bin” at this time. You can find the “cgi-bin” folder in “public_html” folder.
A – Please see “Where do I put my CGI or PERL scripts?“
A – When I activate my CGI program, I get back a page that says “Internal Server Error. The server encountered an internal error or mis-configuration and was unable to complete your request.”
This is generally caused by a problem within the script. Check your script settings again to see that you have entered the correct server information and have set the correct permissions for the script. If this information is correct, you’ll need to contact whoever wrote or is distributing the script for further assistance.
I am being told “File Not Found” or “No Such File or Directory”
Upload your Perl or CGI scripts in ASCII mode, not binary mode.
When I test my Perl script in local mode (by Telnet), I get the following error: “Literal @domain now requires a back slash at myscript.pl line 3, within string. Execution of myscript.pl aborted due to compilation errors.”
This is caused by a misinterpretation by Perl. You see, the “@” sign has a special meaning in Perl; it identifies an array (a table of elements). Since it cannot find the array named domain, it generates an error. You should place a back slash (\) before the “@” symbol to tell Perl to see it as a regular symbol, as in an email address.
I am getting the message “POST not implemented.”
You might be using the wrong reference for cgiemail.
Use the reference /cgi-bin/cgiemail/mail.txt.
Another possibility is that you are pointing to a cgi script that you have not put in your cgi-bin directory. In general, this message really means that the web server is not recognizing the cgi script you are calling as a program. It thinks it is a regular text file.
A – Before executing cgi scripts you need to follow the below steps to avoid any errors:
- You need to upload your script to the “cgi-bin” directory.
- Make sure you upload them in ASCII mode.
- Change permissions to 755 for the script (chmod 755).
You can then access your script via http://www.yourdomain.co.za/cgi-bin/scriptname.cgi
Note: You can’t run CGI or PERL scripts when your domain is under propagation.
A – The following scripts are banned for use on the servers and may not be uploaded or executed. Reasons for banning them include adverse effects on server load, invitations to hackers, spammers and criminal activity and more.
IRC egg drops
Mass Mailing scripts
UBB (Ultimate Bulletin Board, all versions)
Ikonboard, Yabb (all versions)
FormMail.cgi, FormMail.pl from Matt’s Script Archive are not allowed. See Here
Cgi/Perl Content management systems like Moveable Type ( mt.cgi ).
Shell, SSH, Telnet Scripts and Shell, SSH, Telnet Alternatives.
Any script that uses & processes a massive number of flatfiles or large flatfile databases.
A – Server Side Includes (SSI)
When using a UNIX/LINUX system it is sometimes necessary to enable certain HTML file executables for the purpose of using SSI. SSI is often used to run a cgi script. An include is called with an example such as the following:
After you insert your include, you must mark the HTML file as executable so the server will parse the file. This is done using the two options below:
- Renaming the file to .shtml: Any file name with the extension .shtml on the server, will be parsed. So, instead of having an index.html file, you would name itindex.shtml. This is the easiest way of enabling ‘includes’.
- CHMODing the file to 777: With CHMOD 777 you can also mark a file as executable. It is important to only make the files which you want parsed executable. This poses certain security issues, as well as a strain on our resources, as the processor has to work harder to parse a file.
Reasons for Using SSI
SSI is often used to include something into an HTML page. You can insert the contents of one HTML page into another page. An example of a practical usage for this would be to include your e-mail address at the bottom of each page. If you do this as an include, then when your e-mail address changes, you will only have to update it on one page and not your entire web site. Another usage is to call cgi scripts into action. Many counters, clocks, and other scripts are called using SSI. The command used will most likely be provided in the documentation of your cgi script.
A – Perl path (version 5.8.7): /usr/bin/perl
Absolute path for your html files/scripts: /home/username/public_html/
Absolute path for your cgi-bin: /home/username/public_html/cgi-bin/
A – You can download bnbform.cgi from here. Bnbform.cgi is very easy to setup and more secure than many other scripts. Install the bnbform.cgi on your site as per the installation instructions.
A – Internal Server Error (500) errors are usually something wrong in the syntax of your script. You should check to make sure you have the path to PERL correct. Currently we are running Perl5 on the servers.
See “Where can I find server paths used in my CGI or PERL scripts?” for the most common paths needed for CGI & Perl scripting.
Other most common reasons are:
- Wrong syntax in your cgi script.
- Wrong file permissions, chmod 777 world read, write execute is most common error. Try chmod to 755
- Wrong file path. See the correct format here.
- Cgi Script was not uploaded in ASCII mode.