Changing php.ini settings with chef php cookbook

I installed the PHP Cookbook from opscode and the chef-dotdeb cookbook found in chef-dotdeb so that I can run PHP 5.4 in a stray field.

I would like to change some default settings of php.ini .

According to the chef php cookbook documentation, I can change the settings using

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

eg:

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

I made a modification to the webserver.rb script that I created in my application cookbook. When I install or restart the stray box, the php.ini settings remain unchanged.

Any ideas what is wrong?

The contents of the webserver.rb file:

include_recipe "nginx"

include_recipe "php"

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

Even when I delete the dotdeb doll so that the only php material comes from the official php oppode cookie, it still does not update the ini values.

ADDITIONAL INFORMATION

I looked at the code in the opscode php cookie, which actually introduces the erb php.ini template directives into it: https://github.com/opscode-cookbooks/php/blob/master/templates/ubuntu/php.ini.erb

Code that adds directives to the end of the file:

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

it is always empty {}

However .... if I change it to ...

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

Then the ARE directives are introduced into the template. I'm not a ruby ​​specialist. What is the fundamental difference between these two parts of logic?

+6
source share
5 answers

It might have been a real long shot, but I tried to use this function and found that it did not work, then I found it because I was looking at apache2 php.ini when the cookbook by default only adds the setting to the cli php file. ini. This is probably not a problem for Fedora / Redhat, but it is for Ubuntu as it separates configurations from / etc / php5 / in different folders.

+4
source

If the same problem were fixed, try installing Apache Apache. Installing Apache in the first and running apache2 :: mod_php5 does not mean that you can leave php :: apache2, which was a mistake for me.

The solution is to include the php :: apache2 recipe, and then he calls it php.ini "apache_conf_dir". Thus, the development of settings such as

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

will be correctly applied to apache php.ini.

+2
source

Try using:

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

And if that doesn't work, you can try using the override option:

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

Like Chef 11, you need to set an explicitly set priority level:

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

+1
source

I know this is a pretty old question, but it can help others.

the @ symbol means a variable. Template resources have the property of variables, and you can add the attribute of directives there.

More about the document:

 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 cookbook php recipe:

 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 assigns the variables node['php']['directives'] in the template.

0
source

Got this problem that my PHP directives are not applicable on PHP since Ubuntu 16.04. My solution was to override PHP conf_dir to make a skip cli recipe and only update the configuration used by Apache2.

 "override_attributes": { "php": { "conf_dir": "/etc/php/7.0/apache2" 
0
source

All Articles