Forum Moderators: phranque

Message Too Old, No Replies

Q: How do I create subdomains using PHP?

Automatically when an user signs up.

         

Daemon

7:54 am on Jun 12, 2004 (gmt 0)

10+ Year Member



I would like to know how do I create subdomains using PHP?

Basically, I want a new user that signs up to my website to have a homepage: username.domain.com
as well as sub directories as: username.domain.com/journal

If anyone knows, please let me know, I couldn't find the solution.

Thanks!

RonPK

12:58 pm on Jun 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Let's assume that you're not talking about real subdomains in DNS. Let's also assume your webserver software is something like Apache 1.3.x. If so, what needs to be done:

1. create the appropriate web root directory, for example /home/sites/username/web , and any subdirectories you wish
2. edit httpd.conf, add a new virtual host section
3. final step: restart httpd

In a normal Linux server setup, PHP/Apache does not have the necessary permissions to do all this. You'll probably need some shell voodoo like sudo to make it work.

Daemon

4:54 pm on Jun 12, 2004 (gmt 0)

10+ Year Member



hmmm.......perhaps what I have heard of in other places, could mod_rewrite be used to fake a subdomain?

Liek the PHP script would simply create the user, create a subdir with the username, open .htaccess append a line, close.

Would that work? How would I do a mod_rewrite for that?

Thanks!

moltar

5:31 pm on Jun 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you can have wildcard subdomains. Meaning that anything before the .yourname.com would always work. Then you could catch it with mod_rewrite.

jdMorgan

5:45 pm on Jun 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Daemon,

This thread [webmasterworld.com] about rewriting subdomain requests to subdirectories might be useful to you.

Jim