Creating a sub domain using php?

Discussion in 'PHP' started by bonjo, Aug 6, 2006.

  1. #1
    Hi all,

    I need to create a sub domain using php...

    your thoughts....

    bonjo
     
    bonjo, Aug 6, 2006 IP
  2. haentz

    haentz Peon

    Messages:
    78
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2

    First of all your DNS-Entry needs to have a "catch-all-subdomains" root entry (like "*.example.com").

    Now subdomains have to be defined in the Configuration of the webserver. I guess you are running on Apache. I don't know exactly but probably it is possible to define subdomains in the .htaccess file in your webroot. Otherwise you have to use the httpd.conf of the server, which might not accesible to you, if you are on a shared hosting environment. Your PHP-Script has to add a VirtualHost entry to either one of these files:

    <VirtualHost *>
    ServerName subdomain.domain.com
    DocumentRoot /home/httpd/htdocs/subdomain/
    </VirtualHost>


    Just some quick thoughts...

    Kind regards, Hans
     
    haentz, Aug 6, 2006 IP
  3. bonjo

    bonjo Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thx for your reply hans,

    could you please suggest some more simpler techniques....
     
    bonjo, Aug 6, 2006 IP
  4. haentz

    haentz Peon

    Messages:
    78
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Probably experimenting with Rewriting rules in the .htaccess file could work...


    Edited:
    Try setting up your subdomain like this in the .htaccess file:

    RewriteCond %{HTTP_HOST} subdomain.example.com $ [NC]
    RewriteCond %{REQUEST_URI} !/subdomain_directory/
    RewriteRule ^(.*)$ subdomain_directory/$1 [L]
     
    haentz, Aug 6, 2006 IP
  5. sandossu

    sandossu Guest

    Messages:
    2,274
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    0
    #5
    this is not working
     
    sandossu, Aug 7, 2006 IP
  6. prometheus

    prometheus Banned

    Messages:
    880
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #6
    after editing dns like *.mysite.com

    add htaccess here,

    So you can use your subdomain as a variable.
     
    prometheus, Aug 7, 2006 IP
  7. coderlinks

    coderlinks Peon

    Messages:
    282
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Try adding his to the top of your .HTACCESS file:

    Options +FollowSymLinks

    Then create symbolic links to the directories you want to make subdirectories by running the 'ln' *nix command. You can use the functions at : http://www.php.net/exec for this.

    Thomas
     
    coderlinks, Aug 8, 2006 IP
  8. ottodo

    ottodo Guest

    Messages:
    2,055
    Likes Received:
    70
    Best Answers:
    0
    Trophy Points:
    0
    #8
    How can I manage this from my Cpanel??
     
    ottodo, Aug 13, 2006 IP
  9. ajscottsr

    ajscottsr Peon

    Messages:
    388
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Is this a dedicated server or are you on a host? Which host would be helpful as well? It's possible you will need the assistance of your web host.
     
    ajscottsr, Aug 13, 2006 IP