Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2012, 10:39 AM   PM User | #1
bacterozoid
Regular Coder

 
bacterozoid's Avatar
 
Join Date: Jun 2002
Location: USA
Posts: 486
Thanks: 23
Thanked 35 Times in 35 Posts
bacterozoid is an unknown quantity at this point
Different document root per subdomain

I used to be on shared hosting with cPanel. I had multiple subdomains that all pointed to different locations:

a.domain.com -> /www/versions/2
b.domain.com -> /www/versions/3
c.domain.com -> /www/versions/3
d.domain.com -> /www/versions/1

I did this by using cPanel to create the subdomain every time, then set the document root for each of them. That worked fine...using different document roots let me easily include files without worrying about which version to include them from.

I could do this:

PHP Code:
include file.php 
instead of this:

PHP Code:
include $_SERVER['document_root'] . '/www/versions/' $version '/file.php'
Now I've moved over to a VPS and want to do this right. Individually setting up subdomains is slow, so I intend to use a wildcard so that all subdomains point to my server. I don't think I can set different document roots this way, though. I have an entry in the database for each sudomain with a column for version...what's the best way to set this up?

I'm thinking that I hit the database to check the version, then do something like this, but I'm not confident it's the right way:

PHP Code:
define('CLIENT_DOCUMENT_ROOT'$_SERVER['document_root'] . '/www/versions/' $version); 
Edit: I should add that this all has to be done automatically. I can't edit the http.conf and restart Apache every time a new subdomain is added.

Last edited by bacterozoid; 01-29-2012 at 01:45 PM..
bacterozoid is offline   Reply With Quote
Old 01-30-2012, 10:54 PM   PM User | #2
bacterozoid
Regular Coder

 
bacterozoid's Avatar
 
Join Date: Jun 2002
Location: USA
Posts: 486
Thanks: 23
Thanked 35 Times in 35 Posts
bacterozoid is an unknown quantity at this point
Well, as far as I can tell this is simply not possible. There are a lot of neat ways to dynamically set the document root, but that expects that you can use the URL to determine the document root, like:

a.domain.com -> /www/versions/a
b.domain.com -> /www/versions/b
c.domain.com -> /www/versions/c
d.domain.com -> /www/versions/d

All the dynamic methods fall apart when I want this:

a.domain.com -> /www/versions/2
b.domain.com -> /www/versions/3
c.domain.com -> /www/versions/3
d.domain.com -> /www/versions/1

One option is to kill the versions, and just use one version for everybody. I don't want this because then I can't easily move a subset of users to a new version for testing.

The other option, and the best I can come up with right now, is to just use a custom defined variable in PHP on every single page that defines the "version document root". It works OK, but that means I have to prefix every single image, javascript file, css file, etc, with this variable. I also can't have any static HTML pages that have any of these elements because I need PHP to help figure it out. That means I can't leverage caching at all.

Does anyone have any thoughts? Finding a solution to this issue is very important to me and nothing I've found or thought up is any good.


Edit: For now I've settled on this: All users will, by default, point to the most recent production version. I'll set this by pointing *.domain.com to that folder in httpd.conf. I'll override my development domain to point to the development folder. Any time I want to have a few users try out the new version, I'll manually add their subdomains to http.conf to point at the new version. When testing is completed for that version, I'll remove the custom entries and point *.domain.com at the new version.

It's not really perfect, but the best I can come up with right now. I'm still open to other ideas.

Last edited by bacterozoid; 01-30-2012 at 11:07 PM..
bacterozoid is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:36 PM.


Advertisement
Log in to turn off these ads.