Module for multi-tenancy SaaS product development
✅ Support for DigitalOcean Database (Requires PHP version => 7.4 & ssl_ca_path
is path of ssl certificate which is also required)
✅ CRUD for Database servers | Type: MySql & Cpanel MySql
✅ CRUD for Tenant
✅ Identify Tenant via Sub-Domain | tenant1.example.com
or tenant2.example.com
✅ Identify Tenant via Path | example.com/tenant1
or example.com/tenant2
🔲 Identify Tenant via Domain | example.com
- By Path
Add tenant_by_path
middleware and path
parameter is required to identify the tenant
Route::group(
[
'prefix' => '/<URI>/{path}',
'middleware' => ['web', 'tenant_by_path'],
'namespace' => 'Frontend',
],
function () {
//------------------------------------------------
Route::get( '/', 'TenantController@index' )
->name( 'vh.frontend.tenant' );
//------------------------------------------------
});
- By Sub-domain
Add tenant_by_sub_domain
middleware to identify the tenant
Route::group(
[
'domain' => '{sub_domain}.domain.com',
'prefix' => '/<root-uri-sub-domain>', //this should not conflict with root domain
'middleware' => ['web', 'tenant_by_sub_domain'],
'namespace' => 'Frontend',
],
function () {
//------------------------------------------------
Route::get( '/', 'TenantController@index' )
->name( 'vh.tenant' );
//------------------------------------------------
});
- By domain - Pending for Future Release
Add tenant_by_domain
middleware to identify the tenant
Route::group(
[
'middleware' => ['web', 'tenant_by_domain'],
'namespace' => 'Frontend',
],
function () {
//------------------------------------------------
Route::get( '/', 'TenantController@index' )
->name( 'vh.frontend.tenant' );
//------------------------------------------------
});
$tenant = Tenant::find($id);
$tenancy = new Tenancy($tenant);
//to connect tenant database
$tenancy->start();
//disconnect to tenant database and reconnect to central database
$tenancy->end();
$tenant = Tenant::find(2);
$db_manager = new DatabaseManager();
//$created = $db_manager->createDatabase($tenant);
//$created = $db_manager->deleteDatabase($tenant);
//$created = $db_manager->databaseExists($tenant);
$inputs = [
'command' => '',
'path' => '',
];
Tenant::migrate($inputs, $tenant_id);
$inputs = [
'command' => '',
'class' => '',
];
Tenant::seed($inputs, $tenant_id);
Add following to your .env
file:
SESSION_DOMAIN=.domain.com
Replace domain.com
with you actual domain. Clear cache php artisan config:cache
so that new setting can be applied.
SAAS_DB_PREFIX=example
This will result in database name like:
example_tenant_database
example_tenant_database_user
APP_MODULE_SAAS_ENV=develop
Wild Card SSL: https://certifytheweb.com/
Other SSL Sources: https://letsencrypt.org/docs/client-options/
- Login
CPanel >> Subdomains
, enter*
in subdomain, indomain
choosetop level domain
, remove_wildcard_
fromDocument Root
.
After this if you visit any subdomain it will show SSL error, to resolve it we need to install
wildcard ssl
.
- Visit
https://www.sslforfree.com/
and enter*.yourdomain.com
and clickCreate Free Certificate
- Add
A
record to domain as per the instruction. On next page it will show all there SSL Certificate strings. - Login
CPanel >> SSL/TLS >> Manage SSL sites >> Install an SSL Website
and choose*.yourdomain.com
and enter SSL Certificate string to respective section and save. - Now try to visit any sub domain all of them should be working.
- Before deploying VaahSaas, create a folder
vaahsaas
and move all files and folder in that exceptpublic
- Rename
public
folder topublic_html
and change the content to following:
require __DIR__.'/../vaahsaas/vendor/autoload.php';
$app = require_once __DIR__.'/../vaahsaas/bootstrap/app.php';
- So in root folder you will have two folder
vaahsaas
andpublic_html
which can been deployed to theroot
of cpanel
- Open
<xampp>\apache\conf\extra\httpd-vhosts.conf
add following code:
<VirtualHost yourdomain.com>
DocumentRoot "<xampp-path>/htdocs/vaahsaas_director/public"
ServerName yourdomain.com
<Directory "<xampp-path>/htdocs/vaahsaas_director/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost test.yourdomain.com>
DocumentRoot "<xampp-path>/htdocs/vaahsaas_director/public"
ServerName test.yourdomain.com
<Directory "<xampp-path>/htdocs/vaahsaas_director/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
- Then open
notepad
as administratorC:\Windows\System32\drivers\etc\host
- Add following lines:
127.0.0.1 yourdomain.com
127.0.0.1 test.yourdomain.com
- You may see some error
test.yourdomain.com
likeTenancy Not Identified
if you have already not created any tenancy for the domain.
1. Install VaahCMS:
- VaahCMS is the foundation for our project, and Saas is a module within it.
- Follow the installation guide provided here to set up VaahCMS on your local system.
NOTE: VaahCMS Doc Link: https://docs.vaah.dev/vaahcms-2x
2. Integrate Saas Module:
- Once VaahCMS is successfully installed, navigate to the VaahCMS directory located at
<root-path>/VaahCms/Modules
. - Create a new folder named
Saas
. - Clone the Saas repository into this newly created folder.
NOTE: Ensure that the module directory's name does not contain any spaces, as this could affect the namespace.
Activation Process:
Now, let's activate the Saas module to utilize its functionalities:
- Access the VaahCMS backend by visiting
<base-url>/public/backend#/vaah/modules
. - Locate the Saas module in the list of available modules.
- Click on the "activate" button next to the Saas module.
- Once activated successfully, you'll see the module link appearing in the sidebar section of Vaah CMS.
php artisan migrate --path=/VaahCms/Modules/Saas/Database/Migrations
php artisan migrate:rollback --path=/VaahCms/Modules/Saas/Database/Migrations
php artisan db:seed --class=VaahCms\Modules\Saas\Database\Seeds\SampleDataTableSeeder