My product has 70 customers. Each customer has a MYSQL database and I am using Codeigniter.
I have 70 subfolders e.g domain.com/customer1/ domain.com/customer2/ and so on and in each of these folders, I have mentioned the database details of the specific customer, along with all the files for codeigniter installation.
I want to get rid of all these installations and want to have only one installation for all my customers. Ideally domain.com/app/
What is the best way to achieve this?
I tried dynamically writing into the database.php file when one of the client logs in. So what I did is write the database details of the client in the database.php file of the one code base e.g domain.com/app/ and see if it worked. But it won't work for other clients, I think I am doing something wrong here.
Why not use a subdomain for each client and point the web root to that one folder. You can use the subdomain as the database name.
VHOST:
<VirtualHost *:80>
ServerName client.domain.com
ServerAlias *.domain.com
DocumentRoot /home/clients/public_html
<Directory /home/clients/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
</VirtualHost>
Then modify database.php like this
$client_name = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], '.'));
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'username',
'password' => 'password',
'database' => "$client_name",
'dbdriver' => 'mysqli',
'dbprefix' => 'phppos_',
'pconnect' => FALSE,
'db_debug' => FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => FALSE