Scripts and Scripting Languages FAQ

Which versions of Perl are compatible with cPanel?

CentOS 5 installs Perl version 5.8.8, and CentOS 6 installs version 5.10.

However, as of cPanel & WHM version 11.36, cPanel also installs its own copy of Perl version 5.14.3 in /usr/local/cpanel/3rdparty/perl/514/bin/perl

How can I install a Perl Module?

You can find directions in Installing Internal Perl Modules.

Why aren't my CGI and Perl scripts working?

This is a very common problem with a wide array of reasons.

To demonstrate how to troubleshoot script issues, let's use a script called admin.cgi that will not run from the browser as an example.

First, you want to make sure the script is executable. Almost all scripts should be set to permissions 755 with chmod (-rwxr-xr-x = 755).

To find out a script's permissions, log into the command line (as the user with the script problem or as root) and go to the directory the script is in.

The command ls -al admin.cgi will show you what the permissions are for that script:

# ls -al
total 6
drwxr-xr-x 2 burst wheel 512 May 29 16:04 .
drwxr-xr-x 3 burst wheel 512 May 29 16:03 ..
-rw-r--r-- 1 burst wheel 41 May 29 16:04 admin.cgi

From this example, we see that the script has permissions set to 644 (-rw-r--r-- = 644), which means the following:

  • The script is readable by everyone.
  • The script is writable only by the owner.
  • The script is not executable by anyone.

To change the permissions of the script, run the following command:

chmod 755 admin.cgi

When we examine the permissions, we now see the following:

# ls -al
total 6
drwxr-xr-x 2 burst wheel 512 May 29 16:04 .
drwxr-xr-x 3 burst wheel 512 May 29 16:03 ..
-rwxr-xr-x 1 burst wheel 41 May 29 16:04 admin.cgi

The permissions on the script have been changed. The last x means that the script can be executed by anyone, so we can try to view it in our browser again.

If the server still returns a 500 error, let's investigate if the error is due to a coding problem.

Run the following at the command line:

perl -w ./admin.cgi

This will turn on warnings that will let us know if there is an error in the code.

# perl -w ./admin.cgi
Can't find string terminator '"' anywhere before EOF at ./admin.cgi line 3.

That message means that the Perl script will not run because it contains fatal errors.

note Note: How to troubleshoot poor code is far beyond the scope of this FAQ. There are numerous tutorials on Perl and how to troubleshoot specific errors available on the internet, consult your favorite search engine.

If we assume that we have found the error within the code, let's try to run the script from the command line again:

# perl -w ./admin.cgi
Hello World !

If the script works at the command line but still does not work in a browser, there are two common reasons.

The script does not send the correct Content-type to the browser. In our example, admin.cgi will not work in a browser even though it will from the shell.

To fix this problem, add the following lines near the top of the script.

print "Content-type: text/html\n\n";

So, now when we run the script, the first line we see is like this:

# perl -w ./admin.cgi
Content-type: text/html
Hello World !

If the script still does not work in the browser, it's possible that it's the fault of the second reason, su_exec. su_exec is often built into the Apache webserver as a security measure. It forces a sanity check on the permissions of CGI scripts before it runs them, then forces them to run with the permissions of the account owner.

When you check for proper permissions, there are a few things to search for.

# ls -la
total 6
drwxr-xr-x 2 burst wheel 512 May 29 16:04 .
drwxr-xr-x 3 burst wheel 512 May 29 16:03 ..
-rwxr-xr-x 1 burst wheel 78 May 29 16:24 admin.cgi

The directory "." is the current working directory. This must be set to permissions of 755. You may be tempted to set the permissions to 777 with chmod for the cgi-bin as well as all of the scripts. However, that would allow anyone else on the server to save whatever they want to into that directory. If the script is set to permissions of 777 or 775, that would allow anyone on the server to be able to edit that script and change its code. For instance, a credit card handling script could be changed to save credit card numbers to a text file for the 'attacker' to read later. Therefore, the script must also be set to permissions of 755, or su_exec will kill it before it sends the script to the browser.

If you are unsure about problems with a script, examine the su_exec log file located at /usr/local/apache/logs/suexec_log. Use the command tail -f suexec_log to watch the log file, and then try to load the script in your browser to see what the error is caused by the script.

