skip to Main Content

I am trying to create subdomains and databases using PHP in Plesk. I am looking at their API documentation, but I can’t figure out how to do both of these things, so if you could help me, it would be great!

2

Answers


  1. a little bit later. To create a subdomain:

    /usr/local/psa/bin/subdomain -c %subdomain% -www-root %subdomain% -php true -ssi true -d %domain%
    

    The database I usually create directly to MySQL with CREATE DATABASE.

    Login or Signup to reply.
  2. There is no able to create database for subdomain, only for domain/subscription.
    Here the API request:

    <packet version="1.6.3.0">
    <database>
    <add-db>
       <webspace-id>2</webspace-id>
       <name>MyBase</name>
       <type>mysql</type>
    </add-db>
    </database>
    </packet>
    

    where webspace-id – it’a id of domain(not a subdomain) of your subdomain.

    If you try to create db on subdomain, you will receive following response:

    <?xml version="1.0" encoding="UTF-8"?>
    <packet version="1.6.3.0">
      <database>
        <add-db>
          <result>
            <status>error</status>
            <errcode>1023</errcode>
            <errtext>This object can be created **only in a webspace**.</errtext>
          </result>
        </add-db>
      </database>
    </packet>
    

    So, first of all you need to get info about parent domain of subdomain:

    <packet version="1.5.2.0">
    <subdomain>
    <get>
       <filter>
          <name>sub.domain.com</name>
       </filter>
    </get>
    </subdomain>
    </packet>
    

    Then get id of parent:

    <packet version="1.6.3.0">
    <webspace>
    <get>
       <filter>
          <name>domain.com</name>
       </filter>
       <dataset>
          <gen_info/>
       </dataset>
    </get>
    </webspace>
    </packet>
    

    Then create database on parent using received id.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search