Create cpanel database through php script

后端 未结 4 2088
囚心锁ツ
囚心锁ツ 2021-02-06 14:33

Im trying to automate the installation of some custom software using cpanel/whm and postwwwacct php script.This requires files to be copied to the users public_html folder then

4条回答
  •  自闭症患者
    2021-02-06 15:16

    require("xmlapi.php"); // this can be downlaoded from https://github.com/CpanelInc/xmlapi-php/blob/master/xmlapi.php
    $xmlapi = new xmlapi("your cpanel domain");   
    $xmlapi->set_port( 2083 );   
    $xmlapi->password_auth($opts['user'],$opts['pass']);    
    $xmlapi->set_debug(0);//output actions in the error log 1 for true and 0 false 
    
    $cpaneluser=$opts['user'];
    $databasename="something";
    $databaseuser="else";
    $databasepass=$opts['pass'];
    
    //create database    
    $createdb = $xmlapi->api1_query($cpaneluser, "Mysql", "affffdb", array($databasename));   
    //create user 
    $usr = $xmlapi->api1_query($cpaneluser, "Mysql", "adduser", array($databaseuser, $databasepass));   
    //add user 
    $addusr = $xmlapi->api1_query($cpaneluser, "Mysql", "adduserdb", array("".$cpaneluser."_".$databasename."", "".$cpaneluser."_".$databaseuser."", 'all'));
    

    The above code worked for me! Need to make sure that you are using a cpanel user/pass not root and also that you are using port 2083

提交回复
热议问题