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.

HELP Implement Cluster Remote Access into PHP?

Discussion in 'cPanel Developers' started by Alex LD, Jul 30, 2010.

  1. Alex LD

    Alex LD Registered

    Joined:
    Jul 30, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    I'm trying to get a custom php script to create a database on my cPanel/WHM ran server. Its will create a database, insert/create the correct Database and its gonna upload files. (basically and install script)


    PHP:
    $objCon mysql_connect("localhost","DB USERNAME","PASSWORD"); 
    The method above doesnt' work and says access is denied, Even when I've enabled all the permissions or the user, so I'm assuming It would have to be a Root MySQL User? Is there such a thing?

    My programmer wants that to do it, but I know that that is not allowed on many servers including mine because its a security risk.

    I'm trying to tell him to try Cluster remote access key and use that, but neither of us know how to implement that into the PHP code to create it.


    Would this work? Are there any other alternatives.
     
  2. 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 Alex,

    You should use our APIs to had databases and database users for cPanel accounts. Using the MySQL CLI or direct connections via mysql_connect (or other PHP methods) to create or delete databases and users is general not wise on a cPanel server. This is bad because cPanel does other things that help keep the databases and users in-sync with the cPanel account. If you just modify MySQL directly, you could make certain database related parts of cPanel not work as expected.

    If you're just adding or manipulating data within a pre-existing database that you have access to (like adding a row or a table), then mysql_connect is okay to use in your script. And in the case that your script is not being executed on your cPanel server, then yes, you'd need to setup a MySQL remote access grant. You can do this in the cPanel interface (documented here). If you have root access and which to provide remote access to the server for MySQL root account, then you can do that in WHM SQL Services (documented here).

    You should look at using the xml-api PHP client class. There are many forum threads about using it for database creation.

    Basically, the xml-api PHP client class allows you to make your our PHP script that can remotely (or locally) log into your cPanel server and perform specific WHM or cPanel actions. All cPanel actions (API1 or API2 calls) will need a cPanel user name. In your example, it would be the cPanel account that will have access to the database.

    The PHP client class can use regular user/password or root/remote access hash (found in WHM >> Cluster/Remote Access; documented here).

    Please take a look at the following documentation. If you have any specific questions, search the forum and if you don't see a thread that addresses your issue, fill free to create a new one.

    The xml-api PHP client class (tarball with class and example code):
    http://sdk.cpanel.net/lib/xmlapi/php/cp_xmlapi_php_v1.0.5.tar.gz

    The main forum post about how to use the PHP client class:
    http://forums.cpanel.net/f42/xml-api-php-class-version-1-0-a-136449.html

    How to send requests to the xml-api binary on a cPanel/WHM server (this is good information, but the PHP client class can do this for you):
    XML and JSON APIs

    How to send API1 and API2 calls to the xml-api binary (this is good information, but the PHP client class can do this for you):
    CallingAPIFunctions < AllDocumentation/AutomationIntegration < TWiki

    The API1 MySQL calls for creating and managing databases (you'll need to read this to know what the function names are and the required parameters):
    ApiMysql < ApiDocs/Api1 < TWiki

    Regard,
    -DavidN
     
  3. Alex LD

    Alex LD Registered

    Joined:
    Jul 30, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Thanks David I will look into it!
     
Loading...

Share This Page