I've tried to figure out the best way to create a website programmatically in PHP but I couldn't find any similar questions here or elsewhere.
The situation is this:
I have an admin dashboard and a DB connected to this admin dashboard.
In this dashboard I create a website with all the necessary settings. Like list of foods and images and colors etc.
When I save a website in the dashboard I need to create a website folder above the root directory of the admin panel on my web server.
So it creates all the files and folders which will be uploaded to that folder and be connected to the admin DB to get the data.
The thing is that I want to create dozens of websites with the same structure but with different data and colors etc., not as subdomains of the admin dashboard but as a main domain.
Of course the domains will be created manually in my c-panel.
It's not about the coding but about the approach to this problem.
Would be happy about any suggestions.
If the websites are all sharing the same code base, but just have different data, I would consider not creating different folders at all. Store all of your data for each site in the database.
You can then create a single virtual host in Apache set as the default that will handle all requests that do not explicitly match another. Your PHP code can then look at the Host header to determine which site is being accessed, query the database to determine if it is valid and load the data, and then serve the appropriate content.
I would not advise dynamically altering system configuration with PHP. Though it could be done safely, this seems overly complex and prone to errors that could be significant security risks.
Obviously, there are many approaches to this and ultimately the correct one will depend on your use case and the customization and uniqueness of each site.