Page MenuHomeSoftware Heritage

No OneTemporary

diff --git a/.fixtures.yml b/.fixtures.yml
index ff58632..1970773 100644
--- a/.fixtures.yml
+++ b/.fixtures.yml
@@ -1,9 +1,9 @@
fixtures:
repositories:
- stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
- apt: "git://github.com/puppetlabs/puppetlabs-apt.git"
- zypprepo: "git://github.com/deadpoint/puppet-zypprepo.git"
- inifile: "git://github.com/puppetlabs/puppetlabs-inifile.git"
- archive: "git://github.com/voxpupuli/puppet-archive.git"
+ stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git"
+ apt: "https://github.com/puppetlabs/puppetlabs-apt.git"
+ zypprepo: "https://github.com/deadpoint/puppet-zypprepo.git"
+ inifile: "https://github.com/puppetlabs/puppetlabs-inifile.git"
+ archive: "https://github.com/voxpupuli/puppet-archive.git"
symlinks:
php: "#{source_dir}"
diff --git a/README.md b/README.md
index c49ed40..051125f 100644
--- a/README.md
+++ b/README.md
@@ -1,334 +1,453 @@
[![Puppet Forge](http://img.shields.io/puppetforge/v/puppet/php.svg)](https://forge.puppetlabs.com/puppet/php)
[![Build Status](https://travis-ci.org/voxpupuli/puppet-php.svg?branch=master)](https://travis-ci.org/voxpupuli/puppet-php)
## Current Status
As the original creators of `puppet-php` are no longer maintaining the module, it has been handed over into the care of Vox Pupuli.
Please be sure to update all your links to the new location.
# voxpupuli/php Puppet Module
voxpupuli/php is a Puppet module for managing PHP with a strong focus
on php-fpm. The module aims to use sane defaults for the supported
architectures. We strive to support all recent versions of Debian,
Ubuntu, RedHat/CentOS, openSUSE/SLES and FreeBSD. Managing Apache
with `mod_php` is not supported.
This originally was a fork of [jippi/puppet-php](https://github.com/jippi/puppet-php)
(nodes-php on Puppet Forge) but has since been rewritten in large parts.
## Usage
Quickest way to get started is simply `include`'ing the _`php` class_.
```puppet
include '::php'
```
Or, you can override defaults and specify additional custom
configurations by declaring `class { '::php': }` with parameters:
```puppet
class { '::php':
ensure => latest,
manage_repos => true,
fpm => true,
dev => true,
composer => true,
pear => true,
phpunit => false,
}
```
Optionally the PHP version or configuration root directory can be changed also:
```puppet
class { '::php::globals':
php_version => '7.0',
config_root => '/etc/php/7.0',
}->
class { '::php':
manage_repos => true
}
```
There are more configuration options available. Please refer to the
auto-generated documentation at http://php.puppet.mayflower.de/.
### Defining `php.ini` settings
PHP configuration parameters in `php.ini` files can be defined as parameter
`settings` on the main `php` class, or `php::fpm` / `php::cli` classes,
or `php::extension` resources for each component independently.
These settings are written into their respective `php.ini` file. Global
settings in `php::settings` are merged with the settings of all components.
Please note that settings of extensions are always independent.
In the following example the PHP options and timezone will be set in
all PHP configurations, i.e. the PHP cli application and all php-fpm pools.
```puppet
class { '::php':
settings => {
'PHP/max_execution_time' => '90',
'PHP/max_input_time' => '300',
'PHP/memory_limit' => '64M',
'PHP/post_max_size' => '32M',
'PHP/upload_max_filesize' => '32M',
'Date/date.timezone' => 'Europe/Berlin',
},
}
```
### Installing extensions
PHP configuration parameters in `php.ini` files can be defined
as parameter `extensions` on the main `php` class. They are
activated for all activated SAPIs.
```puppet
class { '::php':
extensions => {
bcmath => { },
imagick => {
provider => pecl,
},
xmlrpc => { },
memcached => {
provider => 'pecl',
header_packages => [ 'libmemcached-devel', ],
},
apc => {
provider => 'pecl',
settings => {
'apc/stat' => '1',
'apc/stat_ctime' => '1',
},
sapi => 'fpm',
},
},
}
```
See [the documentation](http://php.puppet.mayflower.de/php/extension.html)
of the `php::extension` resource for all available parameters and default
values.
### Defining php-fpm pools
If different php-fpm pools are required, you can use `php::fpm::pool`
defined resource type. A single pool called `www` will be configured
by default. Specify additional pools like so:
```puppet
php::fpm::pool { 'www2':
listen => '127.0.1.1:9000',
}
```
For an overview of all possible parameters for `php::fpm::pool` resources
please see [its documention](http://php.puppet.mayflower.de/php/fpm/pool.html).
### Overriding php-fpm user
By default, php-fpm is set up to run as Apache. If you need to customize that user, you can do that like so:
```puppet
class { '::php':
fpm_user => 'nginx',
fpm_group => 'nginx',
}
```
### PHP with one FPM pool per user
This will create one vhost. $users is an array of people having php files at
$fqdn/$user. This codesnipped uses voxpupuli/php and voxpupuli/nginx to create
the vhost and one php fpm pool per user. This was tested on Archlinux with
nginx 1.13 and PHP 7.2.3.
```puppet
$users = ['bob', 'alice']
class { 'php':
ensure => 'present',
manage_repos => false,
fpm => true,
dev => false,
composer => false,
pear => true,
phpunit => false,
fpm_pools => {},
}
include nginx
nginx::resource::server{$facts['fqdn']:
www_root => '/var/www',
autoindex => 'on',
}
nginx::resource::location{'dontexportprivatedata':
server => $facts['fqdn'],
location => '~ /\.',
location_deny => ['all'],
}
$users.each |$user| {
# create one fpm pool. will be owned by the specific user
# fpm socket will be owned by the nginx user 'http'
php::fpm::pool{$user:
user => $user,
group => $user,
listen_owner => 'http',
listen_group => 'http',
listen_mode => '0660',
listen => "/var/run/php-fpm/${user}-fpm.sock",
}
nginx::resource::location { "${name}_root":
ensure => 'present',
server => $facts['fqdn'],
location => "~ .*${user}\/.*\.php$",
index_files => ['index.php'],
fastcgi => "unix:/var/run/php-fpm/${user}-fpm.sock",
include => ['fastcgi.conf'],
}
}
```
### Alternative examples using Hiera
Alternative to the Puppet DSL code examples above, you may optionally define your PHP configuration using Hiera.
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
php::fpm: true
php::fpm_user: 'nginx'
php::fpm_group: 'nginx'
php::dev: true
php::composer: true
php::pear: true
php::phpunit: false
php::settings:
'PHP/max_execution_time': '90'
'PHP/max_input_time': '300'
'PHP/memory_limit': '64M'
'PHP/post_max_size': '32M'
'PHP/upload_max_filesize': '32M'
'Date/date.timezone': 'Europe/Berlin'
php::extensions:
bcmath: {}
xmlrpc: {}
imagick:
provider: pecl
memcached:
provider: pecl
header_packages:
- libmemcached-dev
apc:
provider: pecl
settings:
'apc/stat': 1
'apc/stat_ctime': 1
sapi: 'fpm'
php::fpm::pools:
www2:
listen: '127.0.1.1:9000'
```
## Notes
### Debian squeeze & Ubuntu precise come with PHP 5.3
On Debian-based systems, we use `php5enmod` to enable extension-specific
configuration. This script is only present in `php5` packages beginning with
version 5.4. Furthermore, PHP 5.3 is not supported by upstream anymore.
We strongly suggest you use a recent PHP version, even if you're using an
older though still supported distribution release. Our default is to have
`php::manage_repos` enabled to add apt sources for
[Dotdeb](http://www.dotdeb.org/) on Debian and
[ppa:ondrej/php5](https://launchpad.net/~ondrej/+archive/ubuntu/php5/) on
Ubuntu with packages for the current stable PHP version closely tracking
upstream.
### Ubuntu systems and Ondřej's PPA
The older Ubuntu PPAs run by Ondřej have been deprecated (ondrej/php5, ondrej/php5.6)
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
php::composer: true
php::pear: true
php::phpunit: false
```
If you do not specify a php version, in Ubuntu the default will be 7.0 if you are
running Xenial (16.04), otherwise PHP 5.6 will be installed (for other versions)
### Apache support
Apache with `mod_php` is not supported by this module. Please use
[puppetlabs/apache](https://forge.puppetlabs.com/puppetlabs/apache) instead.
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-php71',
+ rhscl => true,
+}->
+class { '::php':
+ manage_repos => false
+}
+```
+
+#### Extensions
+Extensions in SCL are being installed with packages that cover 1 or more .so files. This is kinda incompatible with
+this module, since this module specifies an extension by name and derives the name of the package and the config (.ini)
+from it. To manage extensions of SCL packages you must use the following parameters:
+
+```puppet
+class { '::php':
+ ...
+ extensions => {
+ 'soap' => {
+ ini_prefix => '20-',
+ },
+ }
+}
+```
+
+By this you tell the module to configure bz2 and calender while ensuring only the package `common`. Additionally to the
+installation of 'common' the inifiles 'calender.ini' and 'bz2.ini' will be created by the scheme
+`<config_file_prefix><extension_title>`.
+
+A list of commonly used modules:
+```puppet
+ {
+ extensions => {
+ 'xml' => {
+ ini_prefix => '20-',
+ multifile_settings => true,
+ settings => {
+ 'dom' => {},
+ 'simplexml' => {},
+ 'xmlwriter' => {},
+ 'xsl' => {},
+ 'wddx' => {},
+ 'xmlreader' => {},
+ },
+ },
+ 'soap' => {
+ ini_prefix => '20-',
+ },
+ 'imap' => {
+ ini_prefix => '20-',
+ },
+ 'intl' => {
+ ini_prefix => '20-',
+ },
+ 'gd' => {
+ ini_prefix => '20-',
+ },
+ 'mbstring' => {
+ ini_prefix => '20-',
+ },
+ 'xmlrpc' => {
+ ini_prefix => '20-',
+ },
+ 'pdo' => {
+ ini_prefix => '20-',
+ multifile_settings => true,
+ settings => {
+ 'pdo' => {},
+ 'pdo_sqlite' => {},
+ 'sqlite3' => {},
+ },
+ },
+ 'process' => {
+ ini_prefix => '20-',
+ multifile_settings => true,
+ settings => {
+ 'posix' => {},
+ 'shmop' => {},
+ 'sysvmsg' => {},
+ 'sysvsem' => {},
+ 'sysvshm' => {},
+ },
+ },
+ 'mysqlnd' => {
+ ini_prefix => '30-',
+ multifile_settings => true,
+ settings => {
+ 'mysqlnd' => {},
+ 'mysql' => {},
+ 'mysqli' => {},
+ 'pdo_mysql' => {},
+ 'sysvshm' => {},
+ },
+ },
+ 'mysqlnd' => {
+ ini_prefix => '30-',
+ multifile_settings => true,
+ settings => {
+ 'mysqlnd' => {},
+ 'mysql' => {},
+ 'mysqli' => {},
+ 'pdo_mysql' => {},
+ 'sysvshm' => {},
+ },
+ },
+ }
+ }
+```
+
### Facts
We deliver a `phpversion` fact with this module. This is explicitly **NOT** intended
to be used within your puppet manifests as it will only work on your second puppet
run. Its intention is to make querying PHP versions per server easy via PuppetDB or Foreman.
### FreeBSD support
On FreeBSD systems we purge the system-wide `extensions.ini` in favour of
per-module configuration files.
Please also note that support for Composer and PHPUnit on FreeBSD is untested
and thus likely incomplete.
### Running the test suite
To run the tests install the ruby dependencies with `bundler` and execute
`rake`:
```
bundle install --path vendor/bundle
bundle exec rake
```
## Bugs & New Features
If you happen to stumble upon a bug, please feel free to create a pull request
with a fix (optionally with a test), and a description of the bug and how it
was resolved.
Or if you're not into coding, simply create an issue adding steps to let us
reproduce the bug and we will happily fix it.
If you have a good idea for a feature or how to improve this module in general,
please create an issue to discuss it. We are very open to feedback. Pull
requests are always welcome.
We hate orphaned and unmaintained Puppet modules as much as you do and
therefore promise that we will continue to maintain this module and keep
response times to issues short. If we happen to lose interest, we will write
a big fat warning into this README to let you know.
## License
The project is released under the permissive MIT license.
The source can be found at
[github.com/voxpupuli/puppet-php](https://github.com/voxpupuli/puppet-php/).
This Puppet module was originally maintained by some fellow puppeteers at
[Mayflower GmbH](https://mayflower.de) and is now maintained by
[Vox Pupuli](https://voxpupuli.org/).
diff --git a/manifests/cli.pp b/manifests/cli.pp
index 1776b6c..c29619c 100644
--- a/manifests/cli.pp
+++ b/manifests/cli.pp
@@ -1,24 +1,45 @@
# Install and configure php CLI
#
# === Parameters
#
# [*inifile*]
# The path to the ini php5-cli ini file
#
# [*settings*]
# Hash with nested hash of key => value to set in inifile
#
class php::cli(
Stdlib::Absolutepath $inifile = $php::params::cli_inifile,
Hash $settings = {}
) inherits php::params {
assert_private()
+ if $php::globals::rhscl_mode {
+ # stupid fixes for scl
+ file {'/usr/bin/pear':
+ ensure => 'link',
+ target => "${$php::params::php_bin_dir}/pear",
+ }
+
+ file {'/usr/bin/pecl':
+ ensure => 'link',
+ target => "${$php::params::php_bin_dir}/pecl",
+ }
+
+ file {'/usr/bin/php':
+ ensure => 'link',
+ target => "${$php::params::php_bin_dir}/php",
+ }
+ }
+
$real_settings = deep_merge($settings, hiera_hash('php::cli::settings', {}))
- ::php::config { 'cli':
- file => $inifile,
- config => $real_settings,
+ if $inifile != $php::params::config_root_inifile {
+ # only create a cli specific inifile if the filenames are different
+ ::php::config { 'cli':
+ file => $inifile,
+ config => $real_settings,
+ }
}
}
diff --git a/manifests/extension.pp b/manifests/extension.pp
index 9ee7932..8ae05e1 100644
--- a/manifests/extension.pp
+++ b/manifests/extension.pp
@@ -1,109 +1,130 @@
# Install a PHP extension package
#
# === Parameters
#
# [*ensure*]
# The ensure of the package to install
# Could be "latest", "installed" or a pinned version
#
# [*package_prefix*]
# Prefix to prepend to the package name for the package provider
#
# [*provider*]
# The provider used to install the package
# Could be "pecl", "apt", "dpkg" or any other OS package provider
# If set to "none", no package will be installed
#
# [*source*]
# The source to install the extension from. Possible values
# depend on the *provider* used
#
# [*so_name*]
# The DSO name of the package (e.g. opcache for zendopcache)
#
# [*ini_prefix*]
# An optional filename prefix for the settings file of the extension
#
# [*php_api_version*]
# This parameter is used to build the full path to the extension
# directory for zend_extension in PHP < 5.5 (e.g. 20100525)
#
# [*header_packages*]
# System packages dependencies to install for extensions (e.g. for
# memcached libmemcached-dev on Debian)
#
# [*compiler_packages*]
# System packages dependencies to install for compiling extensions
# (e.g. build-essential on Debian)
#
# [*zend*]
# Boolean parameter, whether to load extension as zend_extension.
# Defaults to false.
#
# [*settings*]
-# Nested hash of global config parameters for php.ini
+# Hash of parameters for the specific extension, which will be written to the extensions config file by
+# php::extension::config or a hash of mutliple settings files, each with parameters
+# (multifile_settings must be true)
+# (f.ex. {p => '..'} or {'bz2' => {..}, {'math' => {...}})
+#
+# [*multifile_settings*]
+# Set this to true if you specify multiple setting files in *settings*. This must be used when the PHP package
+# distribution bundles extensions in a single package (like 'common' bundles extensions 'bz2', ...) and each of
+# the extension comes with a separate settings file.
#
# [*settings_prefix*]
# Boolean/String parameter, whether to prefix all setting keys with
# the extension name or specified name. Defaults to false.
#
# [*sapi*]
# String parameter, whether to specify ALL sapi or a specific sapi.
# Defaults to ALL.
#
# [*responsefile*]
# File containing answers for interactive extension setup. Supported
# *providers*: pear, pecl.
#
# [*install_options*]
# Array of String or Hash options to pass to the provider.
#
define php::extension (
String $ensure = 'installed',
Optional[Php::Provider] $provider = undef,
Optional[String] $source = undef,
- Optional[String] $so_name = downcase($name),
+ Optional[String] $so_name = undef,
Optional[String] $ini_prefix = undef,
Optional[String] $php_api_version = undef,
String $package_prefix = $php::package_prefix,
Boolean $zend = false,
- Hash $settings = {},
+ Variant[Hash, Hash[String, Hash]] $settings = {},
+ Boolean $multifile_settings = false,
Php::Sapi $sapi = 'ALL',
Variant[Boolean, String] $settings_prefix = false,
Optional[Stdlib::AbsolutePath] $responsefile = undef,
Variant[String, Array[String]] $header_packages = [],
Variant[String, Array[String]] $compiler_packages = $php::params::compiler_packages,
Php::InstallOptions $install_options = undef,
) {
if ! defined(Class['php']) {
warning('php::extension is private')
}
php::extension::install { $title:
ensure => $ensure,
provider => $provider,
source => $source,
responsefile => $responsefile,
package_prefix => $package_prefix,
header_packages => $header_packages,
compiler_packages => $compiler_packages,
install_options => $install_options,
}
# PEAR packages don't require any further configuration, they just need to "be there".
if $provider != 'pear' {
- php::extension::config { $title:
- ensure => $ensure,
- provider => $provider,
- so_name => $so_name,
- ini_prefix => $ini_prefix,
- php_api_version => $php_api_version,
- zend => $zend,
- settings => $settings,
- settings_prefix => $settings_prefix,
- sapi => $sapi,
- subscribe => Php::Extension::Install[$title],
+ $_settings = $multifile_settings ? {
+ true => $settings,
+ false => { downcase($title) => $settings } # emulate a hash if no multifile settings
+ }
+
+ $_settings.each |$settings_name, $settings_hash| {
+ $so_name = $multifile_settings ? {
+ true => downcase($settings_name),
+ false => pick(downcase($so_name), downcase($name), downcase($settings_name)),
+ }
+
+ php::extension::config { $settings_name:
+ ensure => $ensure,
+ provider => $provider,
+ so_name => $so_name,
+ ini_prefix => $ini_prefix,
+ php_api_version => $php_api_version,
+ zend => $zend,
+ settings => $settings_hash,
+ settings_prefix => $settings_prefix,
+ sapi => $sapi,
+ subscribe => Php::Extension::Install[$title],
+ }
}
}
}
diff --git a/manifests/fpm.pp b/manifests/fpm.pp
index 76a88fe..aa9c953 100644
--- a/manifests/fpm.pp
+++ b/manifests/fpm.pp
@@ -1,121 +1,122 @@
# Install and configure mod_php for fpm
#
# === Parameters
#
# [*user*]
# The user that php-fpm should run as
#
# [*group*]
# The group that php-fpm should run as
#
# [*service_enable*]
# Enable/disable FPM service
#
# [*service_ensure*]
# Ensure FPM service is either 'running' or 'stopped'
#
# [*service_name*]
# This is the name of the php-fpm service. It defaults to reasonable OS
# defaults but can be different in case of using php7.0/other OS/custom fpm service
#
# [*service_provider*]
# This is the name of the service provider, in case there is a non
# OS default service provider used to start FPM.
# Defaults to 'undef', pick system defaults.
#
# [*pools*]
# Hash of php::fpm::pool resources that will be created. Defaults
# to a single php::fpm::pool named www with default parameters.
#
# [*log_owner*]
# The php-fpm log owner
#
# [*log_group*]
# The group owning php-fpm logs
#
# [*package*]
# Specify which package to install
#
# [*ensure*]
# Specify which version of the package to install
#
# [*inifile*]
# Path to php.ini for fpm
#
# [*settings*]
# fpm settings hash
#
# [*global_pool_settings*]
# Hash of defaults params php::fpm::pool resources that will be created.
# Defaults is empty hash.
#
class php::fpm (
String $ensure = $php::ensure,
$user = $php::fpm_user,
$group = $php::fpm_group,
$service_ensure = $php::fpm_service_ensure,
$service_enable = $php::fpm_service_enable,
$service_name = $php::fpm_service_name,
$service_provider = $php::fpm_service_provider,
String $package = $php::real_fpm_package,
Stdlib::Absolutepath $inifile = $php::fpm_inifile,
Hash $settings = $php::real_settings,
$global_pool_settings = $php::real_fpm_global_pool_settings,
Hash $pools = $php::real_fpm_pools,
$log_owner = $php::log_owner,
$log_group = $php::log_group,
) {
if ! defined(Class['php']) {
warning('php::fpm is private')
}
$real_settings = deep_merge($settings, hiera_hash('php::fpm::settings', {}))
# On FreeBSD fpm is not a separate package, but included in the 'php' package.
# Implies that the option SET+=FPM was set when building the port.
$real_package = $facts['os']['family'] ? {
'FreeBSD' => [],
default => $package,
}
package { $real_package:
ensure => $ensure,
require => Class['php::packages'],
}
class { 'php::fpm::config':
user => $user,
group => $group,
inifile => $inifile,
settings => $real_settings,
log_owner => $log_owner,
log_group => $log_group,
require => Package[$real_package],
}
+
contain 'php::fpm::config'
contain 'php::fpm::service'
Class['php::fpm::config'] ~> Class['php::fpm::service']
$real_global_pool_settings = hiera_hash('php::fpm::global_pool_settings', $global_pool_settings)
$real_pools = hiera_hash('php::fpm::pools', $pools)
create_resources(::php::fpm::pool, $real_pools, $real_global_pool_settings)
# Create an override to use a reload signal as trusty and utopic's
# upstart version supports this
if ($facts['os']['name'] == 'Ubuntu'
and versioncmp($facts['os']['release']['full'], '14') >= 0
and versioncmp($facts['os']['release']['full'], '16') < 0) {
if ($service_enable) {
$fpm_override = 'reload signal USR2'
}
else {
$fpm_override = "reload signal USR2\nmanual"
}
file { "/etc/init/${::php::fpm::service::service_name}.override":
content => $fpm_override,
before => Package[$real_package],
}
}
}
diff --git a/manifests/fpm/config.pp b/manifests/fpm/config.pp
index 99fb70c..c255a85 100644
--- a/manifests/fpm/config.pp
+++ b/manifests/fpm/config.pp
@@ -1,132 +1,140 @@
# Configure php-fpm service
#
# === Parameters
#
# [*config_file*]
# The path to the fpm config file
#
# [*user*]
# The user that runs php-fpm
#
# [*group*]
# The group that runs php-fpm
#
# [*inifile*]
# The path to ini file
#
# [*settings*]
# Nested hash of key => value to apply to php.ini
#
# [*pool_base_dir*]
# The folder that contains the php-fpm pool configs
#
# [*pool_purge*]
# Whether to purge pool config files not created
# by this module
#
# [*error_log*]
# Path to error log file. If it's set to "syslog", log is
# sent to syslogd instead of being written in a local file.
#
# [*log_level*]
# The php-fpm log level
#
# [*emergency_restart_threshold*]
# The php-fpm emergency_restart_threshold
#
# [*emergency_restart_interval*]
# The php-fpm emergency_restart_interval
#
# [*process_control_timeout*]
# The php-fpm process_control_timeout
#
# [*process_max*]
# The maximum number of processes FPM will fork.
#
# [*rlimit_files*]
# Set open file descriptor rlimit for the master process.
#
# [*systemd_interval*]
# The interval between health report notification to systemd
#
# [*log_owner*]
# The php-fpm log owner
#
# [*log_group*]
# The group owning php-fpm logs
#
# [*log_dir_mode*]
# The octal mode of the directory
#
# [*syslog_facility*]
# Used to specify what type of program is logging the message
#
# [*syslog_ident*]
# Prepended to every message
#
# [*root_group*]
# UNIX group of the root user
#
# [*pid_file*]
# Path to fpm pid file
#
class php::fpm::config(
$config_file = $php::params::fpm_config_file,
String $user = $php::params::fpm_user,
String $group = $php::params::fpm_group,
String $inifile = $php::params::fpm_inifile,
$pid_file = $php::params::fpm_pid_file,
Hash $settings = {},
Stdlib::Absolutepath $pool_base_dir = $php::params::fpm_pool_dir,
$pool_purge = false,
String $error_log = $php::params::fpm_error_log,
String $log_level = 'notice',
Integer $emergency_restart_threshold = 0,
Variant[Integer, Pattern[/^\d+[smhd]?$/]] $emergency_restart_interval = 0,
Variant[Integer, Pattern[/^\d+[smhd]?$/]] $process_control_timeout = 0,
Integer $process_max = 0,
$rlimit_files = undef,
Optional[Variant[Integer,Pattern[/^\d+[smhd]?$/]]] $systemd_interval = undef,
String $log_owner = $php::params::fpm_user,
String $log_group = $php::params::fpm_group,
Pattern[/^\d+$/] $log_dir_mode = '0770',
$root_group = $php::params::root_group,
String $syslog_facility = 'daemon',
String $syslog_ident = 'php-fpm',
) inherits php::params {
assert_private()
# Hack-ish to default to user for group too
$log_group_final = $log_group ? {
undef => $log_owner,
default => $log_group,
}
file { $config_file:
ensure => file,
content => template('php/fpm/php-fpm.conf.erb'),
owner => root,
group => $root_group,
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,
group => $root_group,
mode => '0755',
}
if $pool_purge {
File[$pool_base_dir] {
purge => true,
recurse => true,
}
}
- ::php::config { 'fpm':
- file => $inifile,
- config => $settings,
+ if $inifile != $php::params::config_root_inifile {
+ ::php::config { 'fpm':
+ file => $inifile,
+ config => $settings,
+ }
}
}
diff --git a/manifests/globals.pp b/manifests/globals.pp
index 522a7b4..c2414b8 100644
--- a/manifests/globals.pp
+++ b/manifests/globals.pp
@@ -1,128 +1,160 @@
# PHP globals class
#
# === Parameters
#
# [*php_version*]
# The version of php.
#
# [*config_root*]
# The configuration root directory.
#
# [*fpm_pid_file*]
# Path to pid file for fpm
+#
+# [*rhscl_mode*]
+# The mode specifies the specifics in paths for the various RedHat SCL environments so that the module is configured
+# correctly on their pathnames.
+#
+# Valid modes are: 'rhscl', 'remi'
+#
class php::globals (
- Optional[Pattern[/^[57].[0-9]/]] $php_version = undef,
+
+ Optional[Pattern[/^(rh-)?(php)?[57](\.)?[0-9]/]] $php_version = undef,
Optional[Stdlib::Absolutepath] $config_root = undef,
Optional[Stdlib::Absolutepath] $fpm_pid_file = undef,
+ $rhscl_mode = undef,
) {
$default_php_version = $facts['os']['name'] ? {
'Debian' => $facts['os']['release']['major'] ? {
'9' => '7.0',
default => '5.x',
},
'Ubuntu' => $facts['os']['release']['major'] ? {
'18.04' => '7.2',
'16.04' => '7.0',
default => '5.x',
},
default => '5.x',
}
$globals_php_version = pick($php_version, $default_php_version)
case $facts['os']['family'] {
'Debian': {
if $facts['os']['name'] == 'Ubuntu' {
case $globals_php_version {
/^5\.4/: {
- $default_config_root = '/etc/php5'
+ $default_config_root = '/etc/php5'
$default_fpm_pid_file = "/var/run/php/php${globals_php_version}-fpm.pid"
- $fpm_error_log = '/var/log/php5-fpm.log'
- $fpm_service_name = 'php5-fpm'
- $ext_tool_enable = '/usr/sbin/php5enmod'
- $ext_tool_query = '/usr/sbin/php5query'
- $package_prefix = 'php5-'
+ $fpm_error_log = '/var/log/php5-fpm.log'
+ $fpm_service_name = 'php5-fpm'
+ $ext_tool_enable = '/usr/sbin/php5enmod'
+ $ext_tool_query = '/usr/sbin/php5query'
+ $package_prefix = 'php5-'
}
/^[57].[0-9]/: {
- $default_config_root = "/etc/php/${globals_php_version}"
+ $default_config_root = "/etc/php/${globals_php_version}"
$default_fpm_pid_file = "/var/run/php/php${globals_php_version}-fpm.pid"
- $fpm_error_log = "/var/log/php${globals_php_version}-fpm.log"
- $fpm_service_name = "php${globals_php_version}-fpm"
- $ext_tool_enable = "/usr/sbin/phpenmod -v ${globals_php_version}"
- $ext_tool_query = "/usr/sbin/phpquery -v ${globals_php_version}"
- $package_prefix = "php${globals_php_version}-"
+ $fpm_error_log = "/var/log/php${globals_php_version}-fpm.log"
+ $fpm_service_name = "php${globals_php_version}-fpm"
+ $ext_tool_enable = "/usr/sbin/phpenmod -v ${globals_php_version}"
+ $ext_tool_query = "/usr/sbin/phpquery -v ${globals_php_version}"
+ $package_prefix = "php${globals_php_version}-"
}
default: {
# Default php installation from Ubuntu official repository use the following paths until 16.04
# For PPA please use the $php_version to override it.
- $default_config_root = '/etc/php5'
+ $default_config_root = '/etc/php5'
$default_fpm_pid_file = '/var/run/php5-fpm.pid'
- $fpm_error_log = '/var/log/php5-fpm.log'
- $fpm_service_name = 'php5-fpm'
- $ext_tool_enable = '/usr/sbin/php5enmod'
- $ext_tool_query = '/usr/sbin/php5query'
- $package_prefix = 'php5-'
+ $fpm_error_log = '/var/log/php5-fpm.log'
+ $fpm_service_name = 'php5-fpm'
+ $ext_tool_enable = '/usr/sbin/php5enmod'
+ $ext_tool_query = '/usr/sbin/php5query'
+ $package_prefix = 'php5-'
}
}
} else {
case $globals_php_version {
/^7\.[0-9]/: {
$default_config_root = "/etc/php/${globals_php_version}"
$default_fpm_pid_file = "/var/run/php/php${globals_php_version}-fpm.pid"
$fpm_error_log = "/var/log/php${globals_php_version}-fpm.log"
$fpm_service_name = "php${globals_php_version}-fpm"
$ext_tool_enable = "/usr/sbin/phpenmod -v ${globals_php_version}"
$ext_tool_query = "/usr/sbin/phpquery -v ${globals_php_version}"
$package_prefix = "php${globals_php_version}-"
}
default: {
- $default_config_root = '/etc/php5'
+ $default_config_root = '/etc/php5'
$default_fpm_pid_file = '/var/run/php5-fpm.pid'
- $fpm_error_log = '/var/log/php5-fpm.log'
- $fpm_service_name = 'php5-fpm'
- $ext_tool_enable = '/usr/sbin/php5enmod'
- $ext_tool_query = '/usr/sbin/php5query'
- $package_prefix = 'php5-'
+ $fpm_error_log = '/var/log/php5-fpm.log'
+ $fpm_service_name = 'php5-fpm'
+ $ext_tool_enable = '/usr/sbin/php5enmod'
+ $ext_tool_query = '/usr/sbin/php5query'
+ $package_prefix = 'php5-'
}
}
}
}
'Suse': {
case $globals_php_version {
/^7/: {
- $default_config_root = '/etc/php7'
- $package_prefix = 'php7-'
+ $default_config_root = '/etc/php7'
+ $package_prefix = 'php7-'
$default_fpm_pid_file = '/var/run/php7-fpm.pid'
- $fpm_error_log = '/var/log/php7-fpm.log'
+ $fpm_error_log = '/var/log/php7-fpm.log'
}
default: {
- $default_config_root = '/etc/php5'
- $package_prefix = 'php5-'
+ $default_config_root = '/etc/php5'
+ $package_prefix = 'php5-'
$default_fpm_pid_file = '/var/run/php5-fpm.pid'
- $fpm_error_log = '/var/log/php5-fpm.log'
+ $fpm_error_log = '/var/log/php5-fpm.log'
}
}
}
'RedHat': {
- $default_config_root = '/etc'
- $default_fpm_pid_file = '/var/run/php-fpm/php-fpm.pid'
+ case $rhscl_mode {
+ 'remi': {
+ $rhscl_root = "/opt/remi/${php_version}/root"
+ $default_config_root = "/etc/opt/remi/${php_version}"
+ $default_fpm_pid_file = '/var/run/php-fpm/php-fpm.pid'
+ $package_prefix = "${php_version}-php-"
+ $fpm_service_name = "${php_version}-php-fpm"
+ }
+ 'rhscl': {
+ $rhscl_root = "/opt/rh/${php_version}/root"
+ $default_config_root = "/etc/opt/rh/${php_version}" # rhscl registers contents by copy in /etc/opt/rh
+ $default_fpm_pid_file = "/var/opt/rh/${php_version}/run/php-fpm/php-fpm.pid"
+ $package_prefix = "${php_version}-php-"
+ $fpm_service_name = "${php_version}-php-fpm"
+ }
+ undef: {
+ $default_config_root = '/etc/php.d'
+ $default_fpm_pid_file = '/var/run/php-fpm/php-fpm.pid'
+ $fpm_service_name = undef
+ $package_prefix = undef
+ }
+ default: {
+ fail("Unsupported rhscl_mode '${rhscl_mode}'")
+ }
+ }
}
'FreeBSD': {
$default_config_root = '/usr/local/etc'
$default_fpm_pid_file = '/var/run/php-fpm.pid'
+ $fpm_service_name = undef
}
'Archlinux': {
$default_config_root = '/etc/php'
$default_fpm_pid_file = '/run/php-fpm/php-fpm.pid'
}
default: {
fail("Unsupported osfamily: ${facts['os']['family']}")
}
}
- $globals_config_root = pick($config_root, $default_config_root)
-
- $globals_fpm_pid_file = pick($fpm_pid_file, $default_fpm_pid_file)
+ $globals_config_root = pick($config_root, $default_config_root)
+ $globals_fpm_pid_file = pick($fpm_pid_file, $default_fpm_pid_file)
}
diff --git a/manifests/params.pp b/manifests/params.pp
index f4d9acd..6c83eeb 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -1,192 +1,220 @@
# PHP params class
#
class php::params inherits php::globals {
$ensure = 'present'
$fpm_service_enable = true
$fpm_service_ensure = 'running'
$composer_source = 'https://getcomposer.org/composer.phar'
$composer_path = '/usr/local/bin/composer'
$composer_max_age = 30
$pear_ensure = 'present'
$pear_package_suffix = 'pear'
$phpunit_source = 'https://phar.phpunit.de/phpunit.phar'
$phpunit_path = '/usr/local/bin/phpunit'
$phpunit_max_age = 30
case $facts['os']['family'] {
'Debian': {
$config_root = $php::globals::globals_config_root
$config_root_ini = "${config_root}/mods-available"
$config_root_inifile = "${config_root}/php.ini"
$common_package_names = []
$common_package_suffixes = ['cli', 'common']
$cli_inifile = "${config_root}/cli/php.ini"
$dev_package_suffix = 'dev'
$fpm_pid_file = $php::globals::globals_fpm_pid_file
$fpm_config_file = "${config_root}/fpm/php-fpm.conf"
$fpm_error_log = $php::globals::fpm_error_log
$fpm_inifile = "${config_root}/fpm/php.ini"
$fpm_package_suffix = 'fpm'
$fpm_pool_dir = "${config_root}/fpm/pool.d"
$fpm_service_name = $php::globals::fpm_service_name
$fpm_user = 'www-data'
$fpm_group = 'www-data'
$apache_inifile = "${config_root}/apache2/php.ini"
$embedded_package_suffix = 'embed'
$embedded_inifile = "${config_root}/embed/php.ini"
$package_prefix = $php::globals::package_prefix
$compiler_packages = 'build-essential'
$root_group = 'root'
$ext_tool_enable = $php::globals::ext_tool_enable
$ext_tool_query = $php::globals::ext_tool_query
$ext_tool_enabled = true
case $facts['os']['name'] {
'Debian': {
$manage_repos = (versioncmp($facts['os']['release']['major'], '8') < 0)
}
'Ubuntu': {
$manage_repos = false
}
default: {
$manage_repos = false
}
}
}
'Suse': {
if ($php::globals::php_version != undef) {
$php_version_major = regsubst($php::globals::php_version, '^(\d+)\.(\d+)$','\1')
} else {
$php_version_major = 5
}
$config_root = $php::globals::globals_config_root
$config_root_ini = "${config_root}/conf.d"
$config_root_inifile = "${config_root}/php.ini"
$common_package_names = ["php${php_version_major}"]
$common_package_suffixes = []
$cli_inifile = "${config_root}/cli/php.ini"
$dev_package_suffix = 'devel'
$fpm_pid_file = $php::globals::globals_fpm_pid_file
$fpm_config_file = "${config_root}/fpm/php-fpm.conf"
$fpm_error_log = $php::globals::fpm_error_log
$fpm_inifile = "${config_root}/fpm/php.ini"
$fpm_package_suffix = 'fpm'
$fpm_pool_dir = "${config_root}/fpm/pool.d"
$fpm_service_name = 'php-fpm'
$fpm_user = 'wwwrun'
$fpm_group = 'www'
$embedded_package_suffix = 'embed'
$embedded_inifile = "${config_root}/embed/php.ini"
$package_prefix = $php::globals::package_prefix
$manage_repos = true
$root_group = 'root'
$ext_tool_enable = undef
$ext_tool_query = undef
$ext_tool_enabled = false
case $facts['os']['name'] {
'SLES': {
$compiler_packages = []
}
'OpenSuSE': {
$compiler_packages = 'devel_basis'
}
default: {
fail("Unsupported operating system ${facts['os']['name']}")
}
}
}
'RedHat': {
- $config_root = $php::globals::globals_config_root
- $config_root_ini = "${config_root}/php.d"
- $config_root_inifile = "${config_root}/php.ini"
+ $config_root = $php::globals::globals_config_root
+
+ case $php::globals::rhscl_mode {
+ 'remi': {
+ $config_root_ini = "${config_root}/php.d"
+ $config_root_inifile = "${config_root}/php.ini"
+ $cli_inifile = $config_root_inifile
+ $fpm_inifile = $config_root_inifile
+ $fpm_config_file = "${config_root}/php-fpm.conf"
+ $fpm_pool_dir = "${config_root}/php-fpm.d"
+ $php_bin_dir = "${php::globals::rhscl_root}/bin"
+ }
+ 'rhscl': {
+ $config_root_ini = "${config_root}/php.d"
+ $config_root_inifile = "${config_root}/php.ini"
+ $cli_inifile = "${config_root}/php-cli.ini"
+ $fpm_inifile = "${config_root}/php-fpm.ini"
+ $fpm_config_file = "${config_root}/php-fpm.conf"
+ $fpm_pool_dir = "${config_root}/php-fpm.d"
+ $php_bin_dir = "${php::globals::rhscl_root}/bin"
+ }
+ undef: {
+ # no rhscl
+ $config_root_ini = $config_root
+ $config_root_inifile = '/etc/php.ini'
+ $cli_inifile = '/etc/php-cli.ini'
+ $fpm_inifile = '/etc/php-fpm.ini'
+ $fpm_config_file = '/etc/php-fpm.conf'
+ $fpm_pool_dir = '/etc/php-fpm.d'
+ }
+ default: {
+ fail("Unsupported rhscl_mode '${php::globals::rhscl_mode}'")
+ }
+ }
+
+ $apache_inifile = $config_root_inifile
+ $embedded_inifile = $config_root_inifile
$common_package_names = []
$common_package_suffixes = ['cli', 'common']
- $cli_inifile = "${config_root}/php-cli.ini"
$dev_package_suffix = 'devel'
$fpm_pid_file = $php::globals::globals_fpm_pid_file
- $fpm_config_file = "${config_root}/php-fpm.conf"
$fpm_error_log = '/var/log/php-fpm/error.log'
- $fpm_inifile = "${config_root}/php-fpm.ini"
$fpm_package_suffix = 'fpm'
- $fpm_pool_dir = "${config_root}/php-fpm.d"
- $fpm_service_name = 'php-fpm'
+ $fpm_service_name = pick($php::globals::fpm_service_name, 'php-fpm')
$fpm_user = 'apache'
$fpm_group = 'apache'
- $apache_inifile = "${config_root}/php.ini"
$embedded_package_suffix = 'embedded'
- $embedded_inifile = "${config_root}/php.ini"
- $package_prefix = 'php-'
+ $package_prefix = pick($php::globals::package_prefix, 'php-')
$compiler_packages = ['gcc', 'gcc-c++', 'make']
$manage_repos = false
$root_group = 'root'
$ext_tool_enable = undef
$ext_tool_query = undef
$ext_tool_enabled = false
}
'FreeBSD': {
$config_root = $php::globals::globals_config_root
$config_root_ini = "${config_root}/php"
$config_root_inifile = "${config_root}/php.ini"
# No common packages, because the required PHP base package will be
# pulled in as a dependency. This preserves the ability to choose
# any available PHP version by setting the 'package_prefix' parameter.
$common_package_names = []
$common_package_suffixes = ['extensions']
$cli_inifile = "${config_root}/php-cli.ini"
$dev_package_suffix = undef
$fpm_pid_file = $php::globals::globals_fpm_pid_file
$fpm_config_file = "${config_root}/php-fpm.conf"
$fpm_error_log = '/var/log/php-fpm.log'
$fpm_inifile = "${config_root}/php-fpm.ini"
$fpm_package_suffix = undef
$fpm_pool_dir = "${config_root}/php-fpm.d"
$fpm_service_name = 'php-fpm'
$fpm_user = 'www'
$fpm_group = 'www'
$embedded_package_suffix = 'embed'
$embedded_inifile = "${config_root}/php-embed.ini"
$package_prefix = 'php56-'
$compiler_packages = ['gcc']
$manage_repos = false
$root_group = 'wheel'
$ext_tool_enable = undef
$ext_tool_query = undef
$ext_tool_enabled = false
}
'Archlinux': {
$config_root_ini = '/etc/php/conf.d'
$config_root_inifile = '/etc/php/php.ini'
$common_package_names = []
$common_package_suffixes = []
$cli_inifile = '/etc/php/php.ini'
$dev_package_suffix = undef
$fpm_pid_file = '/run/php-fpm/php-fpm.pid'
$fpm_config_file = '/etc/php/php-fpm.conf'
$fpm_error_log = 'syslog'
$fpm_inifile = '/etc/php/php.ini'
$fpm_package_suffix = 'fpm'
$fpm_pool_dir = '/etc/php/php-fpm.d'
$fpm_service_name = 'php-fpm'
$fpm_user = 'root'
$fpm_group = 'root'
$apache_inifile = '/etc/php/php.ini'
$embedded_package_suffix = 'embedded'
$embedded_inifile = '/etc/php/php.ini'
$package_prefix = 'php-'
$compiler_packages = ['gcc', 'make']
$manage_repos = false
$root_group = 'root'
$ext_tool_enable = undef
$ext_tool_query = undef
$ext_tool_enabled = false
}
default: {
fail("Unsupported osfamily: ${facts['os']['family']}")
}
}
}
diff --git a/spec/classes/php_fpm_config_spec.rb b/spec/classes/php_fpm_config_spec.rb
index bf78b3c..3e6d4c9 100644
--- a/spec/classes/php_fpm_config_spec.rb
+++ b/spec/classes/php_fpm_config_spec.rb
@@ -1,40 +1,41 @@
+require 'rspec'
require 'spec_helper'
describe 'php::fpm::config' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let :facts do
facts
end
describe 'creates config file' do
let(:params) do
{
inifile: '/etc/php5/conf.d/unique-name.ini',
settings: {
'apc.enabled' => 1
}
}
end
it do
is_expected.to contain_class('php::fpm::config').with(
inifile: '/etc/php5/conf.d/unique-name.ini',
settings: {
'apc.enabled' => 1
}
)
end
it do
is_expected.to contain_php__config('fpm').with(
file: '/etc/php5/conf.d/unique-name.ini',
config: {
'apc.enabled' => 1
}
)
end
end
end
end
end
diff --git a/spec/classes/php_spec.rb b/spec/classes/php_spec.rb
index 7f739e5..e253899 100644
--- a/spec/classes/php_spec.rb
+++ b/spec/classes/php_spec.rb
@@ -1,198 +1,265 @@
require 'spec_helper'
describe 'php', type: :class do
on_supported_os.each do |os, facts|
context "on #{os}" do
let :facts do
facts
end
php_cli_package = case facts[:os]['name']
when 'Debian'
case facts[:os]['release']['major']
when '9'
'php7.0-cli'
else
'php5-cli'
end
when 'Ubuntu'
case facts[:os]['release']['major']
when '18.04'
'php7.2-cli'
when '16.04'
'php7.0-cli'
else
'php5-cli'
end
end
php_fpm_ackage = case facts[:os]['name']
when 'Debian'
case facts[:os]['release']['major']
when '9'
'php7.0-fpm'
else
'php5-fpm'
end
when 'Ubuntu'
case facts[:os]['release']['major']
when '18.04'
'php7.2-fpm'
when '16.04'
'php7.0-fpm'
else
'php5-fpm'
end
end
php_dev_ackage = case facts[:os]['name']
when 'Debian'
case facts[:os]['release']['major']
when '9'
'php7.0-dev'
else
'php5-dev'
end
when 'Ubuntu'
case facts[:os]['release']['major']
when '18.04'
'php7.2-dev'
when '16.04'
'php7.0-dev'
else
'php5-dev'
end
end
describe 'when called with no parameters' do
+ case facts[:osfamily]
+ when 'Suse', 'RedHat', 'CentOS'
+ it { is_expected.to contain_class('php::global') }
+ end
+
case facts[:osfamily]
when 'Debian'
it { is_expected.not_to contain_class('php::global') }
it { is_expected.to contain_class('php::fpm') }
it { is_expected.to contain_package('php-pear').with_ensure('present') }
it { is_expected.to contain_class('php::composer') }
it { is_expected.to contain_package(php_cli_package).with_ensure('present') }
it { is_expected.to contain_package(php_fpm_ackage).with_ensure('present') }
it { is_expected.to contain_package(php_dev_ackage).with_ensure('present') }
when 'Suse'
- it { is_expected.to contain_class('php::global') }
it { is_expected.to contain_package('php5').with_ensure('present') }
it { is_expected.to contain_package('php5-devel').with_ensure('present') }
it { is_expected.to contain_package('php5-pear').with_ensure('present') }
it { is_expected.not_to contain_package('php5-cli') }
it { is_expected.not_to contain_package('php5-dev') }
it { is_expected.not_to contain_package('php-pear') }
+ when 'RedHat', 'CentOS'
+ it { is_expected.to contain_package('php-cli').with_ensure('present') }
+ it { is_expected.to contain_package('php-common').with_ensure('present') }
end
end
describe 'when called with package_prefix parameter' do
- let(:params) { { package_prefix: 'myphp-' } }
+ package_prefix = 'myphp-'
+ let(:params) { { package_prefix: package_prefix } }
+
+ case facts[:osfamily]
+ when 'Suse', 'RedHat', 'CentOS'
+ it { is_expected.to contain_class('php::global') }
+ end
+
+ case facts[:osfamily]
+ when 'Debian', 'RedHat', 'CentOS'
+ it { is_expected.to contain_package("#{package_prefix}cli").with_ensure('present') }
+ end
case facts[:osfamily]
when 'Debian'
it { is_expected.not_to contain_class('php::global') }
it { is_expected.to contain_class('php::fpm') }
- it { is_expected.to contain_package('myphp-cli').with_ensure('present') }
- it { is_expected.to contain_package('myphp-fpm').with_ensure('present') }
- it { is_expected.to contain_package('myphp-dev').with_ensure('present') }
- it { is_expected.to contain_package('php-pear').with_ensure('present') }
it { is_expected.to contain_class('php::composer') }
+ it { is_expected.to contain_package('php-pear').with_ensure('present') }
+ it { is_expected.to contain_package("#{package_prefix}dev").with_ensure('present') }
+ it { is_expected.to contain_package("#{package_prefix}fpm").with_ensure('present') }
when 'Suse'
- it { is_expected.to contain_class('php::global') }
it { is_expected.to contain_package('php5').with_ensure('present') }
- it { is_expected.to contain_package('myphp-devel').with_ensure('present') }
- it { is_expected.to contain_package('myphp-pear').with_ensure('present') }
- it { is_expected.not_to contain_package('myphp-cli') }
- it { is_expected.not_to contain_package('myphp-dev') }
+ it { is_expected.to contain_package("#{package_prefix}devel").with_ensure('present') }
+ it { is_expected.to contain_package("#{package_prefix}pear").with_ensure('present') }
+ it { is_expected.not_to contain_package("#{package_prefix}cli").with_ensure('present') }
+ it { is_expected.not_to contain_package("#{package_prefix}dev") }
it { is_expected.not_to contain_package('php-pear') }
+ when 'RedHat', 'CentOS'
+ it { is_expected.to contain_package("#{package_prefix}common").with_ensure('present') }
end
end
describe 'when called with fpm_user parameter' do
let(:params) { { fpm_user: 'nginx' } }
it { is_expected.to contain_class('php::fpm').with(user: 'nginx') }
it { is_expected.to contain_php__fpm__pool('www').with(user: 'nginx') }
dstfile = case facts[:osfamily]
when 'Debian'
case facts[:os]['name']
when 'Debian'
case facts[:os]['release']['major']
when '9'
'/etc/php/7.0/fpm/pool.d/www.conf'
else
'/etc/php5/fpm/pool.d/www.conf'
end
when 'Ubuntu'
case facts[:os]['release']['major']
when '18.04'
'/etc/php/7.2/fpm/pool.d/www.conf'
when '16.04'
'/etc/php/7.0/fpm/pool.d/www.conf'
else
'/etc/php5/fpm/pool.d/www.conf'
end
end
when 'Archlinux'
'/etc/php/php-fpm.d/www.conf'
when 'Suse'
'/etc/php5/fpm/pool.d/www.conf'
when 'RedHat'
'/etc/php-fpm.d/www.conf'
when 'FreeBSD'
'/usr/local/etc/php-fpm.d/www.conf'
end
it { is_expected.to contain_file(dstfile).with_content(%r{user = nginx}) }
end
describe 'when called with fpm_group parameter' do
let(:params) { { fpm_group: 'nginx' } }
it { is_expected.to contain_class('php::fpm').with(group: 'nginx') }
it { is_expected.to contain_php__fpm__pool('www').with(group: 'nginx') }
dstfile = case facts[:osfamily]
when 'Debian'
case facts[:os]['name']
when 'Debian'
case facts[:os]['release']['major']
when '9'
'/etc/php/7.0/fpm/pool.d/www.conf'
else
'/etc/php5/fpm/pool.d/www.conf'
end
when 'Ubuntu'
case facts[:os]['release']['major']
when '18.04'
'/etc/php/7.2/fpm/pool.d/www.conf'
when '16.04'
'/etc/php/7.0/fpm/pool.d/www.conf'
else
'/etc/php5/fpm/pool.d/www.conf'
end
end
when 'Archlinux'
'/etc/php/php-fpm.d/www.conf'
when 'Suse'
'/etc/php5/fpm/pool.d/www.conf'
when 'RedHat'
'/etc/php-fpm.d/www.conf'
when 'FreeBSD'
'/usr/local/etc/php-fpm.d/www.conf'
end
it { is_expected.to contain_file(dstfile).with_content(%r{group = nginx}) }
end
describe 'when fpm is disabled' do
let(:params) { { fpm: false } }
it { is_expected.not_to contain_class('php::fpm') }
end
+
describe 'when composer is disabled' do
let(:params) { { composer: false } }
it { is_expected.not_to contain_class('php::composer') }
end
+
+ if facts[:osfamily] == 'RedHat' || facts[:osfamily] == 'CentOS'
+ describe 'when called with global option for rhscl_mode' do
+ describe 'when called with mode "remi"' do
+ scl_php_version = 'php56'
+ rhscl_mode = 'remi'
+ let(:pre_condition) do
+ "class {'::php::globals':
+ php_version => '#{scl_php_version}',
+ rhscl_mode => '#{rhscl_mode}'
+ }"
+ end
+ let(:params) do
+ { settings: { 'Date/date.timezone' => 'Europe/Berlin' } }
+ end
+
+ it { is_expected.to contain_class('php::global') }
+ it { is_expected.to contain_package("#{scl_php_version}-php-cli").with_ensure('present') }
+ it { is_expected.to contain_package("#{scl_php_version}-php-common").with_ensure('present') }
+ it { is_expected.to contain_php__config('global').with(file: "/etc/opt/#{rhscl_mode}/#{scl_php_version}/php.ini") }
+ it { is_expected.not_to contain_php__config('cli') }
+
+ # see: https://github.com/voxpupuli/puppet-php/blob/master/lib/puppet/parser/functions/to_hash_settings.rb
+ it { is_expected.to contain_php__config__setting("/etc/opt/#{rhscl_mode}/#{scl_php_version}/php.ini: Date/date.timezone").with_value('Europe/Berlin') }
+ end
+
+ describe 'when called with mode "rhscl"' do
+ scl_php_version = 'rh-php56'
+ rhscl_mode = 'rhscl'
+ let(:pre_condition) do
+ "class {'::php::globals':
+ php_version => '#{scl_php_version}',
+ rhscl_mode => '#{rhscl_mode}'
+ }"
+ end
+ let(:params) do
+ { settings: { 'Date/date.timezone' => 'Europe/Berlin' } }
+ end
+
+ it { is_expected.to contain_class('php::global') }
+ it { is_expected.to contain_package("#{scl_php_version}-php-cli").with_ensure('present') }
+ it { is_expected.to contain_package("#{scl_php_version}-php-common").with_ensure('present') }
+ it { is_expected.to contain_php__config('global').with(file: "/etc/opt/rh/#{scl_php_version}/php.ini") }
+ it { is_expected.to contain_php__config('cli').with(file: "/etc/opt/rh/#{scl_php_version}/php-cli.ini") }
+ it { is_expected.to contain_php__config__setting("/etc/opt/rh/#{scl_php_version}/php.ini: Date/date.timezone").with_value('Europe/Berlin') }
+ end
+ end
+ end
end
end
end
diff --git a/spec/defines/extension_rhscl_spec.rb b/spec/defines/extension_rhscl_spec.rb
new file mode 100644
index 0000000..213844e
--- /dev/null
+++ b/spec/defines/extension_rhscl_spec.rb
@@ -0,0 +1,53 @@
+require 'spec_helper'
+
+describe 'php::extension' do
+ on_supported_os.each do |os, facts|
+ next unless facts[:osfamily] == 'RedHat' || facts[:osfamily] == 'CentOS'
+
+ context "on #{os}" do
+ let :facts do
+ facts
+ end
+
+ describe 'with rhscl_mode "remi" enabled: install one extension' do
+ scl_php_version = 'php56'
+ rhscl_mode = 'remi'
+ configs_root = "/etc/opt/#{rhscl_mode}/#{scl_php_version}"
+
+ let(:pre_condition) do
+ "class {'::php::globals':
+ php_version => '#{scl_php_version}',
+ rhscl_mode => '#{rhscl_mode}'
+ }->
+ class {'::php':
+ ensure => installed,
+ manage_repos => false,
+ fpm => false,
+ dev => true, # must be true since we are using the provider => pecl (option installs header files)
+ composer => false,
+ pear => true,
+ phpunit => false,
+ }"
+ end
+
+ let(:title) { 'soap' }
+ let(:params) do
+ {
+ ini_prefix: '20-',
+ settings: {
+ 'bz2' => {
+ 'Date/date.timezone' => 'Europe/Berlin'
+ }
+ },
+ multifile_settings: true
+ }
+ end
+
+ it { is_expected.to contain_class('php::global') }
+ it { is_expected.to contain_class('php') }
+ it { is_expected.to contain_php__config('bz2').with(file: "#{configs_root}/php.d/20-bz2.ini") }
+ it { is_expected.to contain_php__config__setting("#{configs_root}/php.d/20-bz2.ini: Date/date.timezone").with_value('Europe/Berlin') }
+ end
+ end
+ end
+end
diff --git a/spec/defines/extension_spec.rb b/spec/defines/extension_spec.rb
index 31fa119..14f5d23 100644
--- a/spec/defines/extension_spec.rb
+++ b/spec/defines/extension_spec.rb
@@ -1,228 +1,230 @@
require 'spec_helper'
describe 'php::extension' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let :facts do
facts
end
-
let(:pre_condition) { 'include php' }
unless facts[:osfamily] == 'Suse' || facts[:osfamily] == 'FreeBSD' # FIXME: something is wrong on these
etcdir = case facts[:os]['name']
when 'Debian'
case facts[:os]['release']['major']
when '9'
'/etc/php/7.0/mods-available'
else
'/etc/php5/mods-available'
end
when 'Ubuntu'
case facts[:os]['release']['major']
when '18.04'
'/etc/php/7.2/mods-available'
when '16.04'
'/etc/php/7.0/mods-available'
else
'/etc/php5/mods-available'
end
when 'Archlinux'
'/etc/php/conf.d'
else
'/etc/php.d'
end
context 'installation from repository' do
let(:title) { 'json' }
let(:params) do
{
package_prefix: 'php5-',
settings: {
'test' => 'foo'
}
}
end
it { is_expected.to contain_package('php5-json') }
it do
is_expected.to contain_php__config('json').with(
file: "#{etcdir}/json.ini",
config: {
'extension' => 'json.so',
'test' => 'foo'
}
)
end
end
context 'configure extension without installing a package' do
let(:title) { 'json' }
let(:params) do
{
provider: 'none',
settings: {
'test' => 'foo'
}
}
end
it do
is_expected.to contain_php__config('json').with(
file: "#{etcdir}/json.ini",
require: nil,
config: {
'extension' => 'json.so',
'test' => 'foo'
}
)
end
end
context 'add settings prefix if requested' do
let(:title) { 'json' }
let(:params) do
{
name: 'json',
settings_prefix: true,
settings: {
'test' => 'foo'
}
}
end
it do
is_expected.to contain_php__config('json').with(
config: {
'extension' => 'json.so',
'json.test' => 'foo'
}
)
end
end
context 'use specific settings prefix if requested' do
let(:title) { 'json' }
let(:params) do
{
name: 'json',
settings_prefix: 'bar',
settings: {
'test' => 'foo'
}
}
end
it do
is_expected.to contain_php__config('json').with(
config: {
'extension' => 'json.so',
'bar.test' => 'foo'
}
)
end
end
context 'extensions can be configured as zend' do
let(:title) { 'xdebug' }
let(:params) do
{
zend: true
}
end
it { is_expected.to contain_php__config('xdebug').with_config('zend_extension' => 'xdebug.so') }
end
context 'pecl extensions support so_name' do
let(:title) { 'zendopcache' }
let(:params) do
{
provider: 'pecl',
zend: true,
so_name: 'opcache'
}
end
it do
is_expected.to contain_php__config('zendopcache').with(
file: "#{etcdir}/opcache.ini",
config: {
'zend_extension' => 'opcache.so'
}
)
end
end
context 'add ini file prefix if requested' do
let(:title) { 'zendopcache' }
let(:params) do
{
provider: 'pecl',
zend: true,
ini_prefix: '10-',
so_name: 'opcache'
}
end
it do
is_expected.to contain_php__config('zendopcache').with(
file: "#{etcdir}/10-opcache.ini",
config: {
'zend_extension' => 'opcache.so'
}
)
end
end
context 'pecl extensions support php_api_version' do
let(:title) { 'xdebug' }
let(:params) do
{
provider: 'pecl',
zend: true,
php_api_version: '20100525'
}
end
it { is_expected.to contain_php__config('xdebug').with_config('zend_extension' => '/usr/lib/php5/20100525/xdebug.so') }
end
case facts[:osfamily]
when 'Debian'
context 'on Debian' do
let(:title) { 'xdebug' }
it { is_expected.to contain_php__config('xdebug').with_file("#{etcdir}/xdebug.ini") }
+
+ # note to consider: As of PHP 5.2.0, the JSON extension is bundled and compiled into PHP by default
+ # http://php.net/manual/en/json.installation.php
context 'pecl installation' do
let(:title) { 'json' }
let(:params) do
{
provider: 'pecl',
header_packages: ['libmemcached-dev'],
name: 'nice_name',
settings: {
'test' => 'foo'
}
}
end
it { is_expected.to contain_package('json') }
it { is_expected.to contain_package('libmemcached-dev') }
it { is_expected.to contain_package('build-essential') }
it do
is_expected.to contain_php__config('json').with(
file: "#{etcdir}/nice_name.ini",
config: {
'extension' => 'nice_name.so',
'test' => 'foo'
}
)
end
end
end
end
end
end
end
end

File Metadata

Mime Type
text/x-diff
Expires
Thu, Sep 18, 4:40 PM (17 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3319608

Event Timeline