I am trying to find a php code to make a subdomain and auto install a cms for the sub account for my user. this subdomain will not have a cpanel just the cms I am making.
-
1Have you tried anything yet? I just did a Google search and found multiple results. – Piccolo Feb 15 '13 at 00:38
-
I looked at all those and it is not what i m looking for – Alan Bell Feb 15 '13 at 00:51
1 Answers
Your question betrays your lack of understanding of how DNS and webservers work. For a car analogy it's like asking "trying to get a diesel-powered car to make a transatlantic flight by solar power".
I'll start from the top:
DNS
A "subdomain" is any DNS label that is a child of another. In most cases this is a third-level domain (the second-level being something like "google.com" of the top-level ".com" domain, so a possible subdomain is "www.google.com" or "something.google.com"). Remember there is absolutely nothing inherently special about the "www." label.
A subdomain label is usually an "A
" or "CNAME
" record that maps a name (e.g. "www" or "ftp") to an IP address, or an "AAAA
" record in the case of IPv6.
Subdomains are stored in a DNS server's "zone file" or returned from a dynamic DNS server.
Websites
A "website" is an entirely abstract and virtual construct that depends on the web-server software. Most traditional webservers (Apache, IIS) define a website as a physical filesystem directory (e.g. "C:\sites\foobar.com") that corresponds to the root "/
" path that is associated with one or more network bindings, a network-binding is usually a host IP address (where each website has its own or shares an IP address), a domain-name "host-header
" (browsers send the requested URI's domain name to the server so the server can differentiate between multiple websites bound to the same IP address), or an SSL certificate (this is less true nowadays, but until recently there could only be one SSL-secured website per IP address for technical reasons).
Now as I said, a website can be associated with multiple domain names, e.g. how Google's website is the same if you go to "www.google.com" or "google.com". Similarly a webserver can also simultaneously host multiple websites simultaneously, all with different domain-name bindings.
PHP
Finally, PHP is a scripting language and environment that runs in the context of a web-server that is used to generate HTML that is returned to the client. PHP can perform filesystem and database IO and processing logic however it is primarily request-driven. PHP can also be used in a command-line environment as an alternative to Perl .
So what do you want?
So given what I've just described, what you've asked is completely ambiguous. Here are the possibilities of what you could mean:
- Write a PHP script that has the ability to reconfigure your Apache webserver to create a new website definition with a binding to a subdomain?
- Write a PHP script that has the ability to reconfigure your DNS server to create a new subdomain A/AAAA/CNAME record?
- Write a PHP-based website that acts on the
$_SERVER["HTTP_HOST"]
header? Such as a joke website that handles any subdomain request (e.g. "yournamehere.loves.me"). Note that this only works if you have a DNS server that supports wildcards. BIND and Windows' DNS Server does not support this. Your webserver will also need to support wildcard host-headers or bind your website to an IP address. - Any or all of the above.

- 141,631
- 28
- 261
- 374
-
Also, if you want to do the 3rd one, check out [this question](http://stackoverflow.com/questions/5292937/php-function-to-get-the-subdomain-of-a-url/14555210#14555210) to have PHP identify the subdomain. – Piccolo Feb 15 '13 at 00:56
-
4
-
I think the 3nd option: Write a PHP-based website that acts on the $_SERVER["HTTP_HOST"] header? Such as a joke website that handles any subdomain request (e.g. "yournamehere.loves.me"). Note that this only works if you have a DNS server that supports wildcards. BIND and Windows' DNS Server does not support this. Your webserver will also need to support wildcard host-headers or bind your website to an IP address. I know a website the is doing what i want. it is enjin.com – Alan Bell Feb 15 '13 at 01:04
-
@AlanBell with respect, it sounds like you don't even know what you want to achieve in the first place, rather than just not knowing how you want to get there. – Dai Feb 15 '13 at 01:08
-
I know what I want to achieve I just did not think it was necessary for you all to know so i just saved the boring details and jumped to the question. the about web site ( enjin.com ) i said is exactly what i want to achieve. so go there and get a free account and you will see what you get. I did not know how to word my question sorry. – Alan Bell Feb 15 '13 at 01:17