Search code examples
phpapisubdomaincpanel

Using cPanel LiveAPI PHP Class on Siteground shared hosting account


I was wondering if anyone has implemented a PHP application level access to cPanel on a shared hosting provider ( in my case - Siteground). I've been looking into the documentation on the LiveAPI PHP website and it mentions that it involves managing some files in the main cPanel installation directory. I couldn't find references to any downloadable resources, so if could provide links to those and an example of how you carried out your implementation, that would be great.

I wish to programmatically (in PHP) create subdomains in cPanel and provide the respective routing directories for the same.

I found this related question but it lead to a dead end as the main PHP class link is not working

https://stackoverflow.com/questions/7549015/php-create-subdomain-over-cpanel-api


Solution

  • I believe that you are not looking fte the LiveAPI since the LiveAPI is for developing inside cPAnel/WHM. The LiveAPI is for creating plugins inside the cPanel and WHM interfaces.

    If you are looking to add a subdomain to your account, the JSON/XML API's are much more suited to your task. If possible use the JSON api since cPanel Docs cite it as the preferred API due to it being faster than the XML api. To add a subdomain using the JSON/XML APIs you would use the following API call:

    XML:

    https://domain.tld:2083/xml-api/cpanel?cpanel_xmlapi_func=addsubdomain&cpanel_xmlapi_module=SubDomain&cpanel_xmlapi_version=2&domain=sub&rootdomain=maindomain.tld

    JSON:

    https://domain.tld:2083/json-api/cpanel?cpanel_jsonapi_func=addsubdomain&cpanel_jsonapi_module=SubDomain&cpanel_jsonapi_version=2&domain=sub&rootdomain=maindomain.tld

    In the above string the arguments that you will need to modify are:

    • domain (string) - The local part of the subdomain you wish to add. (e.g. 'sub' if the subdomain's is sub.example.com) This value should not include the domain with which the subdomain is associated.
    • rootdomain (string) - The domain to which you wish to add the subdomain.

    Below is further documentation including how to integrate these API commands into your php scripts and how to authorize for the API.