Skip to content

Commit

Permalink
- moved path definitions inside of the module
Browse files Browse the repository at this point in the history
- ensured fpm log/pidfile dirs exist
- fixed bug: pear package provider did not install packages properly since the pearlist function was buggy
- add path fixes for pear/pecl to ensure that the package provider work properly
- add the possibility to override the package_name and config_file name. This is useful to adapt the SCL manners of creating configuration files for php extensions (ex.: 20-pdo.ini)
- add documentation on SCL for this module
- make ::php:globals able to modify the config_root on RedHat systems as well
  • Loading branch information
diLLec committed Jan 14, 2017
1 parent e34688d commit 10c76d0
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 78 deletions.
80 changes: 79 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Alternative to the Puppet DSL code examples above, you may optionally define you
Below are all the examples you see above, but defined in YAML format for use with Hiera.

```yaml

---
php::ensure: latest
php::manage_repos: true
Expand Down Expand Up @@ -192,7 +193,7 @@ The older Ubuntu PPAs run by Ondřej have been deprecated (ondrej/php5, ondrej/p
in favor of a new PPA: ondrej/php which contains all 3 versions of PHP: 5.5, 5.6, and 7.0
Here's an example in hiera of getting PHP 5.6 installed with php-fpm, pear/pecl, and composer:

```
```puppet
php::globals::php_version: '5.6'
php::fpm: true
php::dev: true
Expand All @@ -213,6 +214,83 @@ We prefer using php-fpm. You can find an example Apache vhost in
`manifests/apache_vhost.pp` that shows you how to use `mod_proxy_fcgi` to
connect to php-fpm.


### RedHat/CentOS SCL Users
If you plan to use the SCL repositories with this module you must do the following adjustments:

#### General config
This ensures that the module will create configurations in the directory ``/etc/opt/rh/<php_version>/` (also in php.d/
for extensions). Anyway you have to manage the SCL repo's by your own.

```puppet
class { '::php::globals':
php_version => 'rh-php56',
rhscl => true,
}->
class { '::php':
manage_repos => false
}
```

#### Extensions
Extensions in SCL are being installed with packaged that cover 1 or more .so files. This is kinda incompatible with
this module, since this module specifies an extension by name and relates the name of the package and the config (.ini)
from it. To manage extensions with SCL with this module you must use the following parameters:

```puppet
class { '::php':
...
extensions => {
bz2 => { package_name => 'common', config_file_prefix => '20-'},
calendar => { package_name => 'common', config_file_prefix => '20-'},
}
}
```

By this you tell the module to configure bz2 and calender while ensuring only the package `common`. Further the configs
will be created with the schema `<config_file_prefix><extension_title>`.

