The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Questions

Discussion in 'cPanel Developers' started by S P E E D, Jun 13, 2011.

  1. S P E E D

    S P E E D Member

    Joined:
    Jun 13, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Hello
    Can create a database and add user , Change Permissions to Directories and add Password Protect to Directories by useing php ?

    if yes , how ?
    Note I am not root user
     
    #1 S P E E D, Jun 13, 2011
    Last edited: Jun 13, 2011
  2. fi77i

    fi77i Well-Known Member

    Joined:
    Aug 20, 2008
    Messages:
    57
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Uruguay
    cPanel Access Level:
    Root Administrator
    I do not understand very well what you want. But if you are trying to create a db with users on it change perms and set password protected directories you can do it using you panel.

    Check the documentation here:

    MySQL Databases
    File Manager
    Password Protect Directories

    Hope this info can help you.

    Cya.
     
  3. S P E E D

    S P E E D Member

    Joined:
    Jun 13, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    i want do it , by php not cpanel
     
  4. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi SPEED,

    If you're trying to make an application, script, or web application on your site, you should probably use the PHP XML-API client class to make cPanel API calls (documentation for using the XML/JSON-API interface for cPanel APIs).

    If you're writing a cPanel Plugin or an application that lives within a cPanel theme directory, you can use LivePHP to make cPanel API calls

    fi77i is referencing the API calls that you will use when requesting cPanel to perform the manipulations that you mention.

    There should be plenty of forum threads related to using the XML-API client class for MySQL database management. There's also a blog article that discusses using the XML-API client class in a script (note, the article link to the full example is broke, but you can find the full example it here)

    Regards,
    -DavidN
     
  5. S P E E D

    S P E E D Member

    Joined:
    Jun 13, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    yes , i trying to make an application php can add db and user
    but Question can use PHP XML-API client class and i don't have root access
     
  6. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Yes, you can use the cPanel account password. When authenticating as a cPanel user, you need to use port 2083 (ssl) or 2082 (non-ssl).

    PHP:
    <?php
    include "xmlapi.php";

    $ip 'my.domain.com';
    $user 'dave';
    $user_pass 'secret!';

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth($user,$user_pass);
    $xmlapi->set_port('2083');

    $xmlapi->set_debug(1);  //for debugging

    $cp_account $user;

    $args = array(
        
    'cptest',
    );

    /**
     * This call will create the 'dave_cptest' database because we're working
     * against the 'dave' account.
     */
    $result $xmlapi->api1_query($cp_account'Mysql','adddb',$args);
    ?>
    Regards,
    -DavidN
     
  7. S P E E D

    S P E E D Member

    Joined:
    Jun 13, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    nice , but i want add user to db , and i have another Question

    can change Permissions to file or folder ?
     
  8. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Yes, you can add a user to a database too. You will first need to create the user with Mysql::adduser. Then you can give that user privileges to the database with Mysql::adduserdb.

    You can change file permission with the API2 Fileman::fileop call. This works for files within your home directory. You cannot change file ownership with an API call.

    -DavidN
     
    #8 cPanelDavidN, Jun 16, 2011
    Last edited: Jun 16, 2011
  9. S P E E D

    S P E E D Member

    Joined:
    Jun 13, 2011
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    hi ,
    i used this code but see error apper



    Warning: file_get_contents() [function.file-get-contents]: SSL: The operation completed successfully. in C:\xampp\htdocs\xmlapi.php on line 737

    Warning: file_get_contents() [function.file-get-contents]: SSL: The operation completed successfully. in C:\xampp\htdocs\xmlapi.php on line 737

    Warning: file_get_contents() [function.file-get-contents]: SSL: The operation completed successfully. in C:\xampp\htdocs\xmlapi.php on line 737

    Warning: file_get_contents() [function.file-get-contents]: SSL: The operation completed successfully. in C:\xampp\htdocs\xmlapi.php on line 737

    PHP:
    <?php

    /**
     * @author PHPDes7
     * @copyright 2011
     */

    include("xmlapi.php");
    $host "xxx.com";
    $cpuser "cpuser";
    $cppass "cppass";
    $db_name ="dbname";
    $db_user="dbuser";
    $db_pass="dbpassword";

    $xmlapi = new xmlapi($host);
    $xmlapi->set_port(2083);
    $xmlapi->password_auth($cpuser,$cppass);
    $xmlapi->set_debug(1);
    //create database
    print $xmlapi->api1_query($cpuser"Mysql""adddb"$db_name);
    //create user
    print $xmlapi->api1_query($cpuser"Mysql""adduser", array('user' => $db_user,'pass'=> $db_pass));
    //add user to database
    $xmlapi->api1_query($cpuser"Mysql""adduserdb", array(
                        
    'db' => $db_name,
                        
    'user'=> $db_user,
                        
    'SELECT INSERT UPDATE CREATE DELETE ALTER DROP'));  

    ?>
     
  10. TopCatHost

    TopCatHost Member

    Joined:
    Jun 27, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Passaic N.J. USA
    cPanel Access Level:
    Root Administrator
    Hello,

    MY Questions Or Request for Advise:

    I am relatively new to using C-panel and WHM (and later soon WHMPHP). I noticed that as a reseller I fet the following warning:
    Warning! You are logged in with the reseller or root password.

    I am basically wondering what I need to be worried about, naturally I have some ideas. I have logged in a "A Reseller" however I do have some of my own domains and websites to migrate over. I currently have access to a standard reseller, a master reseller and an Alpha reseller.

    I imagine that the migration of the websites might be more difficult with the standard reseller, however all the real functions get carried in C-panel it seems. I have set up name servers and and the domains will not be transferred.

    The entire tar archive for about 30 or so domains with about 15 small (mostly WordPress) websites is about 3 Gigabyte and then apparently there is another homedir which is about another GB.

    Just a simple overview of the migration, and can it be done using file manager or is FTP much better. Is there an order to do things, such as mysql databases 1st then files etc.
     
Loading...

Share This Page