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.

how can we create subdomain through php dynamically

Discussion in 'General Discussion' started by sweta, Jul 18, 2009.

  1. sweta

    sweta Registered

    Joined:
    Jul 1, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    hello friends,

    i want to create subdomain through php i have read many forum and i found that i have to place some code in htaccess file but i unable to find htaccess file in cpanel plz help me.
     
  2. eth00

    eth00 Well-Known Member
    PartnerNOC

    Joined:
    Mar 30, 2003
    Messages:
    723
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    NC
    cPanel Access Level:
    Root Administrator
    You would need an IP based site to do this.

    The htaccess can be created within public_html/.htaccess , simply place the file there and it should work.
     
  3. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    On the contrary, the account DOES NOT need to have it's own dedicated IP (IP based account) but the virtualhost and DNS do need to be setup to operate with a wildcard. Setting up fancy re-writes won't be of much use if Apache does not know to accept the site handling for the subdomain in the first place!

    Something like this in /usr/local/apache/conf/httpd.conf:
    Code:
        ServerName [url=http://forums.cpanel.net]mydomain.com[/url]
        ServerAlias [url=http://forums.cpanel.net]www.mydomain.com  *.mydomain.com[/url]
    
    And in your DNS zone file in /var/named/mydomain.com.db:
    Code:
    * IN A 1.1.1.1
    
    (Obviously mydomain.com would be replaced with your own domain and 1.1.1.1 would be replaced by the IP being used on the account irregardless whether it is using the server shared IP or it's own IP)

    Don't forget that you would want to restart both Apache and DNS servers after making these updates and you will also need to run the Cpanel Apache distiller script so that your changes are not automatically deleted later.

    As for .htaccess, you can use rewrites to detect what HTTP_HOST has been used to connect and parse off different content depending on the URL used to connect or in the reverse rewrite folder addresses to neater looking subdomains. You can also do this through script as well in the index but neither will work unless you have wildcard DNS and wildcard host setup for the account.
     
    #3 Spiral, Jul 18, 2009
    Last edited: Jul 18, 2009
  4. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Another solution I've seen is to create a wildcard subdomain in cPanel that points to a folder, and in that folder have an index.php that controls what to display when a specific subdomain is requested. However, depending on what you're doing, this may or may not be a good solution for what you have in mind.
     
  5. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Yet another solution is to use our APIs. You could build a PHP app that calls the cPanel APIs via your cPanel account and use those to create/remove subdomains as needed. I'll be glad to introduce you to how to use our APIs and assist you with using our APIs.
     
Loading...

Share This Page