Also, confirm that the file is owned by the user of the account. Sometimes, when a passwd or group file gets corrupted, you will see a number rather than a username:

# ls -la
total 6
drwxr-xr-x 2 8840 8840 512 May 29 16:04 .
drwxr-xr-x 3 burst wheel 512 May 29 16:03 ..
-rwxr-xr-x 1 8840 8840 78 May 29 16:24 admin.cgi

In this case, chown the script and the directory back to it's rightful owner with the command chown burst.burst * . Even if the owner appears to be correct, it is possible for it to have the correct name but actually be associated with a different UID. This issue will appear in the suexec_log; use the same fix as if the owner had a different UID alltogether.

If you have performed all of these steps and the script still does not work, submit a support ticket.

How do I write Javascript code on my website?

You will need to search for a tutorial on Javascript. Javascript is a language that has many rules and conventions and as such may take some time to learn. Once you are ready to add your code, you can edit your HTML files directly to add Javacript code with a text editor, or you can edit them through the File Manager in cPanel.

Suexec is breaking my cgi scripts?

Run the following script:

/scripts/fixsuexeccgiscripts

This script reads /usr/local/apache/logs/suexec_log and looks for errors. If the script finds any errors, it will try to fix them. If you still get errors, tail that log file and see what the error is.

Trying to troubleshoot Perl scripts?

Add the following to the top of the perl / cgi script:

#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);

This will redirect errors to the browser instead of showing a 500 error.

Finally, check if the script runs on the command line and check for errors:

perl -w ./scriptname.cgi

All Perl/cgi's not running as root get the error "getgrgid: invalid groupid XXXXX" ?

ALERT! Note: This also affects interchange.

From Apache's error_log:

[Tue Mar 26 09:13:16 2002] [error] [client x.x.x.x] (2)No such file or directory: getgrgid: invalid groupid 32015
[Tue Mar 26 09:13:16 2002] [error] (2)No such file or directory: exec of /home/username/public_html/utility.cgi failed
[Tue Mar 26 09:13:16 2002] [error] [client x.x.x.x] Premature end of script headers: /home/username/public_html/script.cgi

To fix this error, run the following command:

chmod 644 /etc/group

If that fails to fix the issue, check permissions on the passwd file and shadow file.

Can I run PHP4 & PHP5 at the same time?

No. PHP4 is no longer supported by cPanel.

How do I upgrade from PHP 4 to PHP 5, and what changes are need to be made?

You can upgrade from PHP4 to PHP5 during the Apache build process. You can start the Apache build process in WHM under Software >> Apache Update, or on the command line as root with /scripts/easyapache.

You will need to make sure that the PHP programs and scripts you wish to run are compatible with PHP5.

How do I upgrade Perl?

Prior to an upgrade of Perl, use the "autobundle" CPAN feature to ensure that each module gets carried over to the updated Perl version. You will need to execute this command via root in SSH: perl -MCPAN -e 'autobundle'

Once this is complete, a message similar to the following will appear: 'Wrote bundle file /home/.cpan/Bundle/Snapshot_2007_08_16_00.pm'

Make a note of the filename before you proceed with the update.

To update to Perl 5.8.8 on Linux-based servers:

cd /root
wget http://httpupdate.cpanel.net/perl588installer.tar.gz 
tar -zxf perl588installer.tar.gz
cd perl588installer
./install

Once the update is complete, you can restore all the previously installed modules from the CPAN bundle with the following command: perl -MCPAN -e 'install Bundle::Snapshot_2007_08_16_00'

(Make sure that you replace the bundle name with the one that was generated earlier.)

To confirm that all modules required by cPanel 11 have been installed, run the following script:

/scripts/perlinstaller Task::Cpanel::Core

Finally, restart cPanel:

/usr/local/cpanel/startup

How do I activate/install Zend Optimizer?

To install and activate Zend Optimizer, run /scripts/installzendopt at the command line as the root user.

If I have phpsuexec enabled, how can I override the default settings in php.ini?

Since the php module does not have control over the httpd.conf (or .htaccess files), you need to put a customized php.ini file in the directory that contains your php scripts.

How can I add my own module for WHM or cPanel ?

To add your own module to WHM or cPanel, read our documentation about how to create modules for cPanel and WHM.

Topic revision: r18 - 03 May 2013 - 14:50:56 - Main.LaurenceSimon