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
You can install additional PERL modules from source on your hosting account. Before installation: Enable the latest PHP version in the control panel at Web Server Management → PHP Module Management (Управление веб-сервером → Управление модулем PHP). This will also enable an updated software package that may already include the required Perl module.
Next, set environment variables so installed modules are available to the interpreter.
cat >> ~/.bashrc << "EOF"
PERL5LIB=$HOME/PERL/lib:$HOME/PERL/lib/perl5
export PERL5LIB
MANPATH=$HOME/PERL/share/man
export MANPATH
EOF
source ~/.bashrc
To install the selected PERL module:
cd ~/tmp
wget http://search.cpan.org/CPAN/authors/id/S/SA/SAMPO/Net-SMPP-1.12.tar.gz
tar -xf Net-SMPP-1.12.tar.gz
cd Net-SMPP-1.12
Install the module into a separate directory, e.g. /home/login/PERL, where login is your hosting account ID, by specifying the INSTALL_BASE variable.
perl Makefile.PL INSTALL_BASE=$HOME/PERL
make
make install
perl Build.PL
./Build --install_base $HOME/PERL
./Build install --install_base $HOME/PERL
To use the installed modules in a Perl script, add the following lines to the script:
use lib "/home/login/PERL/lib";
use lib "/home/login/PERL/lib/perl5";
use Net::SMPP;
To allow the Apache web server to work with additional modules: In the hosting control panel, enable the env_module. Add the following line to the .htaccess file in the root directory of your site or in the CGI script directory:
SetEnv PERL5LIB /home/login/PERL/lib:/home/login/PERL/lib/perl5
where login is your hosting account ID.
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/.