douque8861 2015-10-24 19:31
浏览 95

来自相同Codeigniter代码库的多个应用程序

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.

  • 写回答

1条回答 默认 最新

  • dreamwind1985 2015-10-24 19:34
    关注

    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
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图