使用Chef PHP Cookbook部署Zend Opcache

我是厨师新手。 我尝试使用Chef的PHP食谱来编写一个安装Zend OpCache(PHP 5.4,因为还没有内置)的配方。

我尝试使用php_pear

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

但生成的.ini文件具有ZendOpcache作为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" 

前缀应该是opcache

然后我尝试自己手动创build.ini文件

 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 

当我尝试执行PHP有这个警告

 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 

opcache模块加载在两个地方完成, ZendOpcache.iniopcache.ini手册。

我能想到的唯一解决scheme就是这样

 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 

这将创build两个文件ZendOpcache.iniopcache.ini 。 一个用于加载模块,另一个用于放置configuration。

使用一个模块的两个configuration文件似乎有点浪费。 有没有更简单的方法来做到这一点?

我们正在使用Remi repos,这是一个普通的yum包,我们不需要直接去PECL。

所以,当你在底部使用的技术得到一个工作的zend opcache设置,我们已经find了一个稍微好一点的方法,只需安装php-pecl-zendopcache yum包。

试试你的食谱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