1

I'm new on Chef. I tried writing a recipe that installs Zend OpCache (for PHP 5.4, since its not built-in yet) using Chef PHP cookbook.

I tried using the php_pear

php_pear "opcache" do
    package_name "ZendOpcache"
    action :install
    preferred_state "beta"
    zend_extensions ["opcache.so"]
    directives node['php']['opcache']['directives']
end

but the .ini file generated has ZendOpcache as the prefix for the variables

ubuntu@webserver3:~$ cat /etc/php5/conf.d/ZendOpcache.ini 
; configuration for php ZendOpcache module
zend_extension=/usr/lib/php5/20100525/opcache.so
ZendOpcache.revalidate_freq="60"
ZendOpcache.enable_cli="1"
ZendOpcache.memory_consumption="128"
ZendOpcache.interned_strings_buffer="8"
ZendOpcache.fast_shutdown="1"
ZendOpcache.max_accelerated_files="4000"
ZendOpcache.save_comments="0"

the prefix should be opcache.

I then tried manually create the .ini file myself

template "#{node['php']['ext_conf_dir']}/opcache.ini" do
    source "extension.ini.erb"
    cookbook "php"
    owner "root"
    group "root"
    mode "0644"
    variables(:name => 'opcache', :extensions => {'/usr/lib/php5/20100525/opcache.so' => true}, :directives => node['php']['opcache']['directives'])
   action :create
end

When I tried executing PHP there is this warning

PHP Warning:  Module 'Zend OPcache' already loaded in Unknown on line 0
[exec] PHP Warning:  Zend OPcache: module registration failed! in Unknown on line 0

The opcache module loading is done in two places, ZendOpcache.ini and the manual opcache.ini.

The only solution I can come up with and working is this

php_pear "opcache" do
    package_name "ZendOpcache"
    action :install
    preferred_state "beta"
    zend_extensions ["opcache.so"]
end

template "#{node['php']['ext_conf_dir']}/opcache.ini" do
    source "extension.ini.erb"
    cookbook "php"
    owner "root"
    group "root"
    mode "0644"
    variables(:name => 'opcache', :extensions => {}, :directives => node['php']['opcache']['directives'])
    action :create
end

this will create two files ZendOpcache.ini and opcache.ini. One for loading the module, and the other for putting configuration.

It seems a bit waste using two config file for one module. Is there any simpler way to do this?

2 Answers 2

1

We are using Remi repos and it is a normal yum package and we don't need to go out to PECL directly.

So while the technique you are using at the bottom gets a working zend opcache setup we have found a slightly better way by just installing the php-pecl-zendopcache yum package.

0

Try in your cookbook default.rb:

bash "adding zendopcache-7.0.3" do
  if `php -v | grep OPcache`.empty?
    code <<-EOH
    apt-get install -y php-pear build-essential php5-dev
    pecl install zendopcache-7.0.3
    EOH
  end
end

template "#{node[:php][:ext_conf_dir]}/opcache.ini" do
  source "opcache.ini.erb"
  mode "0644"
end

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .