Chef correct way to load new rpm and install package

Marty Wallace picture Marty Wallace · Aug 11, 2013 · Viewed 15k times · Source

I am trying to install the latest version of php on a centos box and am struggling.

The cookbook i have been looking at is the opscode one: https://github.com/opscode-cookbooks/php

It doesnt look like i can install php 5.5 using that.

To install manually i would simply do the following (on centos 6.4):

rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
yum install php55w php55w-opcache

How does this translate into using chef (solo) to get php 5.5 installed?

Answer

shawnzhu picture shawnzhu · Aug 12, 2013

It always works by installing from source, but yum is preferred to install rpm to manage dependencies and updates.

If you just want php v5.3, go ahead using the php cookbook where the default option is installing php53 from CentOS yum repo.

If you want php v5.5, you can just provide another recipe to include a yum repository contains php55 like Webtatic EL yum repository or servergrove.com:

remote_file "#{Chef::Config[:file_cache_path]}/webtatic_repo_latest.rpm" do
    source "http://mirror.webtatic.com/yum/el6/latest.rpm"
    action :create
end

rpm_package "jmxtrans" do
    source "#{Chef::Config[:file_cache_path]}/webtatic_repo_latest.rpm"
    action :install
end

Then you just need to override the attribute node['php']['packages'] in your node/environment/role object to install php v5.5 via the opscode php cookbook:

node['php']['packages'] = ['php55w', 'php55w-devel', 'php55w-cli', 'php55w-pear']