Skip to content

Commit

Permalink
Add support for zendphp
Browse files Browse the repository at this point in the history
  • Loading branch information
jbh committed Feb 2, 2023
1 parent fdb719c commit a7128d2
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 87 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '<USERNAME>',
'password' => '<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:
Expand Down
10 changes: 7 additions & 3 deletions manifests/fpm/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()

Expand All @@ -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/',
{
Expand Down
97 changes: 67 additions & 30 deletions manifests/globals.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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 => '<USERNAME>', password => '<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'] ? {
Expand All @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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}'")
}
}
}
}
}
Expand Down
86 changes: 55 additions & 31 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
}
Expand Down Expand Up @@ -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}'")
}
}
}
}

Expand All @@ -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
Expand Down
Loading

0 comments on commit a7128d2

Please sign in to comment.