phplaravelubuntumultiple-instancescode-sharing

How to handle infrastructure for the website in PHP which will be used many times?


I have a few PHP Laravel projects (restful API, admin app, client app). There is only one database which is used by API. The project is some kind of app which can be used by some companies. They have access to admin panel, client web page, they can use own API, they can make own users, permissions and so on. There is no problem if this project will be used by one client, but I'm going to sell this app to many people. I will be responsible for updates, hosting, configurations etc. I wonder how to make it the best way and I have a few ideas.

  1. I thought about cloning the app on the server each time someone buys it from me. This requires setting up a new subdomain on the server and a lot of disk space. Not sure about it.
  2. Or maybe cloning the app and sharing some files with symlinks like vendor, node_modules etc.
  3. Another idea is to make it as a one project with many databases for different clients, but how to make it in Laravel in the best way? I will need some dynamic way to change the database connections (I want each client to have separate database), I'm not sure about conflicts with sessions, cache etc.
  4. Maybe separate databases is a wrong idea, and it's better to have one database and make it as a one project and sell the access to project? But then I need to keep data of my client in one database.

What do you think?


Solution

  • Create this application as SaaS (software as a service). You can give them some default templates of front end or even client app (website and admin part), but keep all backend at your servers. Make REST endpoints, authenticate clients and give them functionality that they bought.

    For example:

    Client A bought calculator services from you. It authenticates, and makes GET call to /api/calculate/subtract/5/1. You give them response what your calculator does, for example 5-1 = 4. They can use your prepared templates for this data preview or create their own.

    Client B bought calculator and storage services from you. You calculate same value, give it back, but also store it in your own database. So client B also can make call GET /api/storage/last_calculation and you give them 4, because client data stored in your database, he bought storage service too so he do not need to setup database for himself.

    It is very simple example, but you should get the point.

    For example simple scheme with separate database for each client: enter image description here