A list of commonly used modules:
```puppet
calendar => { package_name => 'common', config_file_prefix => '20-'},
ctype => { package_name => 'common', config_file_prefix => '20-'},
curl => { package_name => 'common', config_file_prefix => '20-'},
exif => { package_name => 'common', config_file_prefix => '20-'},
fileinfo => { package_name => 'common', config_file_prefix => '20-'},
ftp => { package_name => 'common', config_file_prefix => '20-'},
gettext => { package_name => 'common', config_file_prefix => '20-'},
iconv => { package_name => 'common', config_file_prefix => '20-'},
phar => { package_name => 'common', config_file_prefix => '20-'},
sockets => { package_name => 'common', config_file_prefix => '20-'},
tokenizer => { package_name => 'common', config_file_prefix => '20-'},
zip => { package_name => 'common', config_file_prefix => '20-'},
dom => { package_name => 'xml', config_file_prefix => '20-'},
simplexml => { package_name => 'xml', config_file_prefix => '20-'},
xmlwriter => { package_name => 'xml', config_file_prefix => '20-'},
xsl => { package_name => 'xml', config_file_prefix => '20-'},
wddx => { package_name => 'xml', config_file_prefix => '30-'},
xmlreader => { package_name => 'xml', config_file_prefix => '30-'},
soap => { config_file_prefix => '20-'},
pdo => { package_name => 'pdo', config_file_prefix => '20-'},
pdo_sqlite => { package_name => 'pdo', config_file_prefix => '30-'},
sqlite3 => { package_name => 'pdo', config_file_prefix => '20-'},
imap => { config_file_prefix => '20-'},
posix => { package_name => 'process', config_file_prefix => '20-'},
shmop => { package_name => 'process', config_file_prefix => '20-'},
sysvmsg => { package_name => 'process', config_file_prefix => '20-'},
sysvsem => { package_name => 'process', config_file_prefix => '20-'},
sysvshm => { package_name => 'process', config_file_prefix => '20-'},
intl => { config_file_prefix => '20-'},
gd => { config_file_prefix => '20-'},
mysqlnd => { package_name => 'mysqlnd', config_file_prefix => '20-'},
mysql => { package_name => 'mysqlnd', config_file_prefix => '30-'},
mysqli => { package_name => 'mysqlnd', config_file_prefix => '30-'},
pdo_mysql => { package_name => 'mysqlnd', config_file_prefix => '30-'},
mbstring => { config_file_prefix => '20-'},
xmlrpc => { config_file_prefix => '30-'},
json => { provider => 'pecl', package_name => 'jsonc', config_file_prefix => '40-'},
```

### Facts

We deliver a `phpversion` fact with this module. This is explicitly **NOT** intended
Expand Down
5 changes: 4 additions & 1 deletion lib/puppet/provider/package/pear.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ def self.pearlist(hash)
list = list.map do |set|
%r{INSTALLED PACKAGES, CHANNEL (.*):}i.match(set) { |m| channel = m[1].downcase }

