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

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

问题描述

我刚刚开始使用Symfony。



我使用Git / github作为管理我的项目的一种方式。我已经设置了两个忽略日志和缓存这是罚款。



我现在需要设置一个生产站点。目前在这个小项目上,我在同一台服务器上进行开发和生产,但具有不同的文件位置和数据库。



例如

  www.example.com/mysymfonyproject_dev/<开发区
&
www.example.com/mysymfonyproject/<现场/生产站点

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



所以现在我克隆了我的项目到新的生产文件夹。

它当然会忽略日志和缓存文件夹,但现在我需要更改 database.yml 文件,例如更多可能获得生产区要上班。



处理此问题的最佳方法是什么?

还有其他文件我应该添加到 .gitignore 可以说明这个网站是什么版本的开发或生产。



或者还有一种其他的方法可以使用git吗?



哪个是最佳做法?



您可以想像,我不想每次将git推送到我的生产站点时更新database.yml文件。



更新:



我有一个开发环境。我正在寻找的是部署到生产的分步指南。我可以使用git来做,但是例如我如何去设置环境,以便我部署时所有的设置都是正确的。我确实看到database.yml可以有不同的分期和生产设置,但是那里我告诉symfony什么网站是什么?正如symfony如何知道www.example.com/kickboxing是生产的,www.example.com/kickboxing_dev正在进行?



更新2:



最终我的具体要求似乎很好。

  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存储库是ffine然后所有文件都是可移植的。

解决方案

问题,我可以给你一些相关的信息。



如你所知,symfony中有一个级联配置系统,它允许不同的参数,例如数据库连接许多其他的东西)为您的开发和生产环境。



对于部署,symfony附带了一个利用rsync进行部署的任务。一般来说,您不需要调整它,默认情况下不会部署任何dev前端控制器,因此它适合最基本的需求。请注意,即使部署脚本应该排除开发人员前端控制器的部署,如果要部署它们,e
如果部署它们,则默认情况下,它们只允许从localhost进行访问的小型安全检查。如果您需要从部署中排除其他文件,可以编辑config / rsync_exclude.txt



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



尽管如此,这个部署脚本不会处理数据库部署。你应该手动执行。如果您需要将数据库更改部署到现有数据库,那么还可以执行该手册,或查看原则迁移(假设您使用Doctrine)。



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

 < VirtualHost *:80& 
服务器名称www.myproject.dev
...
SetEnv SYMFONY_APP前端
SetEnv SYMFONY_ENV dev
SetEnv SYMFONY_DEBUG 1
< / VirtualHost>

请注意,对于每个应用程序/ env组合,我将有一个单独的Vhost。您不应该部署vhost配置,所以通常只需要在每个主机上设置一次。我修改过的index.php如下所示:

 <?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之外的任何其他前端控制器从我的存储库。


I'm just getting started with Symfony.

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.

e.g.

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

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

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.

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.

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

Which is best practice?

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.

UPDATE:

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?

UPDATE 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 }

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.

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.

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

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

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).

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>

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();

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最佳实践生产&amp;开发配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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