为理论和弹性搜索设置环境变量 [英] Setup environment variable for doctrine and elasticsearch

查看:92
本文介绍了为理论和弹性搜索设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为symfony设置环境变量.

How to setup environment variable for symfony.

例如,如果我运行我的项目,它应该解开环境并执行操作,例如---

Like if i run my project than it should detetched the envirment and do the action, as an example ---

http: //production.com -> prod * environment *
http: //localhost:9200 -> * dev * environment --- for elasticsearch
http: //localhost:8000 -> * dev * environment --- for doctrine/mysql

因此,如果我在本地主机上运行mysql请求,则应在

So if i run a mysql request on localhost it should make the request at

http: //localhost:8000 

如果我提出对Elasticsearch的请求,则应在以下位置提出请求

and if i make a request for elasticsearch it should make the request at

http: //localhost:9200

并且如果它在生产环境中运行,则应在

and if it runs in the production environment it should do the request at

http: //production.com:9200 --- elasticsearch
http: //production.com:8000 --- doctrine/mysql

我认为可以在parameters.yml完成,但是我真的不知道如何完成.

I think it can be done at parameters.yml but i really did not get how it can be done.

有人可以帮助我解决此问题吗? 非常感谢高级.

Can someone help me to solve this problem. Thanks a lot in advanced .

推荐答案

我不确定这是什么问题,因此我将为您提供更一般的答案.

I'm not exactly sure what's the problem here so I'll give you a more general answer.

Symfony有一种非常好的方法来针对不同的情况(或环境)配置项目.您应该看一下官方文档,其中详细介绍了这些内容.

Symfony has a really great way to configure your project for different situations (or environments). You should have a look at the official documentation which explains things in depth.

默认情况下,Symfony具有针对不同环境的3种配置:

By default, Symfony comes with 3 configurations for different environments:

  1. app/config/config_dev.yml用于开发
  2. app/config/config_prod.yml用于生产
  3. app/config/config_test.yml用于(单元)测试
  1. app/config/config_dev.yml for development
  2. app/config/config_prod.yml for production
  3. app/config/config_test.yml for (unit) testing

每个配置文件都可以覆盖基本配置文件app/config/config.yml中的设置.您将在此处存储常规/通用设置.每当需要为特定环境覆盖某些内容时,只需转到环境配置并进行更改.

Each of these config files can override settings from the base configuration file which is app/config/config.yml. You would store your general/common settings there. Whenever you need to override something for a specific environment, you just go to the environment config and change it.

假设您在app/config/config.yml中具有以下基本配置:

Lets say you have the following base configuration in app/config/config.yml:

# Doctrine Configuration
doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%prod_database_host%"
        port:     "%prod_database_port%"
        dbname:   "%prod_database_name%"
        user:     "%prod_database_user%"
        password: "%prod_database_password%"
        charset:  UTF8

现在可以说,对于每种环境,您都有3个不同的数据库-proddevtest.这样做的方法是覆盖环境配置文件中的配置(让我们说app/config/config_dev.yml:

Now lets say, you have 3 different databases for each environment - prod, dev and test. The way to do this is to override the configuration in the environment configuration file (lets say app/config/config_dev.yml:

# Doctrine Configuration
doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%dev_database_host%"
        port:     "%dev_database_port%"
        dbname:   "%dev_database_name%"
        user:     "%dev_database_user%"
        password: "%dev_database_password%"
        charset:  UTF8

app/config/parameters.yml.distapp/config/parameters.yml中添加必要的%dev_*%参数.现在,每当您使用dev环境打开应用程序时,它将在您的参数(%dev_database...%)中连接到指定的数据库.

Add the necessary %dev_*% parameters to your app/config/parameters.yml.dist and app/config/parameters.yml. Now, whenever you open your application using the dev environment, it will connect to the specified database in your parameters (%dev_database...%).

这差不多.您可以对在特定环境中需要更改的任何配置执行相同的操作.您绝对应该看一下文档.通过示例直接进行了解释.

This is pretty much it. You can do the same for any configuration you need to be changed in a specific environment. You should definitely have a look at the documentation. It's explained straight-forward with examples.

这篇关于为理论和弹性搜索设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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