Introduction
The LiveAPI PHP Class provides an environment for PHP applications. You can find this PHP class in the /usr/local/cpanel/php/cpanel.php
file. An example script ships with cPanel & WHM in the /usr/local/cpanel/base/frontend/x3/test.live.php
file.
Note:
cPanel & WHM version 11.28 and earlier used the LivePHP system, which provided similar functionality.
Basic use
Remember:
- PHP applications that use the LiveAPI PHP class must instantiate the
CPANEL
object. - PHP filenames must end in either the
.livephp
or.live.php
file extensions. - Save files to the
/usr/local/cpanel/base/frontend/theme/
directory, wheretheme
represents the cPanel theme, or create a symlink to the appropriate files.
The following example script uses the LiveAPI PHP class to call the DomainInfo::domains_data
UAPI function:
// Instantiate the CPANEL object. require_once "/usr/local/cpanel/php/cpanel.php"; // Connect to cPanel - only do this once. $cpanel = new CPANEL(); // Get domain user data. $get_userdata = $cpanel->uapi( 'DomainInfo', 'domains_data', array( 'format' => 'hash', ) ); // Perform the desired actions.
Instantiate the CPANEL
object
// Instantiate the CPANEL object. require_once "/usr/local/cpanel/php/cpanel.php";
Line 2 instantiates the CPANEL
object. This ensures that the script or application uses the LiveAPI PHP class.
Connect to cPanel & WHM
// Connect to cPanel - only do this once. $cpanel = new CPANEL();
Line 5 uses the LiveAPI new()
method to connect to cPanel & WHM. For more information, read our LiveAPI Methods documentation.
Important:
- You must include this line in all LiveAPI PHP code.
- Only include this line once in any file.
Call cPanel & WHM API functions
// Get domain user data. $get_userdata = $cpanel->uapi( 'DomainInfo', 'domains_data', array( 'format' => 'hash', ) );
Lines 8 through 13 use the uapi()
method to call the DomainInfo::domains_data
UAPI function, and assign the function's output as a hash reference to the $get_userdata
variable.
Notes:
- You can call multiple functions in a single file.
- For more information and use examples, read that function's documentation. All cPanel API 1, cPanel API 2, and UAPI function documents include specific examples for the LiveAPI PHP class.
Perform the desired actions
// Perform the desired actions.
Your script or application's actions could combine any of PHP's many functions.