php - 通过php脚本创建cpanel数据库

标签 php cpanel

我正在尝试使用 cpanel/whm 和 postwwwacct php 脚本自动安装一些自定义软件。这需要将文件复制到用户 public_html 文件夹,然后编辑配置并设置 eh 文件权限。到目前为止一切顺利,没有问题。在尝试创建数据库时遇到了一些问题。

    $db_create= $opts['user']. '_lol';  
    $db_host="immersion-networks.com";
    include("xmlapi.php");   
    $xmlapi = new xmlapi($db_host);    
    $xmlapi->password_auth("".$opts['user']."","".$opts['pass']."");    
    $xmlapi->set_debug(1);//output actions in the error log 1 for true and 0 false  
    $xmlapi->set_output('array');//set this for browser output  
    //create database    
    $createdb = $xmlapi->api1_query($opts['user'], "Mysql", "adddb", array($db_create));   
    //create user 
    $usr = $xmlapi->api1_query($opts['user'], "Mysql", "adduser", array($db_create, $opts['pass']));   
     //add user 
    $addusr = $xmlapi->api1_query($opts['user'], "Mysql", "adduserdb", array($db_create,$db_create, 'all')); 

其余代码运行正常,但没有创建数据库,也没有创建用户。 有什么想法吗?

最佳答案

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", "adddb", 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'));

上面的代码对我有用! 需要确保您使用的是 cpanel 用户/密码而不是 root,并且您使用的是端口 2083

关于php - 通过php脚本创建cpanel数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11989920/

相关文章:

php - 在 Lumen 或 Laravel 5 中更改时区

php - Foreach太慢

cpanel - 如何更改 cPanel 中显示的邮件服务器信息

shell - WHM/cPanel : Manage Wheel Group Users and SSK Keys access

php - 发生自动换行时通过 JavaScript 更改 DIV 的高度

php - 如何在 Symfony 的 url_for 帮助器中使用通配符?

php - 在 Magento 中,扩展 rest/products api 以检索返回列表中产品的标签和属性的性能如何?

email - 将电子邮件传送到解析器脚本时获取 "Error in argument 1, char 3: option not found"

php - 有没有办法用 Cron Job 加载页面?

linux - 如何在适用于 cPanel 或 CentOS 的 VPS 上安装 PDFTK?