7

I am creating an application in a LAMP stack and I want to provide the user with the ability to use their own domain instead of a subdomain of my site. eg.

Instead of: http://some_user.mysite.com

They will use: http://store.some_user.com/

I know there are a few companies that provide this using CNAME records. (http://help.bigcartel.com/articles/14-using-a-custom-domain) however I'm not sure how they achieve this end-to-end.

My questions are:

  1. What is this process called? (So I can research this further if need be)

  2. What do I need to do to provide this? ie. What do I need to do on the DNS, apache and php side to get this working?

Any advice, links or code snippets would be greatly appreciated.

Thanks


UPDATE

So far I have been able to set up the wildcard DNS entry however I'm still having problems with the CNAME record resolving to the other domain. eg.

http://store.weareunified.com/ -> http://weareunified.joshstuart.com.au/

weareunified.com (this is a test user host) DNS

weareunified.com. A 111.67.3.227
store CNAME weareunified.joshstuart.com.au.

joshstuart.com.au (This is the primary application host) DNS

joshstuart.com.au. A 111.67.3.227
* CNAME joshstuart.com.au.
0

5 Answers 5

7
+50

I have this set up using LAMP and it works very well. Here's how I did it:

  1. The target server with my application on it is on a normal A record (sub)domain. So in your case I'm assuming you have the application running on joshstuart.com.au.
  2. The client needs to change their DNS entry for store.weareunified.com to CNAME to joshstuart.com.au.
  3. The Apache server has a virtualhost without a domain specification (in my case), simply a <VirtualHost *:80>

That's it. There are currently 70+ domains that CNAME to the main application domain, and they each serve their individual site as needed (without a redirect, etc).

6
  • Actually I see the problem I think. <VirtualHost *>ServerName cPanel102-469.hosting24.com.au DocumentRoot /usr/local/apache/htdocs</VirtualHost> So I should be pointing this to the docroot of my joshstuart.com.au domain? Commented Mar 9, 2011 at 21:56
  • Yes, the DocumentRoot should point to your application. Also, don't include a ServerName specification, because it will listen to any domain that CNAMEs to it, not just cPanel102-469.hosting24.com.au.
    – Berklee
    Commented Mar 10, 2011 at 9:49
  • Thanks for your help! The default virtualhosts was holding me back. Commented Mar 11, 2011 at 22:53
  • you can make setup really quick if you use dynamic vhost, so you can serve request from different directory for different customer. Some cases, clients are using different versions of same application, special/dedicated hosting for a client, modified version for some clients.
    – EGL 2-101
    Commented Mar 12, 2011 at 19:43
  • Ah cool that is something to keep in mind. Currently I want everyone to be running the same version of the application. Commented Mar 13, 2011 at 1:15
5

Actually, you dont need to do anything.

Your users need to get their DNS provider add a CNAME record that basically maps http://app.some_user.com/ to http://some_user.app.com.

Any DNS client that look for http://app.some_user.com/ is told to look for http://some_user.app.com instead, and so this is a DNS/client issue, not a server issue.

Amazon recommend this very technique for users of EC2 servers.

Please note that CNAME records have a limitation, they cannot be assigned to the root of a domain - your users cannot assign http://some_user.com/, only http://app.some_user.com/ as a CNAME.

4
  • One thing worth noting is that from your side of things, @Josh, you'd use a wildcard DNS entry for *.app.com to avoid having to play with your own DNS records every time you add a customer. But for the user's own custom address, I'm with Rami, it's their domain and they'll be managing it, either with a CNAME or with an A record pointing at your actual server's IP. Commented Feb 15, 2011 at 12:34
  • Thanks for your help. Excuse my ignorance but will a cname act like a "forwarder" or a url alias. eg. does app.some_user.com/products appear in the address bar like that or will it convert to some_user.app.com/products ? Commented Feb 15, 2011 at 20:43
  • It will appear as app.some_user.com/products, which I guess is what you want :-)
    – Rami C
    Commented Feb 16, 2011 at 9:25
  • Yes that is what I want however I've given this a good shot but can't seem to get it to work. I've even set up a wildcard cname. Commented Feb 16, 2011 at 10:33
