您如何看待关于如何配置开发/登台/生产实例的奇怪想法?

时间:2022-09-03 19:50:43

I just got a weird idea about how to configure environment-dependent parameters. Sort of like parameters you can find in Rails' config/database.yml

我对如何配置依赖于环境的参数有一个奇怪的想法。您可以在Rails的config / database.yml中找到类似的参数

In my current project I use PHP and Litespeed Web Server (though the same technique applies to PHP + Apache), and I thought... 'why not use mod_rewrite for this?'. I have separate virtual hosts configs for each env (development/production at the moment)

在我目前的项目中,我使用PHP和Litespeed Web Server(虽然相同的技术适用于PHP + Apache),我认为......“为什么不使用mod_rewrite?”。我为每个环境都有单独的虚拟主机配置(此刻开发/生产)

What I have now is:

我现在拥有的是:


RewriteRule (.*) $1 [env=development:1]

for the development environment vhost. But what if it will be something like this?

对于开发环境vhost。但如果它会是这样的呢?


RewriteRule (.*) $1 [env=development:1,env=mysql_host:localhost,env=mysql_port:3306,env=mysql_user:root,env=mysql_pass:,env=mysql_db:mydbname]

Would it make sense or will cause some problems? What do you think?

它会有意义还是会引起一些问题?你怎么看?

5 个解决方案

#1


3  

I don't believe rewrite rules are a particularly intuitive place to put configuration information like that. Maybe I am misunderstanding something, but is the only difference between the development, staging, and production environments the database connection? Typically the code is also different (at least once changes are made), and so if you are using a revision control system, I think it might be a better idea to have a template configuration file (database.cfg.template) that you copy (and tell your revision control system to ignore) and modify (to database.cfg). Then it's obvious where this information is.

我不相信重写规则是一个特别直观的地方来放置这样的配置信息。也许我误解了一些东西,但是数据库连接的开发,登台和生产环境之间的唯一区别是什么?通常代码也是不同的(至少进行一次更改),因此如果您使用的是版本控制系统,我认为拥有您复制的模板配置文件(database.cfg.template)可能更好一点。 (并告诉您的修订控制系统忽略)并修改(到database.cfg)。然后很明显这些信息在哪里。

#2


1  

You're right -- it's a wierd idea.

你是对的 - 这是一个奇怪的想法。

IMO, this is a really bad use for mod_rewrite. True, the configuration information belongs with the machine, rather than the codebase (a mistake I see people make all the time), but it doesn't necessarily belong with the webserver configuration, either.

IMO,这对mod_rewrite来说非常糟糕。是的,配置信息属于机器,而不是代码库(我看到人们一直在犯的错误),但它也不一定属于Web服务器配置。

I would recommend a configuration file that is not managed by version control.

我推荐一个不受版本控制管理的配置文件。

#3


0  

If you want to set the environment in the vhost you can do something like

如果要在vhost中设置环境,可以执行类似的操作

php_value ENV "development"

And then read it from the $_SERVER array

然后从$ _SERVER数组中读取它

#4


0  

First of all, if you're not actually changing the URL, don't use $1 as the replacement, just use a dash. As per the docs:

首先,如果您实际上没有更改URL,请不要使用$ 1作为替换,只需使用破折号即可。根据文档:

A dash indicates that no substitution should be performed (the existing path is passed through untouched). This is used when a flag (see below) needs to be applied without changing the path.

短划线表示不应执行替换(现有路径未经过触摸传递)。当需要在不改变路径的情况下应用标志(见下文)时使用。

But really, I think the answer is mod_env. SetEnv directives could be placed within your <VirtualHost> blocks, avoiding the unnecessary RewriteRule foo.

但实际上,我认为答案是mod_env。 SetEnv指令可以放在 块中,避免不必要的RewriteRule foo。

#5


0  

The best and only place where you should define current environment is bootstrap.

您应该定义当前环境的最佳和唯一的地方是bootstrap。

Look at symfony or agavi bootstrapping files.

查看symfony或agavi引导文件。

#1


3  

I don't believe rewrite rules are a particularly intuitive place to put configuration information like that. Maybe I am misunderstanding something, but is the only difference between the development, staging, and production environments the database connection? Typically the code is also different (at least once changes are made), and so if you are using a revision control system, I think it might be a better idea to have a template configuration file (database.cfg.template) that you copy (and tell your revision control system to ignore) and modify (to database.cfg). Then it's obvious where this information is.

我不相信重写规则是一个特别直观的地方来放置这样的配置信息。也许我误解了一些东西,但是数据库连接的开发,登台和生产环境之间的唯一区别是什么?通常代码也是不同的(至少进行一次更改),因此如果您使用的是版本控制系统,我认为拥有您复制的模板配置文件(database.cfg.template)可能更好一点。 (并告诉您的修订控制系统忽略)并修改(到database.cfg)。然后很明显这些信息在哪里。

#2


1  

You're right -- it's a wierd idea.

你是对的 - 这是一个奇怪的想法。

IMO, this is a really bad use for mod_rewrite. True, the configuration information belongs with the machine, rather than the codebase (a mistake I see people make all the time), but it doesn't necessarily belong with the webserver configuration, either.

IMO,这对mod_rewrite来说非常糟糕。是的,配置信息属于机器,而不是代码库(我看到人们一直在犯的错误),但它也不一定属于Web服务器配置。

I would recommend a configuration file that is not managed by version control.

我推荐一个不受版本控制管理的配置文件。

#3


0  

If you want to set the environment in the vhost you can do something like

如果要在vhost中设置环境,可以执行类似的操作

php_value ENV "development"

And then read it from the $_SERVER array

然后从$ _SERVER数组中读取它

#4


0  

First of all, if you're not actually changing the URL, don't use $1 as the replacement, just use a dash. As per the docs:

首先,如果您实际上没有更改URL,请不要使用$ 1作为替换,只需使用破折号即可。根据文档:

A dash indicates that no substitution should be performed (the existing path is passed through untouched). This is used when a flag (see below) needs to be applied without changing the path.

短划线表示不应执行替换(现有路径未经过触摸传递)。当需要在不改变路径的情况下应用标志(见下文)时使用。

But really, I think the answer is mod_env. SetEnv directives could be placed within your <VirtualHost> blocks, avoiding the unnecessary RewriteRule foo.

但实际上,我认为答案是mod_env。 SetEnv指令可以放在 块中,避免不必要的RewriteRule foo。

#5


0  

The best and only place where you should define current environment is bootstrap.

您应该定义当前环境的最佳和唯一的地方是bootstrap。

Look at symfony or agavi bootstrapping files.

查看symfony或agavi引导文件。