duankuangxie9070 2013-12-06 20:51
浏览 38
已采纳

如何通过cpanel / whm API创建数据库?

I have the API creating an account on a dedicated server for a user fine, creating email addresses fine as well, however when I attempt to create an mysql database through the API, I get error message 'Access Denied', even though access is root.

The code I am trying to use:

$xmlapi = new xmlapi($host);
$xmlapi->password_auth("".$root_user."","".$root_pass."");    
$xmlapi->set_debug(1);
$xmlapi->set_output('array');
$xmlapi->set_port('2083'); 
//create database
$createdb = $xmlapi->api1_query($root_user, "Mysql", "adddb", array($dbname));

and the error data I am getting back:

URL: https://delta1.powerstorm.net:2083/xml-api/cpanel
DATA: cpanel_xmlapi_user=root&cpanel_xmlapi_module=Mysql&cpanel_xmlapi_func=adddb&cpanel_xmlapi_apiversion=1&arg-0=site
Authentication Header: Authorization: Basic cm9vdDphY3Jtp3MxOTY1

RESPONSE:
 <?xml version="1.0" ?>
<cpanelresult>
    <error>Access denied</error>
    <data>
        <result>0</result>
        <reason>Access denied</reason>
    </data>
</cpanelresult>

Any ideas on why this one part is failing when everything else works fine?

  • 写回答

2条回答 默认 最新

  • dov11020 2013-12-08 17:10
    关注

    You can not use root account to create cPanel databases. Also, make sure to set the port. 2082 is for unencrypted connection, while 2083 is for encrypted. You can also use the IP address in place of "domainName".

    Check the following code as it should work.

    require("xmlapi.php");
    
    $opts = [
        "userName"   => "UserUserName",      //+++ Replace UserUserName
        "password"   => "UserPassword",      //+++ Replace UserPassword
        "dbPassword" => "DatabasePassword",  //+++ Replace DatabasePassword
    ];
    
    $xmlapi = new xmlapi("domainName");   
    $xmlapi->set_port( 2083 );   
    $xmlapi->password_auth($opts['userName'],$opts['password']);     
    
    $cpaneluser=$opts['userName'];
    $databasename="dbName";
    $databaseuser="dbUserName";
    $databasepass=$opts['dbPassword'];
    
    // database creation    
    $createdb = $xmlapi->api1_query($cpaneluser, "Mysql", "adddb", array($databasename));   
    // user creation
    $usr = $xmlapi->api1_query($cpaneluser, "Mysql", "adduser", array($databaseuser, $databasepass));   
    // adds user to database
    $addusr = $xmlapi->api1_query($cpaneluser, "Mysql", "adduserdb", array("".$cpaneluser."_".$databasename."", "".$cpaneluser."_".$databaseuser."", 'all'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用