If you already have CGI scripts written, before uploading them to the server you must:
Perl: /usr/bin/perl
Python: /usr/local/bin/python
Now you may copy your scripts to the server.
Files must be uploaded to the directory: your_domain/cgi Files from this directory will be available at: http://your_domain/cgi-bin/file_name. To run CGI scripts from the site’s root directory (your_domain/docs), create a .htaccess file in that directory with the following content:
AddHandler cgi-script .cgi .pl .py
Options +ExecCGIMake sure CGI scripts have execution permissions set to 755 (-rwxr-xr-x).
You can change permissions using the file manager in the hosting control panel.
Let’s look at writing a basic CGI script in Perl.
If you are working in Windows, you should use a specialized text editor such as Notepad++ to edit your script code. The default Windows Notepad is not recommended. To demonstrate how a CGI script works, you need to create two files. The first file is an HTML document with a text input form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title> Example of Perl Usage </title>
</head>
<body>
<form method='post' action='/cgi-bin/hello.pl'>
Enter your name:<input type='text' name='name'>
<input type='submit'>
</form>
</body>
</html>The second file is a CGI script
#!/usr/bin/perl
use CGI;
print "Content-type: text/html\n\n";
$my_cgi = new CGI;
$your_name = $my_cgi->param('name');
print "Hello $your_name!!!";Place the first file in the directory: your_domain/docs. Place the second file in the directory: your_domain/cgi. Be sure to check the permissions for your CGI script. They must be set to 755 (-rwxr-xr-x).
To check installed PERL modules, follow these steps:
vim modules.pl
This will create a file named modules.pl.
#!/usr/bin/perl -w
use ExtUtils::Installed;
$installed = ExtUtils::Installed->new();
foreach $module ($installed->modules()){
printf "Module: %s\t\tVersion: %s\n", $module, $installed->version($module);
}
To exit the editor and save the file, press Esc, then type: :wq
perl ./modules.pl
Error 403
If you see a 403 error when accessing a script, it means the script has incorrect permissions. CGI scripts must have execution rights (permissions 755 or -rwxr-xr-x). You can change permissions using the hosting control panel’s file manager.
Error 500
If you see a 500 error when running your script, it means there is an error in the script that prevents the Perl interpreter from finishing its work. The error may be syntactic (e.g., missing a quote or closing curly brace), or logical (e.g., division by zero due to script logic).Error may be both syntactic (for example, you forgot to close a quote or bracket), and logical, for example some of your actions caused a zero division operation. To find out the cause of the error, check the web server log files located in: /var/log/.