1

I have a web application on apache/httpd. By copying this application and putting it in a different directory under document root, I creat a new instance of that application. I do set up a new database for each instance as well.

I use database realm for authenticating the user.

The problem is that I use MySQL for storing the user credentials and the database information is stored in the httpd.conf, that is global for all instances, like this (no password yet):

DBDriver mysql
DBDParams "host=server_host port=3306 dbname=db_name user=user_name"

DBDMin  4
DBDKeep 8
DBDMax  20
DBDExptime 300

I would like to use different dbname for the different instances, or do some mapping for which database to use for authentication, depending on what instance of the application that is accessed.

Is it possible to solve using the built-in support for authentication in Apache2? If not, what strategies can be applied for the solution?

Nicsoft
  • 203
  • 6
  • 15

1 Answers1

0

The answer is to use virtual hosts for each application instance. Then you can configure what database to use for each virtual host.

E.g. add this to httpd.conf:

NameVirtualHost *:80

<VirtualHost *:80>

ServerName 192.168.1.107
DocumentRoot /var/www/html/instance

DBDriver mysql
DBDParams "host=localhost port=3306 dbname=db_instance user=user"

DBDMin  4    
DBDKeep 8
DBDMax  20
DBDExptime 300


<Directory "/var/www/html/instance">

Options Indexes FollowSymLinks

AllowOverride None

Order allow,deny
    Allow from all

        AuthType Basic
        AuthName "Restricted Files"
        AuthBasicProvider dbd
        Require valid-user
        AuthDBDUserPWQuery "SELECT password FROM user WHERE user = %s"
</Directory>
</VirtualHost>
Nicsoft
  • 203
  • 6
  • 15