Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    1

    Default how can we create subdomain through php dynamically

    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. #2
    cPanel Partner NOC cPanel Partner NOC Badge
    Join Date
    Mar 2003
    Location
    NC
    Posts
    725
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    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. #3
    BANNED
    Join Date
    Jun 2005
    Location
    Wild Wild West
    Posts
    2,025

    Exclamation

    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.
    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 mydomain.com
        ServerAlias www.mydomain.com  *.mydomain.com
    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.
    Last edited by Spiral; 07-18-2009 at 08:16 PM.

  4. #4
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    10,718
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    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. #5
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    10,718
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by sweta View Post
    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.
    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.

Similar Threads & Tags
Similar threads

  1. Create subdomain and FTP user account using PHP
    By MarkCool in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 12-01-2008, 01:52 PM
  2. create subdomain (using php)
    By SIFE in forum New User Questions
    Replies: 1
    Last Post: 06-23-2008, 02:51 PM
  3. Create SUBDOMAIN via PHP script
    By mlotfi63 in forum New User Questions
    Replies: 0
    Last Post: 12-29-2006, 12:28 AM
  4. Create subdomain with a php script
    By mahdionline in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 03-03-2004, 12:45 AM
  5. Create Subdomain With PHP
    By erictham in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 02-04-2004, 09:36 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube