Question

Advice needed on how to setup a SAAS service for a php based application

I have worked with a certain php and mysql based crm application for a while as a developer and know it inside out. I have an idea to offer an on-demand saas based hosted version where the client and can purchase a plan based on the number of users. They will simply click a button and this will automatically spin up and deploy a brand knew instance of the application for them and they will then be able to log in and use the software but wont have any access to the actual web space apart the ability to download a dump of there data anytime they want. It will automatically assign a sub-domain and email them their login details when its ready. I basically want it to be as autonomous as possible.

I think I have three possible ways to go about this:

We’ll use digital ocean as an example provider

I could have one or multiple VM’s or droplets and set up each user’s software in a different virtualhost - this way I can host multiple instances of the software on each droplet lowering costs.

Create a new droplet for each user - this provides additional flexibility and is easier to configure but is a bit more costly

Use Docker and scalable cloud hosting to set up each users software in a different container.

Out of all 3, number 3 is the most appealing to me but the one I know least about.

But realistically what is the best way to go about this?

The application can be quite database heavy if it has lots of data and users. Ill also have to consider that the clients can install additional custom modules in the the application and that Ill need a way to upgrade the version on mass when bug fix releases come out etc.

Regarding option 1, does such a script or software already exist that will let me create virtual hosts and deploy a php application within it automatically at the click of a button?

I know option 2 could be done using a snapshot of a droplet and some custom scripts using the Digital ocean api.

It sounds like you’ve got some solid options and already know the key differences between approaches.

Regarding option 1, does such a script or software already exist that will let me create virtual hosts and deploy a php application within it automatically at the click of a button?

I am sure there is but it’s not a complicated process since you can do some text replacement on a template and drop a file into apache’s configuration. In fact control panels like cPanel will often use an /etc/skel directory to set up new accounts which would allow you to pre-seed content but for a SaaS this would end up being overkill in my opinion.

I know option 2 could be done using a snapshot of a droplet and some custom scripts using the Digital ocean api.

Yes. It’s a pretty straightforward process but one droplet per account might not be cost effective unless you’ve got a pretty high markup on your pricing. I’ve built a couple SaaS/PaaS services in Ruby using this method.

Regarding Option 3 I’m all ears?

I agree that this is the most promising option giving you a good balance of separation from other users while utilizing the hardware resources more efficiently than option #2. You would need to decide whether you would also containerize your database services or whether you’d set up a large shared db cluster separate from your web app itself. Docker now has swarm built in by default so managing a cluster of multiple machines is easier. Shipyard might be a good tool to get more familiar with docker swarm (and manage it graphically) but you’ll still need to work out your signup/provisioning processes. There are likely libraries available to work with docker-swarm in php as well.

Thanks for getting back to me, I posted this question on some other forums including the docker one and have not really had any responses. Either this is a complicated question and people cant be bothered to answer or they don’t want to give away information on how to set something like this up.

Ok the way I understand it just from reading so far is: I would use a docker container to hold the application code itself, Apache and php. I would then have a separate container to run mysql and hold all the databases. Then every time a customer signs up I would spin up another application container and create a new database in the mysql container. I also have separate container holding nginx to act as load balancer between all different containers. If my node/droplet started to struggle I could then just scale up using the cloud hosting to cope. Does this sound right so far? I don’t know anything about docker swarm yet but ill go research.

The application itself is customizationable and users could install modules and change layouts that would change the structure of the applications files. So I would need to be able to maintain this between container restarts as well as maintain their databases long term. I understand that we use volumes for this? but is putting the entire php file structure of the application into a volume on each container viable?

I would also need a way to upgrade the application on mass as new versions come out, obviously the customers would need to be kept up to date.

Does all this sound feasible with docker? And is digital ocean a good provider for this kind of thing given that I could potentially have some big customers business. critical data. Im not sure if id need a provider with in depth support options if the shit hit the fan.