|This guide explains the basics of how to test your custom code.|
You can avoid many common issues when you test your code regularly throughout the development process.
While the items below may seem basic, we see many support tickets and forum posts with these issues. As a result, we recommend that, when you troubleshoot custom code, you check the following items first:
Common mistakes include missing semicolons (
;) at the ends of lines, out-of-place comment characters, and misspelled variable names, function names, or filenames.
In Perl code, add the
use strict; and
use warnings; statements to the beginning of your custom code to find these errors more easily.
Make certain that the user who will execute the code possesses the correct permissions.
rootprivileges. For more information, read the desired function's documentation.
cPanel, Inc. produces four current and two deprecated APIs, and they all include separate sets of functions. Make certain that the function and module that you call exist in the API version that your code uses.
Select a tab to view examples of calls to the desired API:
API functions run as a specific user. If that user does not posses the correct permissions, errors may occur.
Often, integrators see errors because of file permission issues with one or more of the files that relate to their custom code.
Make certain that your custom code does not change the permissions for cPanel & WHM's files. Changes to system file permissions may cause unexpected problems on cPanel & WHM servers.
The following examples describe two possible scenarios in which incorrect file permissions could cause problems:
If you see the following error when you call UAPI's
Email::add_pop function, the
/home/username/etc/example.com/shadow file possesses incorrect permissions:
File open for /home/username/etc/example.com/shadow failed with error Permission denied
If the system cannot write to this file, it cannot create an email address, because it must use this file to store email password hashes during the account creation process.
If you see the following error when you call cPanel API 2's
Fileman::mkfile function, the
user cPanel account's files and directories may posses incorrect permissions:
Encountered error in Fileman::mkfile: Could not create file "example.txt" in /home/user/public_html/: Permission denied: Permission denied
To check the permissions for a directory's files, run the
ls -al command.