I have a system with many clients, but for each client we have one database "all database and code are the same", but I can set just one database in .env file, how can I set for each client the correct database.
So, on this case I need to create for each client one folder with the same files in each folder, also i did this on my public/index.php
https://onlinephp.io/c/b61dc
but this one I set differents .env for each client with their own databases, so for each client I'll have one .env
There is the best way to do this?
I know that could I use one database for all clients differentiating by customer_id in each table, but on this for now i'll need to change a lot on the system, i'll do this in a v2
Symfony v5.4
Related
I got a legacy code in symphony, but the systems works like this for each client has a system and one database, but the both are same for all of them, so i have "twenty" same systems "folders" for each client and each client has a database.
So, I'm trying to change this to one folder for all clients, but I've been having a problem with the databases, because the file .env we can set only one database for .env file, so, in this case i think to create a folder inside the system "envs" and i created for each client one .env with their names
Example: .envtest, .envgoogle, .envfacebook and etc...
And i use this function on public/index.php to set the corret .env
(new Dotenv())->load(DIR.'/../envs/.env'.explode(".", $_SERVER['HTTP_HOST'])[0]);
and when client trying to access the system i get from the $_SERVER the URL how i can concat and get the corret .env
but i think that i'm doing too wrong, there is other way to do this?
I can understand your problem. You can ask the creaters of symfony and they can help you. Just write your question in thier website here (choose any course and then put your question):
https://symfonycasts.com/
In my case, I have so many databases for my clients but in diffrent servers (LDAP and Soap) so it was easy for me. but in your case it is better to ask Symfony creater themselves.
We're currently developing a 'sort of' e-commerce platform for our customers that are using our POS system.
This mainly exists of:
An Angular client-side
A PHP API as back-end
A MySQL database
Before I distribute the application to clients, I want to have a 'manageable' system for deploying and updating their platforms in case of code changes etc.
The initial setup would be:
Create database
Copy PHP files
Run composer
Run migrations
Modify configuration file for database credentials, salts, domain,..
Copy client side files
I was looking at Deployer for PHP, but I'm not sure how the whole database creation and config file modifications would work. I've originaly have the database creation in one of my migrations, but this would require a root db-user (or one with create permissions) and this user would need to be created as well.
The intial setup part could be done manually (it's not like it will be more than 5+ installations per week or so, but I would like to make it as simple as possible so that our support can do this instead of me every time)
The next part would be Updates.
I don't want to FTP to every server and apply changes. Updates can be both server side and client side. What would be the best way to do this:
Have a central system with all versions and registered websites at our end and let the client server daily check for a new version. If there is a new version, download all files from our server and run the migrations.
Push via deployer the new version to all clients. But this would overwrite or move the original config file with the DB credentials etc with the new version?
What if I need to add a new config setting? (application settings are stored in the database, but like the 'API' settings are within a config file.)
There will be a chance that all these client-servers will be distributed via our hosting provider, so we'll have access to all of them and they'll all be the same (for the configuration and such)
I've only written web applications used on one (server) location, so updating those were easy, for example via deploybot and such and the database setup was done manually, but now I'm stepping up my game and I want to make sure that I don't give myself more work than it should be.
Here's our case on developing an e-commerce platform - maybe you'll find answers to your questions there.
Codenetix spezializes in custom development, mostly web apps, so if you need help - let us know.
Good luck with your project!
I've developed a Web application with Laravel and everything is ok.
This should be a multi-tenant application, so I would like to share the same code but to use a different database for each tenant (I decided for this architecture as according to me it is too complex to share database schema or records among tenants).
Every tenant is accessing the application with its own third level domain (tenant1.xxxx.com, tenant2.xxxx.com, etc)
I would like then to create n. databases (tenant1, tenant2, etc) and to create n. database config file in Laravel (database.tenant1.php, database.tenant2.php, etc)
The problem now is that I cannot find an elegant way to alter the database config file loading system in Laravel.
I should select the config file, based on the host name used by the customer.
Any help would be appreciated.
Thank you,
Michele
in your config folder, there is a 'database.php' file. in that file you can see an array called 'connection' .
'connection' array manages different configuration for multiple database connections.
you can define your configuration for each of tenants in 'connection' array and based on the scenario you are in it, you can choose the appropriate connection to handle your query with a syntax like this:
DB::connection('tenant1')->select('where...');
or
DB::connection('tenant2')->select('where...');
My database name is student, my problem is every time I include the database name in php file, using include('student.php'); the student.php file connect the mysql query statement.This is normal, but I want to hide the database name any where or other person doesn't see the database and the database settings.
I'm not sure if this is the correct answer, but how we usually do this in Rails is by setting the database settings as environment variables on the server (and locally) and have our app use these environment variables to configure that database connection. You could do the same thing in your PHP app to hide the db name (and password) from people editing the code and from source control. It also helps for deploying to multiple servers.
The best solution you can do is set up your database with a mirror with a user which only has permission to do normal stuff, but not access or drop databases.
That way it doesn't matter what your students do or see the database as.
I am trying to figure out how one would start the setup of a small CMS.
I have the groundwork built, but the step of creating the database tables in mysql, should this all be done at once in a install.php file? Is there a preferred method for creating many tables at once, even if I don't need to insert data into them at this time?
You can
Import the schema file to your database prior to deploying the application
You can have a script that creates the schema
You can have a script that makes any changes to the current schema (for upgrades)
For a small CMS, I'd just keep the SQL in a schema file and import it when I need it.
You could also do a database copy from your dev -> live system. So you make the changes in the dev database as you need them and then push them to the live database. Something like SQLCompare for SQL Server works well.
Wordpress does the install.php route, where you have to enter your credentials and such for the target database and it then pushes the changes to it.
If you're going to be distributing your application for 3rd parties to install on their own servers, a very common approach is to provide (as you said) a simple install.php file. If your application is more complicated, often times an installation directory will come packaged. The user installing the application opens this in a browser, where your script typically does a few things:
Check PHP installation - verify (using function_exists()) all the required functions (and thus libraries) are installed and available. Alert the user of anything missing.
Allow the user to enter their configuration parameters - application specific settings required. Typically database hostname, username & password.
Test database connection - if successful, load initial tables. Commonly you keep your base schema file stored as a SQL file, so the application pushes this through the native mysql client, or issues the individual SQL commands directly.