我在多个环境中设置了一个ExpressionEngine站点:多个环境:本地,开发和生产。
I have an ExpressionEngine site set up with Git in multiple environments: Local, Development, and Production.
我有几个位于Web根目录之上的目录,所以Web根目录本身就在git repo里面,像这样:
I have a couple of directories that are above web root, so the web root directory itself is inside the git repo, like this:
- .git
- 系统
- third_party
- 模板
- public_html(web root)
- 资产
- css
- js
- img
- .git
- system
- third_party
- templates
- public_html (web root)
- assets
- css
- js
- img
现在,我的开发和生产环境都有2个独立的托管服务提供商,而且他们的Web根源之间有不同的名称。例如,Development被命名为 public_html ,但生产命名为内容。
Now, my development and production environments are with 2 separate hosting providers, and their web roots have different names from each other. Development, for example, is named public_html, but Production is named content.
当web根目录具有不同的名称时,如何部署到这两种环境中?
How do I deploy to both of these environments when the web root directories have different names?
推荐答案使用服务器上的符号链接将Web根指向相应的目录是一个时间荣誉的技术。让我们假设你给你的Git Repo一个明显的名字:clientsite,所以在你拥有的文件夹中:
Using symbolic links on the server to point the web root to the appropriate directory is a time honored technique. Let's assume you gave your Git Repo an obvious name: clientsite, so inside that folder you have:
- .git
- 系统
- third_party
- 模板
- web_root
- 资产
- css
- js
- img
- .git
- system
- third_party
- templates
- web_root
- assets
- css
- js
- img
该文件夹被上传到您的登台/生产服务器。在登台服务器上,您将创建一个名为public_html的web_root的符号链接:
That folder gets uploaded to your staging/production servers. On the staging server, you would then create a symbolic link to web_root named public_html:
ln -s clientsite/web_root public_html
然后在生产服务器上,您将创建一个符号链接到web_root称为内容:
And then on the production server, you would make a symbolic link to web_root called content:
ln -s clientsite/web_root content
现在,如果您非常聪明,并且正在使用MSM,那么您可以创建config.php和index.php文件,以便您可以在该EE安装中使用web_root进行所有的域,并创建符号链接为每个网站。例如:
Now, what's brilliant about this is that if you are very clever and are using MSM, you can create config.php and index.php files that allow you to use web_root for ALL your domains in that EE installation and just create symbolic links to it for each site. For example:
ln -s clientsite/web_root siteone_html ln -s clientsite/web_root sitetwo_html然后在index.php中,看看HTTP_HOST服务器配置来设置site_name:
Then in index.php, you look at the HTTP_HOST server config to set the site_name:
switch ( $_SERVER['HTTP_HOST'] ) { case 'siteone' : case 'dev.siteone' : $assign_to_config['site_name'] = 'siteone'; break; case 'sitetwo' : case 'dev.sitetwo' : $assign_to_config['site_name'] = 'site two'; break; }最后,你的config.php可以做一些非常相似的事情:
Finally, your config.php can do something very similar:
$config['site_index'] = ""; $config['site_url'] = "".$_SERVER['HTTP_HOST']; $config['server_path'] = $_SERVER['DOCUMENT_ROOT']; $config['cp_url'] = $config['site_url']."/".$config['system_folder'].'/index.php'; ....stuff here... switch ( $_SERVER['HTTP_HOST'] ) { // production case 'siteone' : $config['cookie_domain'] = ".siteone"; $db['expressionengine']['hostname'] = "111.222.111.22"; $db['expressionengine']['username'] = "siteone"; $db['expressionengine']['password'] = "passone"; $db['expressionengine']['database'] = "database_live"; $db['expressionengine']['db_debug'] = FALSE; break; // staging case 'dev.siteone' : $config['cookie_domain'] = "dev.siteone"; $db['expressionengine']['hostname'] = "333.444.555.22"; $db['expressionengine']['username'] = "siteone"; $db['expressionengine']['password'] = "passone"; $db['expressionengine']['database'] = "database_dev"; $db['expressionengine']['db_debug'] = FALSE; break; }以这种方式,您可以拥有全局配置选项,然后也可以使用网站特定的选项。
In this way, you can have global config options and then site specific options too.
- assets
- 资产
- assets
- 资产
更多推荐
Git:部署到具有不同Web根目录名称的环境
发布评论