Symfony 1.4 最佳实践生产和开发配置 [英] Symfony 1.4 best practice production & development configuration

查看:23
本文介绍了Symfony 1.4 最佳实践生产和开发配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用 Symfony.

I'm just getting started with Symfony.

我使用 Git/github 作为管理项目的一种方式.我为日志和缓存设置了两个忽略,这很好.

I'm using Git/github as a way of managing my project. I've set up two ignores for log and cache which is fine.

我现在需要建立一个生产站点.目前,在这个小项目中,我在同一台服务器上开发和生产,但文件位置和数据库不同.

I now need to set up a production site. At the moment on this small project I've development and production on the same server but with different file locations and databases.

例如

www.example.com/mysymfonyproject_dev/  < development area
&
www.example.com/mysymfonyproject/      < Live / Production site

在服务器上它的 /homes/sites/example.com/www/mysymfonyproject_dev &/home/sites/example.com/www/mysymfonyproject

On server its /homes/sites/example.com/www/mysymfonyproject_dev & /home/sites/example.com/www/mysymfonyproject

所以现在我已将我的项目克隆到新的生产文件夹.
它当然会忽略日志和缓存文件夹,但现在我需要更改 database.yml 文件,并可能进行更多更改以使生产区域正常工作.

So now I have cloned my project to the new production folder.
It of course ignores the log and cache folders but now I need to change the database.yml file for example and possible more to get the production area to work.

处理这个问题的最佳方法是什么?
是否有其他文件我应该添加到 .gitignore 可以说明该站点的版本,例如开发或生产.

What is the best method of dealing with this?
Is there some other file I should add to .gitignore that can state what version this site is e.g. development or production.

或者有没有其他方法可以在不使用 git 的情况下做到这一点?

OR is there a whole other way I can do this with out using git?

最佳做法是什么?

您可以想象,我不想在每次对生产站点执行 git push 时都更新 database.yml 文件.

As you can imagine I don't want to have to update the database.yml file everytime I do a git push to my production site.

更新:

我有一个开发环境.我正在寻找的是部署到生产的分步指南.我可以使用 git 来做到这一点,但例如,我该如何设置环境,以便在部署时所有设置都正确.我确实看到 database.yml 可以有不同的登台和生产设置,但是我在哪里告诉 symfony 哪个站点是什么?就像 symfony 怎么知道 www.example.com/kickboxing 是生产而 www.example.com/kickboxing_dev 是登台?

I've got a development environment. What I'm looking for is a step by step guide to deploy to production. I could use git to do it but for example how do I go about setting up the environments in such a way that all setting will be right when i deploy. I do see that database.yml can have different settings for staging and production but where then do I tell symfony what site is what? as in how does symfony know that www.example.com/kickboxing is production and www.example.com/kickboxing_dev is staging?

更新 2:

最后,对于我的具体要求,这似乎运作良好.

In the end for my specific requirements this seemed to work well.

1 <?php                                                                                                                          
2 
3 
4 require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
5 
6 $theurl = explode('/', $_SERVER['PHP_SELF']);
7 $mydir = $theurl[1];
8 
9 
10 if ($mydir == "mysymfonyproject")  //live
11 {
12     $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);
13     sfContext::createInstance($configuration)->dispatch();
14 }
15 else // dev 
16 {
17     $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
18     sfContext::createInstance($configuration)->dispatch();
19 }

我认为在您可以配置主机文件的本地机器上使用 $_SERVER['SERVER_NAME'] 会更好,例如mysymfonyproject.local 只需添加到索引文件中,然后 git 存储库就可以了,所有文件都是可移植的.

I think using $_SERVER['SERVER_NAME'] would be better on local machines where you might config your hosts file e.g. mysymfonyproject.local just add to the index file and git repository is ffine then and all files are portable.

推荐答案

既然你更新了你的问题,我可以给你一些相关信息.

Since you updated your question, I can give you some relevant info.

