Scripts and Scripting Languages FAQ
Which versions of Perl are compatible with cPanel?
As of cPanel version 11.25, the only compatible Perl version is 5.8.8.
You can obtain installers for the version(s) of Perl compatible with cPanel/WHM under
Perl Installers on our
Downloads page.
How can I install a Perl Module?
On a server with CPanel, you can log into the WHM and install it there. If that
for some reason doesn't work for you, you can log into the shell as root and install
it via the command line.
Once logged in, from any directory, type:
- /scripts/perlinstaller HTML::Template
In this case, the module we want to install is
HTML::Template.
Why aren't my CGI and Perl scripts working?
This is a very common problem, with a wide array of reasons. For this example, we have a cgi called admin.cgi that won't run from the browser. First, you want to make sure the cgi is executable. Almost all cgi's should be chmod 755. To find out, log into the shell (as the user with the cgi problem or as root) and go to the directory the cgi is in.
- ls -al admin.cgi will show you what the permissions are for the cgi in question.
# 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
Here we see that the cgi does not have proper permissions. Currently, it's chmod 644, which means readble by everyone and writable only by the owner and not executable by anyone. To fix this:
Now when we look at the permissions, we see this..
# 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
Now that the cgi has the proper permissions (the last x means executable by anyone), we can try to bring it up in our browser again.
If the server is still returning a 500 error, examine if it is a coding problem.
- perl -w ./admin.cgi will turn on warnings that will let us know whether or not there is an error in the code.
# perl -w ./admin.cgi
Can't find string terminator '"' anywhere before EOF at ./admin.cgi line 3.
If we see that, for now, the perl script won't run because it has fatal errors in it. Fixing poor code is far beyond the scope of this FAQ. There are numerous tutorials on perl and troubleshooting specific errors available on the internet, consult your favorite search engine. Assuming we found the error in the code, let's try to run it from the command line again.
# perl -w ./admin.cgi
Hello World !
If the script works but still does not work in a browser, there are two common reasons.
The cgi is not sending the correct Content-type to the browser. In our script, the admin.cgi won't work in a browser even though it will from the shell. To fix, we 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 it's still not working in the browser, it's quite possible 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 sanity checking on the permissions of CGI scripts before running them, then forces them to run with the permissions of the account owner. When checking for proper permissions, there are a few things we want to look 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 chmod 755, though it might be tempting to chmod the cgi-bin 777 as well as the cgi's, it opens up the ability of someone else on the server to save whatever they want to in the directory. If the cgi is chmod 777 (or 775 for that matter), it would allow anyone on the server to be able to edit that cgi and change the code. The ramifications of this can be quite serious, such as saving credit card numbers to a text file for the 'attacker' to read later. The cgi must also be chmod 755 or su_exec will kill it before sending it to the browser.
Traditionally, the su_exec log file is
/usr/local/apache/logs/suexec_log. If you are unsure about problems with a cgi, this is a good place to look. You might want to
tail -f the log file then try to load the cgi in your browser (hitting reload a few times won't hurt) to see wheat the exact error is for the cgi. You should also check to see that the file is owned by the user of the account. Sometimes when a passwd or group file get's 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, you would want to chown the cgi AND the directory back to it's rightful owner by typing "chown burst.burst *" . Even if it looks correct, it is possible for it to have the name correct yet be associated with a different UID. This will show up in the suexec_log, and you use the same fix as if it had a different UID alltogether.
If it still won't work, put in a support ticket so we can take a look at it!
How do I write Javascript code on my website?
You'll 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 using 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 reads
/usr/local/apache/logs/suexec_log and looks for errors and tries to fix them, though 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); Then errors should be redirected to browser rather then getting a 500 error.
Finaly, check if the script runs on the command line and check for errors:
All perl/cgi's not running as root get the error "getgrgid: invalid groupid XXXXX" ?
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:
If that doesn't fix it, check permissions on the passwd file and shadow file as well just for good measure.
Can I run PHP4 & PHP5 at the same time?
Question 1) How do I set this up?
The PHPSuExec option is not available in Easy Apache 3. Rather it uses the regular suExec capabilities of Apache. Also, suPHP is available for both PHP 4 and 5, in all versions of Apache. There are several ways to have a PHP 4 + PHP 5 setup. A new configuration page is available in WHM to allow you to configure some of the global setup.
Specifically, the Configuration page allows you (the admin) to specify:
- The default PHP version
- The default handler: suPHP, DSO, CGI, none
- Whether suExec is enabled or not
There is a special new method in EA3 called Concurrent PHP, which one must manually select in EA3. This allows the use of PHP 4 + PHP5 as Apache modules (i.e. both libphp4 and libphp5 are loaded). The same configuration page mentioned will allow yo uto specify which is the system wide default.
suPHP will give users the same benefit as PHPSuExec: the ability to customize PHP by use of a local php.ini file. Unlike PHPSuExec though, suPHP is configurable at runtime by the WHM Admin, using the configuration file in
/opt/suphp/etc/
Question 2) Which version of PHP4/PHP5 is running perfect/okay/problem free now?
The answer to this in part depends upon which 3rdparty extensions you need. For example, many people seem to have issues with Zend Opt 3.3.0 and PHP 5.2.2+ As incompatibilities are identified, we document them in the EA 3 interface. For example, the Suhosin patch is not compatible with Concurrent PHP, and is noted in the interface. We also do some dependency resolution before the build, to skip extensions that are known to be incompatible, in case a user ignores the warning in the interface.
Question 3) At the end user's cPanel, which PHP version will be display?
It's supposed to show whatever is set as the system default.
Question 4) How can end-users choose to use a specific version of PHP?
Right now the only way an end user can choose is by renaming their scripts. For example, if the Admin specifies PHP 5 to be the default, and the user needs PHP 4 for some scripts, renaming the scripts to be .php4 will execute using the PHP 4 handler.
We are currently working on a method that allows an end user more control over this as file renaming is rather awkward for a major application. Once this is tested and available, the user's cPanel should show what he has chosen for default.
Until that tool is available, the end user can over-ride by use of
.htaccess — which we don't recommend. The Admin can also specify overrides by the use of VirtualHost includes. This entails including a configuration file fragment in the vhost, for example:
Include "/usr/local/apache/conf/userdata/std/2/user/custom.conf">
Documentation is in the process of being prepared to fully explain the use of vhost includes. In short, one would place the configuration fragment file in:
/usr/local/apache/conf/userdata/std/2/ or
/usr/local/apache/conf/userdata/std/2/user/
(Note: these directories might need to be created.) Then execute the
/scripts/ensure_vhost_includes script.
--help will explain the use of the script.
The specific Addhandler mime-types used to do overrides will depend upon the specific PHP setup and handler configuration.
Question 5) Are they (PHP5+PHP4) available for Apache 2.X.X?
PHP 4 + PHP 5 combinations are available for Apache 1.3, 2.0 and 2.2 The Concurrent PHP and the PHP Configuration page in WHM are both relatively new.
As far as which Apache version we recommend, we cannot give that answer. In part it depends upon your needs. Apache 2.2 is where all new developments will happen. 2.0 and 1.3 will only receive fixes. Due to the threading changes and issues with PHP 4, Apache 1.3 is highly recommended for that specific version of PHP4, however it will work adequately with 2.0 and 2.2 with the preform MPM.
How do I upgarde from PHP 4 to PHP 5, and what changes are need to be made ?
You can upgrade from PHP4 to PHP5 by recompiling PHP 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 using
/scripts/easyapache.
You'll need to make sure that the PHP programs and scripts you wish to run are compatible with PHP5. You can also choose to run both PHP 4 and 5. For more information on running both versions of PHP and the Apache build process, see
http://www.cpanel.net/support/docs/ea/ea3/.
How do I upgrade Perl?
Prior to upgrading Perl, it is a good idea to ensure that each module gets carried over to the update Perl version using the "autobundle" CPAN feature. You will need to execute this command via root in SSH:
perl -MCPAN -e 'autobundle'
Once this is complete, you should have the the following outputted before returning to the shell:
'Wrote bundle file /home/.cpan/Bundle/Snapshot_2007_08_16_00.pm'
Make a note of the filename before proceeding 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
To update to Perl 5.8.8 on FreeBSD® based servers:
cd /usr/ports/lang/perl5
make && make install
Once the update is complete, you can restore all the previously installed modules from the CPAN bundle that was created by executing:
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.
We should now make sure that all modules required by cPanel 11 are installed and restart cPanel:
/usr/local/cpanel/bin/checkperlmodules
/usr/local/cpanel/startup
How do I activate/install Zend Optimizer?
You can install and activate Zend Optimizer by running
/scripts/installzendopt from the command line as root.
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 php.ini file with your needed changes in file in the directory your php scripts are running in.
How can I add my own module for WHM or Cpanel ?
Please read our
documentation about creating modules for cPanel and WHM.