How to create an SaaS Application?
Asked Answered
H

1

8

I don't know how else to say it so I'm just going to explain my ideal scenario and hopefully you can explain to me how to implement it...

I'm creating an application with the Zend Framework that will be hosted with DreamHost. The application will be hosted on its own domain (i.e. example-app.com). Basically, a user should be able to sign up, get their own domain sampleuser.example-app.com or example-app.com/sampleuser which points to, what looks like their own instance of the app, which is really a single instance serving up different content based on the url.

Eventually, I want my users to be able to create their own domain (like foobar.com) that points to sampleuser.example-app.com, such that visitors to foobar.com don't notice that the site is really being served up from example-app.com.

I don't know how to do most of that stuff. How does this process work? Do I need to do some funky stuff with Apache or can this be done with a third party host, like DreamHost?

Update: Thanks for the advice! I've decided to bite the bullet and upgrade my hosting plan to utilize wildcard subdomains. It's cheaper than I was expecting! I also found out about domain reseller programs, like opensrs.com, that have their own API. I think using one of these APIs will be the solution to my domain registration issue.

Homologue answered 16/6, 2009 at 6:53 Comment(0)
C
10

Subdomains are easy. In hosting environements, in most cases, apache is configured to catch all subdomain calls below the main domain. You just need to have a wildcard DNS defined, so *.example-app.com are pointed to IP of your server. Then your website should catch all calls to those subdomain names.

Other domains are hard. They need to be configured as virtual hosts in Apache - see http://httpd.apache.org/docs/1.3/vhosts/name-based.html - that means it will be difficult to automate that, especially in hosting environement - unless your host gives you some API to do just that (easy and more feasible scenario would be to have a distinctive IP assigned to your website, then you can catch all with your Apache - it's probably possible to configure using your hosting control panel or works out of the box - and then just point DNS servers to your IP).

Then, after you have configured your Apache to point all necessary calls to your website, you can differnetiate application partitions per subdomain in this way:

  • get the host header from HTTP request
  • have a database table containing all subdomain names you're serving
  • make a lookup to that database table to determine instance, or user, id and use it later for filtering data / or selecting a database, if you'll go with a "database per application instance" schema.

Good luck :)

Considerable answered 16/6, 2009 at 7:8 Comment(5)
I run an application with a similar architecture and it works as described. Be sure to check that you can set up a wildcard host (*.domain.tld) if using shared hosting.Deflate
I am using shared hosting, and wildcard subdomain is not supported. I could upgrade my account and petition for wildcard support, but it doesn't seem worth it. Can this be done in a way that doesn't use the wildcard? Thanks!Homologue
If you are willing to add every host header to you website (or have a way to automate it - again, check for some API from your host) - then yes, it is possible. Your website has to answer to calls by those all addresses somehow - wildcard DNS (or assigned IP for "any domain" scenario) would be optimal. If your host doesn't give you such options, then change it.Hollyhock
If you're serious about developing this, there's no excuse to skimp on hosting. You can spend all your time trying to work around the limitations of a feature restricted shared hosting environment, or you can realize that it's never going to work for your needs and move out now.Diagnose
I have to agree with Sean, if you fancy a challenge. You can purchase an entry level Virtual Private Server for around £20 and manage the whole thing yourself.Deflate

© 2022 - 2024 — McMap. All rights reserved.