正如您现在所知,您在 symfony 中有一个级联配置系统,它允许不同的参数,例如您的开发和生产环境的数据库连接(以及许多其他内容).

As you now know, you have a cascading configuration system in symfony which allows different parameters for for example your database connection (among many other things) for your dev and prod environment.

关于部署,symfony 自带一个任务,就是利用 rsync 来部署.一般来说,您不需要对其进行太多调整,默认情况下它不会部署任何开发"前端控制器,因此它适合大多数基本需求.请注意,即使部署脚本应该完全排除 dev 前端控制器的部署,e即使你会部署它们,它们默认也有一个小的安全检查,只允许从本地主机访问.如果需要从部署中排除其他文件,可以编辑 config/rsync_exclude.txt

As to deployment, symfony comes with a task that utilizes rsync to deploy. In general you do not need to tweak it much, it will by default not deploy any "dev" front controller, so it suits most basic needs. Note that even if the deployment script should exclude the dev front controllers from deploying at all, e ven if you would deploy them, they by default have a small security check which only allows access from localhost. If you need to exclude other files from deployment, you can edit config/rsync_exclude.txt

在此处部署的详细信息:http://www.symfony-project.org/gentle-introduction/1_4/en/16-Application-Management-Tools#chapter_16_deploying_applications

Detailed info in deploying here: http://www.symfony-project.org/gentle-introduction/1_4/en/16-Application-Management-Tools#chapter_16_deploying_applications

但要注意的是,此部署脚本不处理数据库部署.您应该手动执行此操作.如果您需要将数据库更改部署到现有数据库,您也可以手动操作,或查看 Doctrine Migrations(假设您使用 Doctrine).

A big note though, is that this deployment script does NOT handle database deployment. You should do that manually. If you need to deploy database changes to an existing database, you could also do that manual, or look into Doctrine Migrations (assuming you use Doctrine).

更新:您可以为不同的应用程序和/或环境使用一个前端控制器 (index.php).您可以检查主机名或其他内容,但我发现并采用的最简洁的解决方案是设置 Apache 环境变量.在我的 Vhost 配置中,我会这样做:

Update: you can have a single frontend controller (index.php) for different apps and/or environments. You can either check the hostname or other things, but the cleanest solution I found and employ is setting Apache environment variables. In my Vhost config I'll do:

<VirtualHost *:80>
  Servername www.myproject.dev
  ...
  SetEnv SYMFONY_APP frontend
  SetEnv SYMFONY_ENV dev
  SetEnv SYMFONY_DEBUG 1
</VirtualHost>

请注意,我当然会为每个应用程序/环境组合使用单独的 Vhost.你不应该部署虚拟主机配置,所以通常你只需要在每台主机上设置一次.我修改后的 index.php 是这样的:

Note that ofcourse I'll have a separate Vhost for every single app/env combination. You shouldn't be deploying vhost configs, so normally you'll only need to set this up once on each host. My modified index.php looks like this:

<?php

require_once dirname(__FILE__) . '/../config/ProjectConfiguration.class.php';

$app = isset($_SERVER['SYMFONY_APP']) ? $_SERVER['SYMFONY_APP'] : 'frontend';
$env = isset($_SERVER['SYMFONY_ENV']) ? $_SERVER['SYMFONY_ENV'] : 'prod';
$debug = isset($_SERVER['SYMFONY_DEBUG']) ? $_SERVER['SYMFONY_DEBUG'] : false;

$configuration = ProjectConfiguration::getApplicationConfiguration($app, $env, $debug);
sfContext::createInstance($configuration)->dispatch();

通过这个设置,我可以从我的存储库中删除 frontend_dev.php 和除 index.php 之外的任何其他前端控制器.

With this setup, I can just remove frontend_dev.php and any other frontend controllers apart from index.php from my repository.

这篇关于Symfony 1.4 最佳实践生产和开发配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