# if hash[:justme] is specified this should only put something into pearhash if
# the line matched the string in hash[:justme]
if hash[:justme] && set =~ %r{^#{hash[:justme]}}
pearhash = pearsplit(set, channel)
pearhash[:provider] = :pear
pearhash
elsif (pearhash = pearsplit(set, channel))
elsif !hash[:justme] and (pearhash = pearsplit(set, channel))
pearhash[:provider] = :pear
pearhash
end
Expand Down Expand Up @@ -102,6 +104,7 @@ def latest
end

def query
Puppet.debug format("doing the pearlist for '%s'", @resource[:name])
self.class.pearlist(justme: @resource[:name])
end

Expand Down
13 changes: 13 additions & 0 deletions manifests/cli.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@
validate_absolute_path($inifile)
validate_hash($settings)

if $php::globals::rhscl {
file {'/usr/bin/pear':
ensure => 'link',
target => "/opt/rh/${$php::globals::php_version}/root/usr/bin/pear",
}

# stupid fixes for scl
file {'/usr/bin/pecl':
ensure => 'link',
target => "/opt/rh/${$php::globals::php_version}/root/usr/bin/pecl",
}
}

$real_settings = deep_merge($settings, hiera_hash('php::cli::settings', {}))

::php::config { 'cli':
Expand Down
78 changes: 54 additions & 24 deletions manifests/extension.pp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@
# String parameter, whether to specify ALL sapi or a specific sapi.
# Defaults to ALL.
#
# [*package_name*]
# String parameter, which can be used to override the package name. This can be useful if you have multiple extensions
# grouped into one package. Just specify multiple php::extension with the same package name.
# Defaults to namevar
#
# [*config_file_prefix*]
# String parameter, to add a prefix to config files created for this extension. This is there to make the define able
# to work with SCL packages which add forced ordering to their configs (like 20-pdo.ini)
# Defaults to namevar
#
define php::extension (
$ensure = 'installed',
$provider = undef,
Expand All @@ -66,6 +76,8 @@
$settings = {},
$settings_prefix = false,
$sapi = 'ALL',
$package_name = undef,
$config_file_prefix = undef,
) {

if ! defined(Class['php']) {
Expand All @@ -79,6 +91,8 @@
validate_string($sapi)
validate_array($header_packages)
validate_bool($zend)
validate_string($package_name)
validate_string($config_file_prefix)

if $source and $pecl_source {
fail('Only one of $source and $pecl_source can be specified.')
Expand All @@ -91,45 +105,54 @@
$real_source = $pecl_source
}

if $package_name {
$real_package_name = $package_name
}
else {
$real_package_name = $title
}

if $provider != 'none' {

if $provider == 'pecl' {
$real_package = "pecl-${title}"
$real_package = "pecl-${real_package_name}"
}
else {
$real_package = "${package_prefix}${title}"
$real_package = "${package_prefix}${real_package_name}"
}

unless empty($header_packages) {
ensure_resource('package', $header_packages)
Package[$header_packages] -> Package[$real_package]
}

if $provider == 'pecl' {
ensure_packages( [ $real_package ], {
ensure => $ensure,
provider => $provider,
source => $real_source,
require => [
Class['::php::pear'],
Class['::php::dev'],
],
})

unless empty($compiler_packages) {
ensure_resource('package', $compiler_packages)
Package[$compiler_packages] -> Package[$real_package]
if !($real_package_name in $::php::params::common_package_suffixes) and !defined(Package[$real_package]) {
if $provider == 'pecl' {
ensure_resource('package', [ $real_package ], {
ensure => $ensure,
provider => $provider,
source => $real_source,
require => [
Class['::php::pear'],
Class['::php::dev']
],
})
unless empty($compiler_packages) {
ensure_resource('package', $compiler_packages)
Package[$compiler_packages] -> Package[$real_package]
}
}
else {
ensure_resource('package', $real_package, {
ensure => $ensure,
provider => $provider,
source => $real_source,
})
}
}
else {
ensure_packages( [ $real_package ], {
ensure => $ensure,
provider => $provider,
source => $real_source,
})
}

$package_depends = "Package[${real_package}]"

} else {
$package_depends = undef
}
Expand Down Expand Up @@ -167,14 +190,21 @@
$full_settings = $settings
}

if $config_file_prefix {
$real_config_file_name = "${config_file_prefix}${lowercase_title}.ini"
}
else {
$real_config_file_name = "${lowercase_title}.ini"
}

$final_settings = deep_merge(
{"${extension_key}" => "${module_path}${so_name}.so"},
$full_settings
)

$config_root_ini = pick_default($::php::config_root_ini, $::php::params::config_root_ini)
::php::config { $title:
file => "${config_root_ini}/${lowercase_title}.ini",
file => "${config_root_ini}/${real_config_file_name}",
config => $final_settings,
require => $package_depends,
}
Expand Down
2 changes: 2 additions & 0 deletions manifests/fpm.pp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
$service_provider = $::php::fpm_service_provider,
$package = $::php::real_fpm_package,
$inifile = $::php::fpm_inifile,
$pid_file = $::php::params::fpm_pid_file,
$settings = $::php::real_settings,
$global_pool_settings = $::php::real_fpm_global_pool_settings,
$pools = $::php::real_fpm_pools,
Expand Down Expand Up @@ -87,6 +88,7 @@
settings => $real_settings,
log_owner => $log_owner,
log_group => $log_group,
pid_file => $pid_file,
require => Package[$real_package],
}
contain '::php::fpm::config'
Expand Down
6 changes: 6 additions & 0 deletions manifests/fpm/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@
mode => '0644',
}

ensure_resource('file', ['/var/run/php-fpm/', '/var/log/php-fpm/'], {
ensure => directory,
owner => $user,
group => $group,
})

file { $pool_base_dir:
ensure => directory,
owner => root,
Expand Down
Loading

0 comments on commit 10c76d0

Please sign in to comment.