1

I have something similar which I did with the cpanel api2.

Basically, the user points his domain to my dns, and I use the api to park his domain on mine.

I store each user's domain in a database.

On a page load, I extract the http_host and compare it to my database to see if the domain exists. I then load the page based on the users settings(I'm serving all pages from the same script) and database entries.

To reduce database load, I save the info in a session identifying the host. I can then check this on each subsequent load instead of checking the database each time.

3
  • This is pretty much what I have done except instead of parking their domain I'm using a wildcard entry on the primary application host (joshstuart.com.au) and a CNAME entry on the users host (for testing weareunified.com). However it isn't resolving correctly. All the DB side and site recognition via http_host is ok. Do you have any links/code for this api solution? Commented Mar 7, 2011 at 21:04
  • Concerning the api, there is a class on the cpanel website which implements it. There is however an error with it. docs.cpanel.net/twiki/bin/view/AllDocumentation/… Concerning your app, does each user have a directory or the same script serves him? Are you trying to link the users domain with your subdomain? If so, that won't work since using wildcards, the subdomain is not specific and thus you cannot point a domain to a subdomain which is not explicitly defined in your DNs. Commented Mar 7, 2011 at 23:08
  • Your best bet is to use domain parking since the domain will then land on your site And you can do the necessary checks. I'm assuming you are trying to get the subdomain which the domain has landed on. Commented Mar 7, 2011 at 23:11
0

The other possibility is to actually be the user's DNS host and handle all the records. You can get open source solution for this. (But you might need own two DNS servers on different subnets).

0

There's a couple of different parts here - getting the DNS entries set up, and then getting Apache to respond to the request.

Do you have the CNAME set up properly for the customer? Note, you can't set up a CNAME on weareunited.com, it has to be on store.weareunited.com, or some other hostname that is not the root domain.

It sounds like you may not understand how CNAME's work. An overly simplified version is, when a user requests store.weareunited.com, their local nameserver (e.g. the nameserver that is in the end user's ISP. For me on Comcast, it's usually a Comcast NS in Beaverton, OR. This is assuming the local nameserver hasn't already resolved the hostname and doesn't have it in cache) will query the root nameservers to determine who is responsible for the domain. The local namserver will then query the domain nameserver to get the record. The record could be an A record, which is an IP address, or a CNAME, which points to another hostname.

When the local namesever gets the CNAME, it will then run through this process again to get the A record. Once it finally has the A record with the IP address, it will hand back the IP address to the end user's browser, and the web browser will make a request to the IP address.

The end result is the web browser gets an IP address, and it then makes a request to this IP address using the original hostname as the host header - store.weareunited.com. So Apache should be set up to receive requests for the hostname store.weareunited.com.

PHP won't care what the hostname is, unless you are checking environment variables like $_SERVER...

You can get your customers to set up a CNAME to joshstuart.com.au. You could certainly create additional hostnames like weareunited.joshstuart.com.au, or do a wildcard, and then have your customers set the CNAME target to that unique hostname, but why bother? I would just have:

store.weareunited.com.  3600 IN CNAME   joshstuart.com.au.

As long as joshstuart.com.au then hands out an IP address to your web server, the CNAME will work. As I mentioned above, Apache will see a request coming in for store.weareunited.com, so you either need to set up a virtual host for that hostname, or create a generic vhost as Berklee mentions (although I'm not sure what apache directives you would use to ensure the request is then mapped to the proper files for the domain...).

1
  • Thanks for the explanation. Unfortunately as it turns out I was having trouble with the virtualhost side of things. Commented Mar 13, 2011 at 1:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.