Debugging on part(s) of the bash script

Using the set Bash built-in you can run in normal mode those portions of the script of which you are sure they are without fault, and display debugging information only for troublesome zones. Say we are not sure what the w command will do in the example commented-script1.sh, then we could enclose it in the script like this.

set -x # activate debugging from here
w
set +x # stop debugging from here

You can switch debugging mode on and off as many times as you want within the same script.

Whenever possible place any executable scripts inside the cgi-bin directory.

When uploading scripts via FTP make sure to always use ASCII mode. If you are doing a server to server FTP transfer use BINARY mode.

The first line in all PERL scripts must contain the path to PERL which is: #!/usr/bin/perl

Directories and scripts should both executable. Usually the permission level 755 is the best. All files and directories where CGI will be executed must NOT be world or group writeable and must be at least user executable.

Data files that scripts will read/write must NOT be group or world writeable.

Make sure that you DO NOT modify the permissions of the cgi-bin itself. This will cause all scripts to fail. If the permissions have be altered, chmod the cgi-bin back to 755.

Check the code. Frequently there may be a line not closed with “;” or a routine that is not closed.

Make sure that all modules and ‘include files’ required by the scripts are located on the server and are in the proper locations.

Check that your CGI/Perl script is outputting the necessary HTTP headers. To do that in Perl, just below the “shebang” line (#!/usr/bin/perl), type the following line.


#!/usr/bin/perl
print "Content-type: text/html\n\n"


Add a “-w” to the first line of your script. (Example: # !/usr/bin/perl

Most FTP programs allow you to change the permissions of files on the server. You may also use the command shell (SSH) and use the command directly. Example: chmod 755 myscript.cgi

Running CGI scripts in the httpdocs directory without mod_perl in Plesk

To accomplish this on a per domain basis you will need to create a vhost.conf in the conf directory at /var/www/vhosts/serverbuddies.com/ with the following code.

<Directory /var/www/vhosts/mt-example.com/httpdocs>
<Files ~ (\.cgi$)>
SetHandler cgi-script
Options ExecCGI
allow from all
</Files>
</Directory>

Then run the following command to enable the change.

/usr/local/psa/admin/sbin/websrvmng -v -a

Now, all files with ‘.cgi’ extension will be executed as usual CGI scripts in /cgi-bin/.

To enable CGI in httpdocs for the whole server just uncomment the “AddHandler cgi-script .cgi” directive in httpd.conf and restart Apache.

Reference: http://parallels.com/


Safety net for Perl

Safety net for Perl

Perl by default is very forgiving. In order to make it more robust it is recommended to start every program with the following lines:

#!/usr/bin/perl
use strict;
use warnings;

The two additional lines request from perl to catch various common problems in your code. They check different things so you need both. A potential problem caught by use strict; will cause your code to stop immediately when it is encountered, while use warnings; will merely give a warning (like the command-line switch -w) and let your code run.

To read more about them check their respective manual pages at strict and warnings.

How do I enable cgi-scripts to run from both httpdocs and httpsdocs directories in Plesk?

By default Plesk runs CGI scripts in /cgi-bin/ folder only. To allow CGI scripts be processed from any folder, you should uncomment the cgi-script AddHandler directive in the main apache configuration file /etc/httpd/conf/httpd.conf

AddHandler cgi-script .cgi

Then restart Apache with the following command:

/etc/rc.d/init.d/httpd restart

Such customizations can also be done on a per domain basis in vhost.conf.

« Prev - Next »