Same HTML files but different database connections for subdomains

Hi guys,

I would like to do the following thing, but I can not figure out how to do it:

I am developing an application which has many users. Each user has their own separated MySQL database. I’d like to setup Apache virtual hosts, and every vhost serve HTML files from the same directory, but every user have to connect to their own database.

Serving HTML files for every vhosts from the same directory is easy, not problem, I set the DocumentRoot in every vhosts to the same location.
The problem is somehow redirecting requests of dmxConnect/modules/Connections/myconnection.php which should contain different database location for each users/vhosts.

for eg.:

App HTML files are under https://core-app.mydomain.com

User1 subdomain is https://user1-app.mydomain.com

User2 subdomain is https://user2-app.mydomain.com

User3 subdomain is https://user3-app.mydomain.com

Sounds a little bit complicated, but I hope you can understand what I mean :slight_smile:

I have tried to place a different “myconnection.php” to User1, User2, User3 subdomain folders and write “Alias dmxConnect/modules/Connections/myconnection.php /var/www/user1/myconnection.php”, but it was unsuccessful.

thanks,
Attila

Hi Attila,

Nice project!

Currently the connect files use static values as those are more common.

However you can try using expressions like:

{{some_variable}}

And especially point to environment variables.
I think it was $_ENV

So something like:

{{$_ENV[‘user_database’]}}

Etc for the different user settings.

So enter those instead of static values. And make sure the right variables get set.

You also use $_SESSION from php session variables or $_SERVER

Of course when you save such a db connection the test will fail, but you can still choose to save it.

Let me know if that works.

I will add some more data pickers so you can choose the expressions more easily in the next updates.

5 Likes

Thank you!!! This ENV variable thing working well, you made my day! :beers:

1 Like