Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.