Description

This function changes a subdomain's document root.

Examples


https://hostname.example.com:2087/cpsess###########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=SubDomain&cpanel_jsonapi_func=changedocroot&subdomain=subdomain&rootdomain=example.com&dir=public_html%2Fnew_directory

$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
 
// Change a subdomain's document root.
$changedocroot = $cpanel->api2(
    'SubDomain', 'changedocroot', 
        array(
        'subdomaindomain'       => 'subdomain'
        'rootdomain'            => 'example.com'
        'dir'              		=> '/public_html/directory_name'
    )
);

 

my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
 
# Change a subdomain's document root.
my $changedocroot = $cpliveapi->api2(
    'SubDomain', 'changedocroot',
	{
        'subdomain'             => 'subdomain'
        'rootdomain'            => 'example.com'
        'dir'              		=> '/public_html/directory_name'
    } 
);

 

cpapi2 --user=username SubDomain changedocroot subdomain=subdomain rootdomain=example.com dir=%2Fpublic_html%2Fdirectory_name

{
  "cpanelresult": {
    "apiversion": 2,
    "func": "changedocroot",
    "data": [
      {
        "reason": "",
        "reldir": "public_html/new_directory",
        "result": 1,
        "dir": "/home/example/public_html/new_directory"
      }
    ],
    "event": {
      "result": 1
    },
    "module": "SubDomain"
  }

Parameters

ParameterTypeDescriptionPossible valuesExample
subdomainstring

Required

The subdomain for which to change the document root.

A valid domain name.

subdomain
rootdomainstring

Required

The main domain of the subdomain for which to change the document root.

A domain that already exists on the cPanel account.example.com
dirstring

Required

The document root to which to move the subdomain.

A valid directory path, relative to the user's home directory./public_html/directory_name

Returns

ReturnTypeDescriptionPossible valuesExample
reasonstring

A reason for failure.

This function only returns a reason value if there was an error. 

A string that describes the error.

This is an error message.
reldirstringThe path to the subdomain's document root, relative to the cPanel account's home directory.

A valid directory path, relative to the user's home directory.

public_html/new_directory
resultBoolean

Whether the function succeeded.

  • 1 — The function succeeded.
  • 0 — The function failed.
1
dirstringThe absolute path to the subdomain's document root.The absolute path to the addon domain's document root.
/home/example/public_html/new_directory