From a7128d21c640d26438ea828de1d9e9ec04b49669 Mon Sep 17 00:00:00 2001 From: Yeshua Hall Date: Thu, 2 Feb 2023 13:52:48 -0800 Subject: [PATCH] Add support for zendphp --- .fixtures.yml | 1 + README.md | 49 ++++++++++++++++++++ manifests/fpm/config.pp | 10 +++-- manifests/globals.pp | 97 +++++++++++++++++++++++++++------------- manifests/params.pp | 86 ++++++++++++++++++++++------------- manifests/repo.pp | 50 ++++++++++++--------- metadata.json | 6 ++- spec/classes/php_spec.rb | 28 ++++++++++++ 8 files changed, 240 insertions(+), 87 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index 3c6280a2..8604b3ff 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -9,3 +9,4 @@ fixtures: yumrepo_core: repo: https://github.com/puppetlabs/puppetlabs-yumrepo_core.git puppet_version: ">= 6.0.0" + zend_common: "https://github.com/zendtech/puppet-zend-common.git" diff --git a/README.md b/README.md index 1d21c338..25a68b11 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,55 @@ 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. +### ZendPHP support + +To use ZendPHP, configure the global zend parameters. + +```puppet +class { 'php::globals': + php_version => '7.4', + flavor => 'zend', + zend_creds => { + 'username' => '', + 'password' => '', + }, +}-> +class { 'php': + fpm => true, + fpm_pools => { + www => { + listen => "127.0.0.1:9000", + }, + } +} +``` + +#### ZendPHP soft dependencies on RedHat/CentOS/Rocky + +Due to the nature of ZendPHP delivering patched, LTS versions of PHP and its extensions, +RedHat systems sometimes depend on `epel` and the `powertools` repo. + +If you're trying to use ZendPHP and running into issues of missing dependencies, +first try installing epel. If the dependencies still can't be found, try +enabling `powertools`. + +```puppet +if $facts['os']['family'] == 'RedHat' { + package { 'epel-release': } + + if Float($php_version) < 7.4 { + # Depends on puppet/yum + class { 'yum': + managed_repos => ['powertools'], + repos => { + 'powertools' => { + enabled => true, + }, + }, + } + } +} +``` ### RedHat/CentOS SCL Users If you plan to use the SCL repositories with this module you must do the following adjustments: diff --git a/manifests/fpm/config.pp b/manifests/fpm/config.pp index 60fa953d..3ac787f0 100644 --- a/manifests/fpm/config.pp +++ b/manifests/fpm/config.pp @@ -70,6 +70,9 @@ # [*pid_file*] # Path to fpm pid file # +# [*manage_run_dir*] +# Manage the run directory +# class php::fpm::config ( Stdlib::Absolutepath $config_file = $php::params::fpm_config_file, String $user = $php::params::fpm_user, @@ -93,6 +96,7 @@ String[1] $root_group = $php::params::root_group, String $syslog_facility = 'daemon', String $syslog_ident = 'php-fpm', + Boolean $manage_run_dir = true ) inherits php::params { assert_private() @@ -104,14 +108,14 @@ mode => '0644', } - ensure_resource('file', '/var/run/php-fpm', - { + if $manage_run_dir { + file { '/var/run/php-fpm': ensure => directory, owner => 'root', group => $root_group, mode => '0755', } - ) + } ensure_resource('file', '/var/log/php-fpm/', { diff --git a/manifests/globals.pp b/manifests/globals.pp index cbbbcd88..7affa455 100644 --- a/manifests/globals.pp +++ b/manifests/globals.pp @@ -15,13 +15,20 @@ # The mode specifies the specifics in paths for the various RedHat SCL environments so that the module is configured # correctly on their pathnames. # +# @param flavor +# Flavor of PHP, either 'community' or 'zend'. +# +# @param zend_creds +# Hash of ZendPHP repo credentials; {username => '', password => ''} +# class php::globals ( - Optional[Pattern[/^(rh-)?(php)?[578](\.)?[0-9]/]] $php_version = undef, - Optional[Stdlib::Absolutepath] $config_root = undef, - Optional[Stdlib::Absolutepath] $fpm_pid_file = undef, - Optional[Enum['rhscl', 'remi']] $rhscl_mode = undef, + Optional[Stdlib::Absolutepath] $config_root = undef, + Optional[Stdlib::Absolutepath] $fpm_pid_file = undef, + Optional[Enum['rhscl', 'remi']] $rhscl_mode = undef, + Optional[Hash] $zend_creds = undef, + Enum['community', 'zend'] $flavor = 'community', ) { if ($php_version == undef) { $globals_php_version = $facts['os']['name'] ? { @@ -47,13 +54,22 @@ if $facts['os']['name'] == 'Ubuntu' { case $globals_php_version { /^[578].[0-9]/: { - $default_config_root = "/etc/php/${globals_php_version}" + case $flavor { + 'zend': { + $default_config_root = "/etc/php/${globals_php_version}-zend" + $fpm_service_name = "php${globals_php_version}-zend-fpm" + $package_prefix = "php${globals_php_version}-zend-" + } + default: { + $default_config_root = "/etc/php/${globals_php_version}" + $fpm_service_name = "php${globals_php_version}-fpm" + $package_prefix = "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 php installation from Ubuntu official repository use the following paths until 16.04 @@ -72,13 +88,22 @@ /^5\.6/, /^7\.[0-9]/, /^8\.[0-9]/: { - $default_config_root = "/etc/php/${globals_php_version}" + case $flavor { + 'zend': { + $default_config_root = "/etc/php/${globals_php_version}-zend" + $fpm_service_name = "php${globals_php_version}-zend-fpm" + $package_prefix = "php${globals_php_version}-zend-" + } + default: { + $default_config_root = "/etc/php/${globals_php_version}" + $fpm_service_name = "php${globals_php_version}-fpm" + $package_prefix = "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' @@ -109,29 +134,41 @@ } } 'RedHat': { - 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' + case $flavor { + 'zend': { + $php_version_sans_dot = $php_version.regsubst(/\./, '', 'G') + $default_config_root = "/etc/opt/zend/php${php_version_sans_dot}zend" $default_fpm_pid_file = '/var/run/php-fpm/php-fpm.pid' - $fpm_service_name = undef - $package_prefix = undef + $fpm_service_name = "php${php_version_sans_dot}zend-php-fpm" + $package_prefix = "php${php_version_sans_dot}zend-php-" } + default: { - fail("Unsupported rhscl_mode '${rhscl_mode}'") + 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}'") + } + } } } } diff --git a/manifests/params.pp b/manifests/params.pp index f6dc8ba0..3953cf2a 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -58,17 +58,25 @@ $ext_tool_enabled = true $pear = true - case $facts['os']['name'] { - 'Debian': { - $manage_repos = false - } - - 'Ubuntu': { - $manage_repos = false + case $php::globals::flavor { + 'zend': { + $manage_repos = true } default: { - $manage_repos = false + case $facts['os']['name'] { + 'Debian': { + $manage_repos = false + } + + 'Ubuntu': { + $manage_repos = false + } + + default: { + $manage_repos = false + } + } } } } @@ -121,36 +129,49 @@ 'RedHat': { $config_root = $php::globals::globals_config_root - case $php::globals::rhscl_mode { - 'remi': { + case $php::globals::flavor { + 'zend': { $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}'") + 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}'") + } + } } } @@ -168,7 +189,10 @@ $embedded_package_suffix = 'embedded' $package_prefix = pick($php::globals::package_prefix, 'php-') $compiler_packages = ['gcc', 'gcc-c++', 'make'] - $manage_repos = false + $manage_repos = $php::globals::flavor ? { + 'zend' => true, + default => false + } $root_group = 'root' $ext_tool_enable = undef $ext_tool_query = undef diff --git a/manifests/repo.pp b/manifests/repo.pp index 9cd217c3..2b8396e1 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -3,30 +3,36 @@ class php::repo { $msg_no_repo = "No repo available for ${facts['os']['family']}/${facts['os']['name']}" - case $facts['os']['family'] { - 'Debian': { - # no contain here because apt does that already - case $facts['os']['name'] { - 'Debian': { - include php::repo::debian - } - 'Ubuntu': { - include php::repo::ubuntu - } - default: { - fail($msg_no_repo) + if $php::params::flavor == 'zend' { + class { 'zend_common::repo': + creds => $php::globals::zend_creds, + } + } else { + case $facts['os']['family'] { + 'Debian': { + # no contain here because apt does that already + case $facts['os']['name'] { + 'Debian': { + include php::repo::debian + } + 'Ubuntu': { + include php::repo::ubuntu + } + default: { + fail($msg_no_repo) + } } } - } - 'FreeBSD': {} - 'Suse': { - contain php::repo::suse - } - 'RedHat': { - contain 'php::repo::redhat' - } - default: { - fail($msg_no_repo) + 'FreeBSD': {} + 'Suse': { + contain php::repo::suse + } + 'RedHat': { + contain 'php::repo::redhat' + } + default: { + fail($msg_no_repo) + } } } } diff --git a/metadata.json b/metadata.json index 389ccdf8..eac3006e 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "puppet-php", - "version": "8.1.2-rc0", + "version": "8.2.1-rc0", "author": "Vox Pupuli", "summary": "Generic PHP module that supports many platforms", "license": "MIT", @@ -28,6 +28,10 @@ { "name": "puppet/archive", "version_requirement": ">= 1.0.0 < 8.0.0" + }, + { + "name": "zend/zend_common", + "version_requirement": ">= 1.1.1 < 8.0.0" } ], "requirements": [ diff --git a/spec/classes/php_spec.rb b/spec/classes/php_spec.rb index b7945ca2..3387485e 100644 --- a/spec/classes/php_spec.rb +++ b/spec/classes/php_spec.rb @@ -307,6 +307,34 @@ it { is_expected.not_to contain_class('php::composer') } end + if facts[:osfamily] == 'RedHat' || facts[:osfamily] == 'CentOS' || facts[:osfamily] == 'Debian' + describe 'when called with flavor zend' do + zendphp_cli_package = case facts[:os]['name'] + when 'Debian', 'Ubuntu' + 'php8.1-zend-cli' + when 'RedHat', 'CentOS' + 'php81zend-php-cli' + end + zendphp_fpm_package = case facts[:os]['name'] + when 'Debian', 'Ubuntu' + 'php8.1-zend-fpm' + when 'RedHat', 'CentOS' + 'php81zend-php-fpm' + end + + let(:pre_condition) do + "class {'php::globals': + php_version => '8.1', + flavor => 'zend' + }" + end + + it { is_expected.to contain_class('zend_common::repo') } + it { is_expected.to contain_package(zendphp_cli_package).with_ensure('present') } + it { is_expected.to contain_package(zendphp_fpm_package).with_ensure('present') } + end + end + if facts[:osfamily] == 'RedHat' || facts[:osfamily] == 'CentOS' describe 'when called with valid settings parameter types' do let(:params) do