Modifying php.ini setting with chef php cookbook
Asked Answered
I

5

6

I have installed the PHP Cookbook from opscode and the chef-dotdeb cookbook found at chef-dotdeb so that I can run PHP 5.4 in the vagrant box.

I would like to modify some of the default php.ini settings.

According to the documentation for the chef php cookbook I can modify the settings using

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

for example:

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

I have made the modification in the webserver.rb script I have created in my applications cookbook. When I provision or reload the vagrant box the php.ini settings remain unchanged.

Any ideas what is wrong?

The contents of the webserver.rb file are:

include_recipe "nginx"

include_recipe "php"

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

Even when i remove the dotdeb cookbook so that the only php stuff comes from the official opscode php cookbook it still doesnt update any ini values.

ADDITIONAL INFO

I have looked at the code in the opscode php cookbook that actually injects the directives into it erb php.ini template: https://github.com/opscode-cookbooks/php/blob/master/templates/ubuntu/php.ini.erb

The code that injects the appends the directives to the end of the file is:

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

this is always empty {}

However.... if i modify it to...

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

Then the directives ARE injected into the template. Im not a ruby expert. What is the fundamental difference between these 2 pieces of logic???

Inelegancy answered 16/12, 2013 at 14:25 Comment(4)
Re-provisioning rarely works for me for certain cookbooks. Have you tried a full vagrant destroy and a vagrant up explicitly?Polydactyl
Destroyed the box and then did a vagrant up but still didn't work :(Inelegancy
My telepathic abilities are somehow limited. Show more code (webserver.rb), how do you call the recipes and the output.Capel
I use override_attributes('php'=> { 'conf_dir'=>'/etc/php5/apache2' } ) and it updates the apache configuration instead of the cli... not the cleanest solution but if you only need your webserver config updated that's the simplest way to go.Naominaor
S
3

Might be a real long shot but I was trying to use this feature and was finding it doesn't work, then I actually found it's because I was looking at the apache2 php.ini when the cookbook by default only adds the setting to the cli php.ini file. This probably isn't an issue for Fedora/Redhat, but it is for Ubuntu because it separates the configs out under /etc/php5/ into different folders.

Scherle answered 2/1, 2014 at 0:40 Comment(1)
Same issue here. I solved this by just creating a custom template and writing the file with chef template.Weathering
V
2

Had the same issue installing priestjims php with Apache. Installing Apache first and running apache2::mod_php5 does not mean you can leave out php::apache2 that was the mistake for me.

Solution is to include php::apache2 recipe and then it is writing it's php.ini to 'apache_conf_dir'. This way development ini settings like

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

will be correctly applied to apache's php.ini.

Vincentvincenta answered 21/10, 2015 at 10:30 Comment(0)
S
1

Try using:

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

And if that doesn't work you can try to use the override option:

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

As of chef 11 you need to set the explicitly set the precedence level:

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

Soporific answered 16/12, 2013 at 18:42 Comment(2)
Thanks for your reply. I already tried those and have read that part of the docs. Didn't fix it I'm afraid :(Inelegancy
when i tried this one this is the generated code short_open_tag="Off" but it should be short_open_tag = Off and it is only appending on the cli/php.ini not it apache2/php.iniShrieval
W
0

I know it's quite old question, but it's might help others.

the @ symbol meant it's a variable. Template resources have variables property and you can add the directives attribute there.

More on the doc:

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

If you see the ini recipe of cookbook 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

it's assigning the node['php']['directives'] to variables in template.

Worldwide answered 18/9, 2014 at 9:45 Comment(0)
B
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"
Borries answered 16/8, 2016 at 13:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.