2016-02-19 105 views
1

我想用CakePHP 3構建多租戶Web應用程序,如http://www.orangescrum.com/,它也是用CakePHP編寫的。Cakephp3應用程序子域共享相同的應用程序代碼,但不同的數據庫

每個租戶都有單獨的子域和單獨的數據庫,只有應用程序源代碼對於所有子域都是相同的。這些域將擁有自己的文件夾,如x.domain.comy.domain.com映射到文件夾x, y, z

我不想在所有子域中都有重複的應用程序源代碼。我想重複使用相同的應用程序代碼。

當請求中的每個子域如何使用相同的應用程序代碼但不同的數據庫?任何形式的實施建議都是值得歡迎的。

+1

本文可能會幫助你http://mark-story.com/posts/view/using-cakephp-and-a-horizo​​ntally-sharded-database –

回答

1

你必須爲此創建一個conf文件。

它可以自動創建使用SH文件,如下

#!/bin/bash 

if [ "x${1}" = "x" ]; then 
    echo "User is not specified" 
    exit 1 
fi 

if [ "x${2}" = "x" ]; then 
    echo "Domain is not specified" 
    exit 1 
fi 

if [ "x${3}" = "x" ]; then 
    echo "Domain is not specified" 
    exit 1 
fi 

/bin/echo ${1}${2} | /bin/egrep -q ';|`|\||>' 
if [ $? -eq 0 ]; then 
    echo "Bad parameter" 
    exit 1 
fi 

/bin/cat > /etc/httpd/vhost.d/${1}.${2}.conf <<EOF 
<VirtualHost *:80> 
DocumentRoot /home/user/www.${2}/htdocs 
ServerName ${1}.${2} 
ServerAlias ${3} 
ServerAdmin [email protected] 
</VirtualHost> 


<VirtualHost *:443> 
DocumentRoot /home/user/www.${2}/htdocs 
ServerName ${1}.${2} 
ServerAlias ${3} 
ServerAdmin [email protected] 
SSLEngine on 
SSLCertificateFile /etc/httpd/conf/ssl.crt/example.com.crt 
SSLCertificateKeyFile /etc/httpd/conf/ssl.key/example.key 
SSLCACertificateFile /etc/httpd/conf/ssl.crt/example.crt 
</VirtualHost> 


EOF 

service httpd restart 

echo "Vhost has been added" 

exit 0 

路徑和指定的電子郵件可以根據自己的配置被修改,並與「一vhost_gen.sh將其保存在/ usr /本地/ bin /' 或任何你喜歡的地方。

,如果你想給任何真正的域別名到子域名稱CakePHP中該SH文件

$subdomain_name = 'xyz'; 
$domain_name = 'domain.com'; 
$real_domain_name = 'xyz.domain.com'; 

exec ("/usr/local/bin/vhost_gen.sh ".$subdomain_name." ". 
$domain_name." ".$real_domain_name); 

$ real_domain_name是ServerAlias。

相關問題