6

我已经安装了来自 opscode 的 PHP Cookbook 和在 chef-dotdeb 找到的 chef-dotdeb 食谱,这样我就可以在 vagrant box 中运行PHP 5.4 。

我想修改一些默认php.ini设置。

根据chef php cookbook的文档,我可以使用修改设置

node['php']['directives'] = {}

例如:

node['php']['directives'] = { :short_open_tag => 'Off' }

webserver.rb我已经在我的应用程序说明书中创建的脚本中进行了修改。当我配置或重新加载 vagrant box 时,php.ini设置保持不变。

有什么想法有什么问题吗?

webserver.rb 文件的内容是:

include_recipe“nginx”

include_recipe "php"

node.default["php"]["directives"] = { :short_open_tag => 'Off' }

即使当我删除 dotdeb 食谱以便唯一的 php 内容来自官方 opscode php 食谱时,它仍然不会更新任何 ini 值。

附加信息

我查看了 opscode php 食谱中的代码,该代码实际上将指令注入到 erb php.ini 模板中: https://github.com/opscode-cookbooks/php/blob/master/templates/ubuntu/php.ini。 erb

将指令添加到文件末尾的代码是:

<% @directives.sort_by { |key, val| key }.each do |directive, value| -%>
<%= "#{directive}=\"#{value}\"" %>
<% end -%>

这总是空的 {}

但是....如果我将其修改为...

<% node.default[:php][:directives].sort_by { |key, val| key }.each do |directive, value| -%>
<%= "#{directive}=\"#{value}\"" %>
<% end -%>

然后指令被注入到模板中。我不是红宝石专家。这两条逻辑之间的根本区别是什么???

4

5 回答 5

3

可能是一个真正的远景,但我试图使用此功能并发现它不起作用,然后我实际上发现它是因为我正在查看 apache2 php.ini,而默认情况下食谱仅将设置添加到 cli php.ini 文件。这对于 Fedora/Redhat 来说可能不是问题,但对于 Ubuntu 来说是这样,因为它将 /etc/php5/ 下的配置分离到不同的文件夹中。

于 2014-01-02T00:40:54.557 回答
2

用 Apache 安装牧师jims php 时遇到了同样的问题。首先安装 Apache 并运行 apache2::mod_php5 并不意味着您可以忽略对我来说是错误的 php::apache2。

解决方案是包含 php::apache2 配方,然后将其 php.ini 写入“apache_conf_dir”。这样开发ini设置就像

default['php']['directives'] = {
     'display_errors' => 'On',
     'allow_url_fopen' => 'On',
     'allow_url_include' => 'On',
     'short_open_tag' => 'Off'
}

将正确应用于 apache 的 php.ini。

于 2015-10-21T10:30:13.520 回答
1

尝试使用:

node.set['php']['directives'] = { :short_open_tag => 'Off' }

如果这不起作用,您可以尝试使用覆盖选项:

node.override['php']['directives'] = { :short_open_tag => 'Off' }

从厨师 11 开始,您需要设置显式设置优先级:

https://wiki.opscode.com/display/chef/Breaking+Changes+in+Chef+11

于 2013-12-16T18:42:24.753 回答
0

我知道这是一个很老的问题,但它可能会帮助其他人。

@符号表示它是一个变量。模板资源具有 variables 属性,您可以在其中添加 directives 属性。

更多关于文档:

This attribute can also be used to reference a partial template file by using a Hash. For example:

template "/file/name.txt" do
  variables :partials => {
    "partial_name_1.txt.erb" => "message",
    "partial_name_2.txt.erb" => "message",
    "partial_name_3.txt.erb" => "message"
  },
end
where each of the partial template files can then be combined using normal Ruby template patterns within a template file, such as:

<% @partials.each do |partial, message| %>
  Here is <%= partial %>
<%= render partial, :variables => {:message => message} %>
<% end %>

https://docs.getchef.com/resource_template.html

如果您看到ini食谱 php 的食谱:

template "#{node['php']['conf_dir']}/php.ini" do
    source node['php']['ini']['template']
    cookbook node['php']['ini']['cookbook']
    unless platform?('windows')
        owner 'root'
        group 'root'
        mode '0644'
    end
    variables(:directives => node['php']['directives'])
end

https://github.com/opscode-cookbooks/php/blob/master/recipes/ini.rb

它分配给node['php']['directives']模板中的变量。

于 2014-09-18T09:45:10.207 回答
0

Got this this problem that my PHP directives where not applied on PHP running Ubuntu 16.04. My solution was to override PHP's conf_dir to make the recipe skip cli and update only the config used by Apache2.

"override_attributes": {   
      "php": {
            "conf_dir": "/etc/php/7.0/apache2"
于 2016-08-16T13:06:59.343 回答