diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 42264bde2..2571550d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,19 +24,20 @@ jobs: matrix: os: - almalinux-8 - - centos-7 + - almalinux-9 - centos-stream-8 - - debian-10 + - centos-stream-9 - debian-11 + - debian-12 - rockylinux-8 - - ubuntu-1804 + - rockylinux-9 - ubuntu-2004 - ubuntu-2204 + - ubuntu-2404 suite: - resource - resource-community - resource-peclchannel - - source-install fail-fast: false steps: @@ -59,12 +60,10 @@ jobs: strategy: matrix: os: - - amazonlinux-2 + - amazonlinux-2023 suite: - resource - - resource-community - resource-peclchannel - - source-install fail-fast: false steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index 8654fc5a0..ff824f4dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,15 @@ This file is used to list changes made in each version of the PHP cookbook. Standardise files with files in sous-chefs/repo-management +- Convert cookbook to resource-based by replacing recipes and attributes +- Add custom resources php_install and php_ini +- Drop direct support for installation from community repos and source +- Fix failing Actions + - Drop support for CentOS 7, Debian 10, and Amazon Linux 2 + - Add support for AlmaLinux 9, CentOS Stream 9, Rocky Linux 9, and Ubuntu 24.04 + - Exclude Amazon Linux and Ubuntu 18.04 from community install tests because + they aren't supported by the community repos + ## 9.2.18 - *2024-05-03* ## 9.2.17 - *2024-05-03* @@ -375,7 +384,7 @@ Special thanks to @ThatGerber for getting the PR for this release together ### Bug -- **[COOK-4186](https://tickets.opscode.com/browse/COOK-4186)** - Upgrade_package concatenates an empty version string when version is not set or is empty. +- [COOK-4186] - Upgrade_package concatenates an empty version string when version is not set or is empty. ## v1.3.12 (2014-01-28) @@ -405,28 +414,28 @@ Fixing style cops. Updating test harness ### Bug -- **[COOK-3479](https://tickets.opscode.com/browse/COOK-3479)** - Added Windows support to PHP -- **[COOK-2909](https://tickets.opscode.com/browse/COOK-2909)** - Warnings about Chef::Exceptions::ShellCommandFailed is deprecated +- [COOK-3479] - Added Windows support to PHP +- [COOK-2909] - Warnings about Chef::Exceptions::ShellCommandFailed is deprecated ## v1.2.6 ### Bug -- **[COOK-3628](https://tickets.opscode.com/browse/COOK-3628)** - Fix PHP download URL -- **[COOK-3568](https://tickets.opscode.com/browse/COOK-3568)** - Fix Test Kitchen tests -- **[COOK-3402](https://tickets.opscode.com/browse/COOK-3402)** - When the `ext_dir` setting is present, configure php properly for the source recipe -- **[COOK-2926](https://tickets.opscode.com/browse/COOK-2926)** - Fix pear package detection when installing specific version +- [COOK-3628] - Fix PHP download URL +- [COOK-3568] - Fix Test Kitchen tests +- [COOK-3402] - When the `ext_dir` setting is present, configure php properly for the source recipe +- [COOK-2926] - Fix pear package detection when installing specific version ## v1.2.4 ### Improvement -- **[COOK-3047](https://tickets.opscode.com/browse/COOK-3047)** - Sort directives in `php.ini` -- **[COOK-2928](https://tickets.opscode.com/browse/COOK-2928)** - Abstract `php.ini` directives into variables +- [COOK-3047] - Sort directives in `php.ini` +- [COOK-2928] - Abstract `php.ini` directives into variables ### Bug -- **[COOK-2378](https://tickets.opscode.com/browse/COOK-2378)** - Fix `php_pear` for libevent +- [COOK-2378] - Fix `php_pear` for libevent ## v1.2.2 diff --git a/Dangerfile b/Dangerfile deleted file mode 100644 index bc08b7aeb..000000000 --- a/Dangerfile +++ /dev/null @@ -1,47 +0,0 @@ -# Reference: http://danger.systems/reference.html - -# A pull request summary is required. Add a description of the pull request purpose. -# Changelog must be updated for each pull request that changes code. -# Warnings will be issued for: -# Pull request with more than 400 lines of code changed -# Pull reqest that change more than 5 lines without test changes -# Failures will be issued for: -# Pull request without summary -# Pull requests with code changes without changelog entry - -def code_changes? - code = %w(libraries attributes recipes resources files templates) - code.each do |location| - return true unless git.modified_files.grep(/#{location}/).empty? - end - false -end - -def test_changes? - tests = %w(spec test kitchen.yml kitchen.dokken.yml) - tests.each do |location| - return true unless git.modified_files.grep(/#{location}/).empty? - end - false -end - -failure 'Please provide a summary of your Pull Request.' if github.pr_body.length < 10 - -warn 'This is a big Pull Request.' if git.lines_of_code > 400 - -warn 'This is a Table Flip.' if git.lines_of_code > 2000 - -# Require a CHANGELOG entry for non-test changes. -if !git.modified_files.include?('CHANGELOG.md') && code_changes? - failure 'Please include a CHANGELOG entry.' -end - -# Require Major Minor Patch version labels -unless github.pr_labels.grep /minor|major|patch/i - warn 'Please add a release label to this pull request' -end - -# A sanity check for tests. -if git.lines_of_code > 5 && code_changes? && !test_changes? - warn 'This Pull Request is probably missing tests.' -end diff --git a/README.md b/README.md index b3ba147ff..1496832c2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) -It installs and configures PHP and the PEAR package management system. Also includes resources for managing PEAR (and PECL) packages, PECL channels, and PHP-FPM pools. +The `php` cookbook installs and configures PHP and the PEAR package management system. Also includes resources for managing PEAR (and PECL) packages, PECL channels, and PHP-FPM pools. ## Maintainers @@ -19,76 +19,33 @@ This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of - Ubuntu 18.04 / 20.04 / 22.04 - Debian 10 / 11 - CentOS 7+ (incl. Alma & Rocky) +- Amazon Linux 2023 ### Chef - Chef 15.3+ -## Attributes - -- `node['php']['install_method']` = method to install php with, default `package`. -- `node['php']['directives']` = Hash of directives and values to append to `php.ini`, default `{}`. -- `node['php']['pear_setup']` = Boolean value to determine whether to set up pear repositories. Default: `true` -- `node['php']['pear_channels']` = List of external pear channels to add if `node['php']['pear_setup']` is true. Default: `['pear.php.net', 'pecl.php.net']` - -The file also contains the following attribute types: - -- platform specific locations and settings. -- source installation settings - ## Resources This cookbook includes resources for managing: -- [php_pear](https://github.com/sous-chefs/php/tree/master/documentation/php_pear.md) -- [php_pear_channel](https://github.com/sous-chefs/php/tree/master/documentation/php_pear_channel.md) -- [php_fpm_pool](https://github.com/sous-chefs/php/tree/master/documentation/php_fpm_pool.md) - -## Recipes - -### `php::default` - -Include the default recipe in a run list, to get `php`. By default `php` is installed from packages but this can be changed by using the `install_method` attribute. - -### `php::package` +- [php_ini](documentation/php_ini.md) +- [php_install](documentation/php_install.md) +- [php_pear](documentation/php_pear.md) +- [php_pear_channel](documentation/php_pear_channel.md) +- [php_fpm_pool](documentation/php_fpm_pool.md) -This recipe installs PHP from packages. - -### `php::community_package` - -This recipe installs PHP from one of two available community package repositories, depending on platform family. This provides the ability to install PHP versions that are no provided by the official distro repositories. +## Usage -Set `node['php']['install_method'] = 'community_package'` to use these repositories. + +Simply use the `php_install` resource wherever you would like PHP installed from a package. By default, it will install from the platform's package manager (see [`libraries/helpers.rb`](https://github.com/sous-chefs/php/tree/main/libraries/helpers.rb) to see the default packages list for each platoform). -Please see `test/cookbooks/test/recipes/community.rb` for an example of how to use attributes to install the desired version of PHP & its supporting packages, and please refer to the documentation on these community repositories: +Please see [`test/cookbooks/test/recipes/community.rb`](https://github.com/sous-chefs/php/tree/main/test/cookbooks/test/recipes/community.rb) for an example of using the `php_install` resource to install the desired version of PHP & its supporting packages from a community repository, and please refer to the documentation on these community repositories: -- CentOS - [Remi’s RPM repository](https://rpms.remirepo.net) +- RHEL/CentOS - [Remi’s RPM repository](https://rpms.remirepo.net) - Ubuntu - [Ondřej Surý PPA](https://launchpad.net/~ondrej/+archive/ubuntu/php) - Debian - [Sury repo](https://deb.sury.org/) -### `php::source` - -This recipe installs PHP from source. - -## Usage - -Simply include the `php` recipe where ever you would like php installed. To install from source override the `node['php']['install_method']` attribute within a role or wrapper cookbook: - -### Role example - -```ruby -name 'php' -description 'Install php from source' -override_attributes( - 'php' => { - 'install_method' => 'source', - } -) -run_list( - 'recipe[php]' -) -``` - ## Contributors This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) diff --git a/UPGRADING.md b/UPGRADING.md new file mode 100644 index 000000000..bb03ab395 --- /dev/null +++ b/UPGRADING.md @@ -0,0 +1,115 @@ +# Upgrading + +The `package` and `ini` recipes have been removed and replaced with custom resources: + +- package --> php_install +- ini --> php_ini + +## Attributes + +Attributes have been converted to resource properties; default values are set in helpers. Please see the documentation for all properties and their defaults. + +The following table lists the resources and properties that attributes have been moved to: + +| Attribute | Resource | Property Name (if different) | +| ----------------------| -------------------------------------------- | ---------------------------- | +| ['bin'] | Removed | | +| ['checksum'] | Removed | | +| ['conf_dir'] | php_ini, php_install, php_pear | | +| ['configure_options'] | Removed | | +| ['directives'] | php_fpm_pool, php_ini, php_install, php_pear | | +| ['disable_mod'] | php_pear | | +| ['enable_mod'] | php_pear | | +| ['ext_conf_dir'] | php_pear | | +| ['ext_dir'] | php_fpm_pool, php_ini, php_install | | +| ['fpm_conf_dir'] | php_fpm_pool | | +| ['fpm_default_conf'] | php_fpm_pool | :default_conf | +| ['fpm_group'] | php_fpm_pool | :group | +| ['fpm_ini_control'] | php_fpm_pool | | +| ['fpm_listen_group'] | php_fpm_pool | :listen_group | +| ['fpm_listen_user'] | php_fpm_pool | :listen_user | +| ['fpm_package'] | php_fpm_pool | | +| ['fpm_pool_dir'] | php_fpm_pool | :pool_dir | +| ['fpm_service'] | php_fpm_pool | :service | +| ['fpm_socket'] | php_fpm_pool | :listen | +| ['fpm_user'] | php_fpm_pool | :user | +| ['ini']['cookbook'] | php_fpm_pool, php_ini, php_install | :ini_cookbook | +| ['ini']['template'] | php_fpm_pool, php_ini, php_install | :ini_template | +| ['install_method'] | Removed | | +| ['packages'] | php_install | | +| ['pear'] | Removed | | +| ['pear_channels'] | Removed | | +| ['pear_setup'] | Removed | | +| ['pecl'] | php_pear | | +| ['prefix_dir'] | Removed | | +| ['src_deps'] | Removed | | +| ['src_recompile'] | Removed | | +| ['url'] | Removed | | +| ['version'] | Helper - versions now follow X.X format | php_version | + +Attributes specific to recipes or installing from source were removed. + +## Package Install + +Installing from package managers can now be done through the `php_install` resource. + +```ruby +# Old Style +include_recipe 'php::default' +``` + +```ruby +# New Style +php_install 'php' do + action :install +end +``` + +## Community Install + +Installing from community repos is no longer built in to the cookbook. The `php_install` resource can be configured to help in installing from community repos. See [`test/cookbooks/test/recipes/community.rb`](https://github.com/sous-chefs/php/tree/main/test/cookbooks/test/recipes/community.rb) for an example of fetching and installing from community repos. + +## Source Install + +Installing from source is no longer built in to the cookbook. Users should manage installation from source on their own. The original recipe can be referenced [here](https://github.com/sous-chefs/php/blob/9.2.16/recipes/source.rb) to help with the switch. + +## .ini Configuration + +Configuring PHP and FPM can now be done through the `php_ini` resource. + +```ruby +# Old Style +include_recipe 'php::ini' +``` + +```ruby +# New Style +php_ini 'php' do + action :add +end +``` + +A `.ini` file can also be removed using the `php_ini` resource. + +```ruby +# New Style +php_ini 'php' do + action :remove +end +``` + +The `node['php']['fpm_ini_control']` attribute has been moved to a property of the `php_fpm_pool` resource. + +```ruby +# Old Style +node['php']['fpm_ini_control'] = true +include_recipe 'php::ini' +``` + +```ruby +# New Style +php_fpm_pool 'fpm_pool' do + fpm_ini_control true + action :install +end +``` diff --git a/attributes/default.rb b/attributes/default.rb deleted file mode 100644 index 717c89e8a..000000000 --- a/attributes/default.rb +++ /dev/null @@ -1,201 +0,0 @@ -# -# Cookbook:: php -# Attributes:: default -# -# Copyright:: 2011-2021, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -lib_dir = 'lib' - -default['php']['install_method'] = 'package' -default['php']['directives'] = {} -default['php']['bin'] = 'php' - -default['php']['pecl'] = 'pecl' - -default['php']['version'] = '7.2.31' - -default['php']['pear'] = '/usr/bin/pear' -default['php']['pear_setup'] = true -default['php']['pear_channels'] = [ - 'pear.php.net', - 'pecl.php.net', -] - -default['php']['url'] = 'https://www.php.net/distributions' -default['php']['checksum'] = '796837831ccebf00dc15921ed327cfbac59177da41b33044d9a6c7134cdd250c' # checksum of the .tar.gz files -default['php']['prefix_dir'] = '/usr/local' -default['php']['enable_mod'] = '/usr/sbin/phpenmod' -default['php']['disable_mod'] = '/usr/sbin/phpdismod' - -default['php']['ini']['template'] = 'php.ini.erb' -default['php']['ini']['cookbook'] = 'php' - -default['php']['fpm_socket'] = '/var/run/php7.2-fpm.sock' -default['php']['fpm_conf_dir'] = nil -default['php']['fpm_ini_control'] = false - -case node['platform_family'] -when 'rhel', 'amazon' - lib_dir = node['kernel']['machine'] =~ /x86_64/ ? 'lib64' : 'lib' - - default['php']['conf_dir'] = '/etc' - default['php']['ext_conf_dir'] = '/etc/php.d' - default['php']['fpm_user'] = 'nobody' - default['php']['fpm_group'] = 'nobody' - default['php']['fpm_listen_user'] = 'nobody' - default['php']['fpm_listen_group'] = 'nobody' - default['php']['ext_dir'] = "/usr/#{lib_dir}/php/modules" - default['php']['fpm_package'] = 'php-fpm' - - default['php']['src_deps'] = if platform?('amazon') || node['platform_version'].to_i < 8 - %w(bzip2-devel libc-client-devel libcurl-devel freetype-devel gmp-devel libjpeg-devel krb5-devel libmcrypt-devel libpng-devel openssl-devel t1lib-devel libxml2-devel libxslt-devel zlib-devel mhash-devel) - else # redhat does not name their packages with version on RHEL 6+ - %w(bzip2-devel libc-client-devel curl-devel freetype-devel gmp-devel libjpeg-devel krb5-devel libmcrypt-devel libpng-devel openssl-devel libxml2-devel libxslt-devel zlib-devel mhash-devel) - end - default['php']['packages'] = %w(php php-devel php-cli php-pear) - default['php']['fpm_pooldir'] = '/etc/php-fpm.d' - default['php']['fpm_default_conf'] = '/etc/php-fpm.d/www.conf' - default['php']['fpm_service'] = 'php-fpm' - if node['php']['install_method'] == 'package' - default['php']['fpm_user'] = 'apache' - default['php']['fpm_group'] = 'apache' - default['php']['fpm_listen_user'] = 'apache' - default['php']['fpm_listen_group'] = 'apache' - end -when 'debian' - default['php']['version'] = '7.0.4' - default['php']['checksum'] = 'f6cdac2fd37da0ac0bbcee0187d74b3719c2f83973dfe883d5cde81c356fe0a8' - default['php']['conf_dir'] = '/etc/php/7.0/cli' - default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg-dev libkrb5-dev libmcrypt-dev libpng-dev libssl-dev pkg-config libxml2-dev) - default['php']['packages'] = %w(php7.0-cgi php7.0 php7.0-dev php7.0-cli php-pear) - default['php']['disable_mod'] = '/usr/sbin/phpdismod' - default['php']['enable_mod'] = '/usr/sbin/phpenmod' - default['php']['fpm_default_conf'] = '/etc/php/7.0/fpm/pool.d/www.conf' - default['php']['fpm_conf_dir'] = '/etc/php/7.0/fpm' - default['php']['ext_conf_dir'] = '/etc/php/7.0/mods-available' - default['php']['fpm_package'] = 'php7.0-fpm' - default['php']['fpm_pooldir'] = '/etc/php/7.0/fpm/pool.d' - default['php']['fpm_service'] = 'php7.0-fpm' - default['php']['fpm_socket'] = '/var/run/php/php7.0-fpm.sock' - default['php']['fpm_user'] = 'www-data' - default['php']['fpm_group'] = 'www-data' - default['php']['fpm_listen_user'] = 'www-data' - default['php']['fpm_listen_group'] = 'www-data' - - if platform?('debian') && node['platform_version'].to_i == 10 - default['php']['version'] = '7.3.19' - default['php']['checksum'] = '809126b46d62a1a06c2d5a0f9d7ba61aba40e165f24d2d185396d0f9646d3280' - default['php']['conf_dir'] = '/etc/php/7.3/cli' - default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-turbo-dev libkrb5-dev libmcrypt-dev libpng-dev libssl-dev pkg-config libxml2-dev file re2c libzip-dev) - # Debian >= 10 drops versions from the package names - default['php']['packages'] = %w(php-cgi php php-dev php-cli php-pear) - default['php']['fpm_package'] = 'php7.3-fpm' - default['php']['fpm_pooldir'] = '/etc/php/7.3/fpm/pool.d' - default['php']['fpm_service'] = 'php7.3-fpm' - default['php']['fpm_socket'] = '/var/run/php/php7.3-fpm.sock' - default['php']['fpm_default_conf'] = '/etc/php/7.3/fpm/pool.d/www.conf' - default['php']['fpm_conf_dir'] = '/etc/php/7.3/fpm' - default['php']['ext_conf_dir'] = '/etc/php/7.3/mods-available' - elsif platform?('debian') && node['platform_version'].to_i >= 11 - default['php']['version'] = '7.4.27' - default['php']['checksum'] = '564fd5bc9850370db0cb4058d9087f2f40177fa4921ce698a375416db9ab43ca' - default['php']['conf_dir'] = '/etc/php/7.4/cli' - default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-turbo-dev libkrb5-dev libmcrypt-dev libonig-dev libpng-dev libsqlite3-dev libssl-dev pkg-config libxml2-dev file re2c libzip-dev) - default['php']['packages'] = %w(php-cgi php php-dev php-cli php-pear) - default['php']['fpm_package'] = 'php7.4-fpm' - default['php']['fpm_pooldir'] = '/etc/php/7.4/fpm/pool.d' - default['php']['fpm_service'] = 'php7.4-fpm' - default['php']['fpm_socket'] = '/var/run/php/php7.4-fpm.sock' - default['php']['fpm_default_conf'] = '/etc/php/7.4/fpm/pool.d/www.conf' - default['php']['fpm_conf_dir'] = '/etc/php/7.4/fpm' - default['php']['ext_conf_dir'] = '/etc/php/7.4/mods-available' - elsif platform?('ubuntu') && node['platform_version'].to_f == 18.04 - default['php']['version'] = '7.2.31' - default['php']['checksum'] = '796837831ccebf00dc15921ed327cfbac59177da41b33044d9a6c7134cdd250c' - default['php']['conf_dir'] = '/etc/php/7.2/cli' - default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-dev libkrb5-dev libmcrypt-dev libpng-dev libssl-dev pkg-config libxml2-dev) - default['php']['packages'] = %w(php7.2-cgi php7.2 php7.2-dev php7.2-cli php-pear) - default['php']['fpm_package'] = 'php7.2-fpm' - default['php']['fpm_pooldir'] = '/etc/php/7.2/fpm/pool.d' - default['php']['fpm_service'] = 'php7.2-fpm' - default['php']['fpm_socket'] = '/var/run/php/php7.2-fpm.sock' - default['php']['fpm_default_conf'] = '/etc/php/7.2/fpm/pool.d/www.conf' - default['php']['fpm_conf_dir'] = '/etc/php/7.2/fpm' - default['php']['ext_conf_dir'] = '/etc/php/7.2/mods-available' - elsif platform?('ubuntu') && node['platform_version'].to_f == 20.04 - default['php']['version'] = '7.4.7' - default['php']['checksum'] = 'a554a510190e726ebe7157fb00b4aceabdb50c679430510a3b93cbf5d7546e44' - default['php']['conf_dir'] = '/etc/php/7.4/cli' - default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-dev libkrb5-dev libmcrypt-dev libpng-dev libssl-dev pkg-config libxml2-dev libsqlite3-dev libonig-dev) - default['php']['packages'] = %w(php7.4-cgi php7.4 php7.4-dev php7.4-cli php-pear) - default['php']['fpm_package'] = 'php7.4-fpm' - default['php']['fpm_pooldir'] = '/etc/php/7.4/fpm/pool.d' - default['php']['fpm_service'] = 'php7.4-fpm' - default['php']['fpm_socket'] = '/var/run/php/php7.4-fpm.sock' - default['php']['fpm_default_conf'] = '/etc/php/7.4/fpm/pool.d/www.conf' - default['php']['fpm_conf_dir'] = '/etc/php/7.4/fpm' - default['php']['enable_mod'] = '/usr/sbin/phpenmod' - default['php']['disable_mod'] = '/usr/sbin/phpdismod' - default['php']['ext_conf_dir'] = '/etc/php/7.4/mods-available' - elsif platform?('ubuntu') && node['platform_version'].to_f >= 22.04 - default['php']['version'] = '8.1.7' - default['php']['checksum'] = '5f0b422a117633c86d48d028934b8dc078309d4247e7565ea34b2686189abdd8' - default['php']['conf_dir'] = '/etc/php/8.1/cli' - default['php']['src_deps'] = %w(libbz2-dev libc-client2007e-dev libcurl4-gnutls-dev libfreetype6-dev libgmp3-dev libjpeg62-dev libkrb5-dev libmcrypt-dev libpng-dev libssl-dev pkg-config libxml2-dev libsqlite3-dev libonig-dev) - default['php']['packages'] = %w(php8.1-cgi php8.1 php8.1-dev php8.1-cli php-pear) - default['php']['fpm_package'] = 'php8.1-fpm' - default['php']['fpm_pooldir'] = '/etc/php/8.1/fpm/pool.d' - default['php']['fpm_service'] = 'php8.1-fpm' - default['php']['fpm_socket'] = '/var/run/php/php8.1-fpm.sock' - default['php']['fpm_default_conf'] = '/etc/php/8.1/fpm/pool.d/www.conf' - default['php']['fpm_conf_dir'] = '/etc/php/8.1/fpm' - default['php']['enable_mod'] = '/usr/sbin/phpenmod' - default['php']['disable_mod'] = '/usr/sbin/phpdismod' - default['php']['ext_conf_dir'] = '/etc/php/8.1/mods-available' - end -end - -default['php']['src_recompile'] = false - -default['php']['configure_options'] = %W(--prefix=#{node['php']['prefix_dir']} - --with-libdir=#{lib_dir} - --with-config-file-path=#{node['php']['conf_dir']} - --with-config-file-scan-dir=#{node['php']['ext_conf_dir']} - --with-pear - --enable-fpm - --with-fpm-user=#{node['php']['fpm_user']} - --with-fpm-group=#{node['php']['fpm_group']} - --with-zlib - --with-openssl - --with-kerberos - --with-bz2 - --with-curl - --enable-ftp - --enable-zip - --enable-exif - --with-gd - --enable-gd-native-ttf - --with-gettext - --with-gmp - --with-mhash - --with-iconv - --with-imap - --with-imap-ssl - --enable-sockets - --enable-soap - --with-xmlrpc - --with-mcrypt - --enable-mbstring) diff --git a/documentation/php_fpm_pool.md b/documentation/php_fpm_pool.md index 8b56193b1..61597d345 100644 --- a/documentation/php_fpm_pool.md +++ b/documentation/php_fpm_pool.md @@ -1,6 +1,6 @@ # `php_fpm_pool` -Installs the `php-fpm` package appropriate for your distro (if using packages) and configures a FPM pool for you. Currently only supported in Debian-family operating systems and CentOS 7 (or at least tested with such, YMMV if you are using source). +Installs the `php-fpm` package appropriate for your platform and configures a FPM pool for you. Currently only supported in Debian-family operating systems and CentOS 7 (or at least tested with such). Please consider FPM functionally pre-release, and test it thoroughly in your environment before using it in production @@ -13,23 +13,24 @@ More info: ## Properties -| Name | Type | Default | Descrption | -| ------------------- | -------- | ------------------------------------ | ------------------------------------------------------------------------------------- | -| `pool_name` | `String` | The name of the FPM pool | | -| `listen` | `String` | Default: `/var/run/php5-fpm.sock` | The listen address | -| `user` | | The webserver user for your distro. | The user to run the FPM under | -| `group` | | The webserver group for your distro. | The group to run the FPM under | -| `process_manager` | | `dynamic` | Process manager to use - see | -| `max_children` | | `5` | Max children to scale to | -| `start_servers` | | `2` | Number of servers to start the pool with | -| `min_spare_servers` | | `1` | Minimum number of servers to have as spares | -| `max_spare_servers` | | `3` | Maximum number of servers to have as spares | -| `chdir` | | `/` | The startup working directory of the pool | -| `additional_config` | | `{}` | Additional parameters in JSON | +| Name | Type | Default | Description | +| ------------------- | --------------- | ------------------------------------ | ------------------------------------------------------------------------------------- | +| `pool_name` | `String` | The name of the FPM pool | | +| `listen` | `String` | `/var/run/php-fpm.sock` (RHEL & Amazon) or `/var/run/php/php-fpm.sock` (Debian) | The listen address | +| `user` | `String` | The webserver user for your distro. | The user to run the FPM under | +| `group` | `String` | The webserver group for your distro. | The group to run the FPM under | +| `process_manager` | `String` | `dynamic` | Process manager to use - see | +| `max_children` | `Integer` | `5` | Max children to scale to | +| `start_servers` | `Integer` | `2` | Number of servers to start the pool with | +| `min_spare_servers` | `Integer` | `1` | Minimum number of servers to have as spares | +| `max_spare_servers` | `Integer` | `3` | Maximum number of servers to have as spares | +| `chdir` | `String` | `/` | The startup working directory of the pool | +| `additional_config` | `Hash` | `{}` | Additional parameters in JSON | +| `fpm_ini_control` | `[true, false]` | `false` | Whether to add a new `php.ini` file for FPM | ## Examples -Install a FPM pool named default +Install a FPM pool named 'default' ```ruby php_fpm_pool 'default' do diff --git a/documentation/php_ini.md b/documentation/php_ini.md new file mode 100644 index 000000000..98de81783 --- /dev/null +++ b/documentation/php_ini.md @@ -0,0 +1,46 @@ +# `php_install` + +Adds a `php.ini` to the appropriate location. + +## Actions + +- `:add`: Add a `php.ini` file (default) +- `:remove`: Remove a `php.ini` file + +## Properties + +| Name | Type | Default | Description | +| ------------------- | ---------------- | ----------------------------------------------------- | ----------------------------------------------------------- | +| `conf_dir` | `String` | Platform-specific - see `libraries/helpers.rb | Directory to place the `php.ini` file under | +| `ini_template | `String` | `php.ini.erb` (see `templates//php.ini.rb`) | Template to use to create the `php.ini` file | +| `ini_cookbook` | `String` | `php` (this cookbook) | Cookbook where the template is located | +| `directives` | `Hash` | `{}` | Directive-value pairs to add to the `php.ini` file | +| `ext_dir` | `String` | Platform-specific - see `libraries/helpers.rb` | Directory in which the loadable extensions (modules) reside | + +## Examples + +Add a `php.ini` file to the default location for your platform + +```ruby +php_ini 'ini' do + action :add +end +``` + +Add a `php.ini` file to the `/etc/php-fpm.d` directory + +```ruby +php_ini 'fpm.d' do + conf_dir '/etc/php-fpm.d' + action :add +end +``` + +Remove a `php.ini` file from the `/etc/php-fpm.d` directory + +```ruby +php_ini 'fpm.d' do + conf_dir '/etc/php-fpm.d' + action :remove +end +``` diff --git a/documentation/php_install.md b/documentation/php_install.md new file mode 100644 index 000000000..cb1cad86f --- /dev/null +++ b/documentation/php_install.md @@ -0,0 +1,31 @@ +# `php_install` + +By default, installs the `php` packages appropriate for your platform and adds a `php.ini` to the default location for that platform. + +## Actions + +- `:install`: Installs PHP packages (default) + +## Properties + +| Name | Type | Default | Description | +| ------------------- | ---------------- | ----------------------------------------------------- | ----------------------------------------------------------- | +| `packages` | `String` | Platform-specific - see `libraries/helpers.rb` | Packages to install | +| `options` | `[String, Array] | | Installation options (see Chef `package` resource) | +| `conf_dir` | `String` | Platform-specific - see `libraries/helpers.rb | Directory to place the `php.ini` file under | +| `ini_template | `String` | `php.ini.erb` (see `templates//php.ini.rb`) | Template to use to create the `php.ini` file | +| `ini_cookbook` | `String` | `php` (this cookbook) | Cookbook where the template is located | +| `directives` | `Hash` | `{}` | Directive-value pairs to add to the `php.ini` file | +| `ext_dir` | `String` | Platform-specific - see `libraries/helpers.rb` | Directory in which the loadable extensions (modules) reside | + +## Examples + +Install the default packages for your platform + +```ruby +php_install 'php' do + action :install +end +``` + +See [`test/cookbooks/test/recipes/community.rb`](https://github.com/sous-chefs/php/tree/main/test/cookbooks/test/recipes/community.rb) for an example for installing from a community repository. diff --git a/documentation/php_pear.md b/documentation/php_pear.md index b4fded5da..e34aca7d7 100644 --- a/documentation/php_pear.md +++ b/documentation/php_pear.md @@ -12,16 +12,16 @@ ## Properties -| Name | Type | Default | Descrption | +| Name | Type | Default | Description | | ----------------- | -------- | -------- | ----------------------------------------------------------------------------------------------------------------------------- | | `package_name` | `String` | | The name of the pear package to install | | `version` | `String` | | the version of the pear package to install/upgrade. If no version is given latest is assumed. | | `channel` | `String` | | | | `options` | `String` | | Add additional options to the underlying pear package command | -| `directives` | `Hash` | `{}` | extra extension directives (settings) for a pecl. on most platforms these usually get rendered into the extension's .ini file | +| `directives` | `Hash` | `{}` | Extra extension directives (settings) for a pecl. On most platforms these usually get rendered into the extension's .ini file | | `zend_extensions` | `Array` | `[]` | PEAR by default installs stable packages only, this allows you to install pear packages in a devel, alpha or beta state | | `preferred_state` | `String` | `stable` | Package type to install | -| `binary` | `String` | | The pear binary to use, by default pear, can be overridden if the binary is not called pear, e.g. pear7 | +| `binary` | `String` | | The pear binary to use, by default `pear`, can be overridden if the binary is not called `pear`, e.g. `pear7` | ## Examples diff --git a/documentation/php_pear_channel.md b/documentation/php_pear_channel.md index 09260eb06..4070cb240 100644 --- a/documentation/php_pear_channel.md +++ b/documentation/php_pear_channel.md @@ -11,11 +11,11 @@ ## Properties -| Name | Type | Default | Descrption | +| Name | Type | Default | Description | | -------------- | -------- | ------- | --------------------------------------------------- | | `channel_name` | `String` | | Name attribute. The name of the channel to discover | | `channel_xml` | `String` | | The channel.xml file of the channel you are adding | -| `binary` | `String` | `pear` | Pear binary, default: pear | +| `binary` | `String` | `pear` | Pear binary | ## Examples diff --git a/kitchen.yml b/kitchen.yml index 0912763c9..3dc48c4ac 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -32,6 +32,9 @@ suites: - name: resource_community run_list: - recipe[test::community] + excludes: + - ubuntu-18.04 + - amazonlinux-2023 - name: resource_peclchannel run_list: - recipe[test::default] @@ -40,6 +43,3 @@ suites: verifier: inspec_tests: - test/integration/resource - - name: source_install - run_list: - - recipe[test::source] diff --git a/libraries/helpers.rb b/libraries/helpers.rb new file mode 100644 index 000000000..79fdc77a9 --- /dev/null +++ b/libraries/helpers.rb @@ -0,0 +1,185 @@ +module Php + module Cookbook + module Helpers + def php_conf_dir + if platform_family?('rhel', 'amazon') + '/etc' + else + "/etc/php/#{php_version}/cli" + end + end + + def php_disable_mod + '/usr/sbin/phpdismod' + end + + def php_enable_mod + '/usr/sbin/phpenmod' + end + + def php_ext_conf_dir + if platform_family?('rhel', 'amazon') + '/etc/php.d' + else + "/etc/php/#{php_version}/mods-available" + end + end + + def php_ext_dir + '/usr/lib64/php/modules' + end + + def php_fpm_conf_dir + if platform_family?('rhel', 'amazon') + '/etc/php-fpm.d' + else + "/etc/php/#{php_version}/fpm" + end + end + + def php_fpm_default_conf + if platform_family?('rhel', 'amazon') + '/etc/php-fpm.d/www.conf' + else + "/etc/php/#{php_version}/fpm/pool.d/www.conf" + end + end + + def php_fpm_group + case node['platform_family'] + when 'rhel', 'amazon' + 'apache' + when 'debian' + 'www-data' + end + end + + def php_fpm_listen_group + case node['platform_family'] + when 'rhel', 'amazon' + 'apache' + when 'debian' + 'www-data' + end + end + + def php_fpm_listen_user + case node['platform_family'] + when 'rhel', 'amazon' + 'apache' + when 'debian' + 'www-data' + end + end + + def php_fpm_package + if platform_family?('rhel', 'amazon') + 'php-fpm' + else + "php#{php_version}-fpm" + end + end + + def php_fpm_pool_dir + if platform_family?('rhel', 'amazon') + '/etc/php-fpm.d' + else + "/etc/php/#{php_version}/fpm/pool.d" + end + end + + def php_fpm_pool_template + 'fpm-pool.conf.erb' + end + + def php_fpm_service + if platform_family?('rhel', 'amazon') + 'php-fpm' + else + "php#{php_version}-fpm" + end + end + + def php_fpm_socket + if platform_family?('rhel', 'amazon') + "/var/run/php#{php_version}-fpm.sock" + else + "/var/run/php/php#{php_version}-fpm.sock" + end + end + + def php_fpm_user + case node['platform_family'] + when 'rhel', 'amazon' + 'apache' + when 'debian' + 'www-data' + end + end + + def php_ini_template + 'php.ini.erb' + end + + def php_installation_packages + case node['platform_family'] + when 'rhel' + %w(php php-devel php-cli php-pear) + # Sometimes Amazon will default to different versions for each package, + # so versions are pinned here to avoid packages getting ahead of each + # other + when 'amazon' + ["php#{php_version}", "php#{php_version}-devel", "php#{php_version}-cli", 'php-pear'] + when 'debian' + case node['platform'] + when 'debian' + %w(php-cgi php php-dev php-cli php-pear) + when 'ubuntu' + ["php#{php_version}-cgi", "php#{php_version}", "php#{php_version}-dev", "php#{php_version}-cli", 'php-pear'] + end + end + end + + def php_pecl + 'pecl' + end + + def php_version + case node['platform_family'] + when 'rhel' + '7.2' + when 'amazon' + '8.2' + when 'debian' + case node['platform'] + when 'debian' + case node['platform_version'].to_i + when 10 + '7.3' + when 11 + '7.4' + else + '8.2' # >= 12 + end + when 'ubuntu' + case node['platform_version'].to_f + when 18.04 + '7.2' + when 20.04 + '7.4' + when 22.04 + '8.1' + else + '8.3' # >= 24.04 + end + else + '7.0' + end + end + end + end + end +end + +Chef::DSL::Recipe.include Php::Cookbook::Helpers +Chef::Resource.include Php::Cookbook::Helpers diff --git a/metadata.rb b/metadata.rb index 7abb3cc16..9ecb31fc8 100644 --- a/metadata.rb +++ b/metadata.rb @@ -8,10 +8,6 @@ version '9.2.18' chef_version '>= 15.3' -depends 'ondrej_ppa_ubuntu' -depends 'yum-epel' -depends 'yum-remi-chef', '>= 5.0.1' - supports 'amazon', '>= 2.0' supports 'centos', '>= 7.0' supports 'debian', '>= 10.0' diff --git a/recipes/community_package.rb b/recipes/community_package.rb deleted file mode 100644 index c5f8a9212..000000000 --- a/recipes/community_package.rb +++ /dev/null @@ -1,34 +0,0 @@ -# -# Author:: Jeff Byrnes () -# Cookbook:: php -# Recipe:: package -# -# Copyright:: 2021, Jeff Byrnes -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -if platform_family?('rhel', 'amazon') - include_recipe 'yum-remi-chef::remi' -elsif platform?('ubuntu') - include_recipe 'ondrej_ppa_ubuntu' -elsif platform?('debian') - # use sury repo for debian (https://deb.sury.org/) - apt_repository 'sury-php' do - uri 'https://packages.sury.org/php/' - key 'https://packages.sury.org/php/apt.gpg' - components %w(main) - end -end - -include_recipe 'php::package' diff --git a/recipes/default.rb b/recipes/default.rb deleted file mode 100644 index e46959824..000000000 --- a/recipes/default.rb +++ /dev/null @@ -1,33 +0,0 @@ -# -# Author:: Joshua Timberman () -# Author:: Seth Chisamore () -# Cookbook:: php -# Recipe:: default -# -# Copyright:: 2009-2021, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -include_recipe "php::#{node['php']['install_method']}" - -# update the main channels -node['php']['pear_channels'].each do |channel| - php_pear_channel channel do - binary node['php']['pear'] - action :update - only_if { node['php']['pear_setup'] } - end -end - -include_recipe 'php::ini' diff --git a/recipes/ini.rb b/recipes/ini.rb deleted file mode 100644 index 99e9920f0..000000000 --- a/recipes/ini.rb +++ /dev/null @@ -1,49 +0,0 @@ -# -# Author:: Christo De Lange () -# Cookbook:: php -# Recipe:: ini -# -# Copyright:: 2011-2021, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -if node['php']['fpm_ini_control'] - - service node['php']['fpm_service'] do - action :enable - end - - template "#{node['php']['fpm_conf_dir']}/php.ini" do - source node['php']['ini']['template'] - cookbook node['php']['ini']['cookbook'] - owner 'root' - group node['root_group'] - mode '0644' - manage_symlink_source true - variables(directives: node['php']['directives']) - notifies :restart, "service[#{node['php']['fpm_service']}]" - not_if { node['php']['fpm_conf_dir'].nil? } - end - -end - -template "#{node['php']['conf_dir']}/php.ini" do - source node['php']['ini']['template'] - cookbook node['php']['ini']['cookbook'] - owner 'root' - group node['root_group'] - mode '0644' - manage_symlink_source true - variables(directives: node['php']['directives']) -end diff --git a/recipes/package.rb b/recipes/package.rb deleted file mode 100644 index 08330fb28..000000000 --- a/recipes/package.rb +++ /dev/null @@ -1,26 +0,0 @@ -# -# Author:: Seth Chisamore () -# Author:: Lucas Hansen () -# Cookbook:: php -# Recipe:: package -# -# Copyright:: 2013-2021, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package node['php']['packages'] do - options node['php']['package_options'] -end - -include_recipe 'php::ini' diff --git a/recipes/recompile.rb b/recipes/recompile.rb deleted file mode 100644 index a64d6e335..000000000 --- a/recipes/recompile.rb +++ /dev/null @@ -1,23 +0,0 @@ -# -# Author:: David Kinzer () -# Cookbook:: php -# Recipe:: recompile -# -# Copyright:: 2014-2021, David Kinzer -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -node.default['php']['src_recompile'] = true - -include_recipe 'php::source' diff --git a/recipes/source.rb b/recipes/source.rb deleted file mode 100644 index e1e16d9e9..000000000 --- a/recipes/source.rb +++ /dev/null @@ -1,106 +0,0 @@ -# -# Author:: Seth Chisamore () -# Cookbook:: php -# Recipe:: source -# -# Copyright:: 2011-2021, Chef Software, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -if platform?('debian') && node['platform_version'].to_i == 9 - Chef::Log.fatal 'Debian 9 is not supported when building from source' -end - -version = node['php']['version'] -configure_options = node['php']['configure_options'].join(' ') -ext_dir_prefix = node['php']['ext_dir'] ? "EXTENSION_DIR=#{node['php']['ext_dir']}" : '' - -php_exists = if node['php']['src_recompile'] - false - else - "$(which #{node['php']['bin']}) --version | grep #{version}" - end - -build_essential - -include_recipe 'yum-epel' if platform_family?('rhel', 'amazon') - -package node['php']['src_deps'] - -log "php_exists == #{php_exists}" - -remote_file "#{Chef::Config[:file_cache_path]}/php-#{version}.tar.gz" do - source "#{node['php']['url']}/php-#{version}.tar.gz" - checksum node['php']['checksum'] - action :create_if_missing - not_if php_exists - notifies :run, 'execute[un-pack php]', :immediately -end - -execute 'un-pack php' do - cwd Chef::Config[:file_cache_path] - command "tar -zxf php-#{version}.tar.gz" - creates "#{Chef::Config[:file_cache_path]}/php-#{version}" - action :nothing -end - -if node['php']['ext_dir'] - directory node['php']['ext_dir'] do - owner 'root' - group 'root' - mode '0755' - recursive true - end -end - -# PHP is unable to find the GMP library on Ubuntu 16.04 -# This symlink brings the file inside of the included libraries -link '/usr/include/gmp.h' do - to '/usr/include/x86_64-linux-gnu/gmp.h' - only_if { platform?('ubuntu') && node['platform_version'].to_f == 16.04 } -end - -execute 'clean build' do - cwd "#{Chef::Config[:file_cache_path]}/php-#{version}" - command 'make clean' - only_if { node['php']['src_recompile'] } -end - -execute 'configure php' do - cwd "#{Chef::Config[:file_cache_path]}/php-#{version}" - command "#{ext_dir_prefix} ./configure #{configure_options}" - not_if php_exists -end - -execute 'build and install php' do - cwd "#{Chef::Config[:file_cache_path]}/php-#{version}" - command "make -j #{node['cpu']['total']} && make install" - not_if php_exists -end - -directory node['php']['conf_dir'] do - owner 'root' - group 'root' - mode '0755' - recursive true -end - -directory node['php']['ext_conf_dir'] do - owner 'root' - group 'root' - mode '0755' - recursive true -end - -include_recipe 'php::ini' diff --git a/resources/fpm_pool.rb b/resources/fpm_pool.rb index b5f287993..80237287f 100644 --- a/resources/fpm_pool.rb +++ b/resources/fpm_pool.rb @@ -3,7 +3,7 @@ # Cookbook:: php # Resource:: fpm_pool # -# Copyright:: 2015-2021, Chef Software, Inc +# Copyright:: 2015-2023, Chef Software, Inc # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,30 +20,56 @@ unified_mode true +property :additional_config, Hash, default: {} +property :chdir, String, default: '/' +property :default_conf, String, default: lazy { php_fpm_default_conf } +property :fpm_package, String, default: lazy { php_fpm_package } +property :group, String, default: lazy { php_fpm_group } +property :listen, String, default: lazy { php_fpm_socket } +property :listen_group, String, default: lazy { php_fpm_listen_group } +property :listen_user, String, default: lazy { php_fpm_listen_user } +property :max_children, Integer, default: 5 +property :max_spare_servers, Integer, default: 3 +property :min_spare_servers, Integer, default: 1 +property :pool_cookbook, String, default: 'php' +property :pool_dir, String, default: lazy { php_fpm_pool_dir } property :pool_name, String, name_property: true -property :listen, String, default: lazy { node['php']['fpm_socket'] } -property :user, String, default: lazy { node['php']['fpm_user'] } -property :group, String, default: lazy { node['php']['fpm_group'] } -property :listen_user, String, default: lazy { node['php']['fpm_listen_user'] } -property :listen_group, String, default: lazy { node['php']['fpm_listen_group'] } +property :pool_template, String, default: lazy { php_fpm_pool_template } property :process_manager, String, default: 'dynamic' -property :max_children, Integer, default: 5 +property :service, String, default: lazy { php_fpm_service } property :start_servers, Integer, default: 2 -property :min_spare_servers, Integer, default: 1 -property :max_spare_servers, Integer, default: 3 -property :chdir, String, default: '/' -property :additional_config, Hash, default: {} +property :user, String, default: lazy { php_fpm_user } + +property :fpm_ini_control, [true, false], default: false +property :fpm_conf_dir, String, default: lazy { php_fpm_conf_dir } +property :ini_template, String, default: lazy { php_ini_template } +property :ini_cookbook, String, default: 'php' +property :directives, Hash, default: {} +property :ext_dir, String, default: lazy { php_ext_dir } action :install do - # Ensure the FPM pacakge is installed, and the service is registered + # Ensure the FPM package is installed, and the service is registered install_fpm_package register_fpm_service + + if new_resource.fpm_ini_control + php_ini 'fpm_ini' do + conf_dir new_resource.fpm_conf_dir + ini_template new_resource.ini_template + ini_cookbook new_resource.ini_cookbook + directives new_resource.directives + ext_dir new_resource.ext_dir + notifies :restart, "service[#{new_resource.service}]" + not_if { new_resource.fpm_conf_dir.nil? } + end + end + # I wanted to have this as a function in itself, but doing this seems to # break testing suites? - template "#{node['php']['fpm_pooldir']}/#{new_resource.pool_name}.conf" do - source 'fpm-pool.conf.erb' + template "#{new_resource.pool_dir}/#{new_resource.pool_name}.conf" do + source new_resource.pool_template action :create - cookbook 'php' + cookbook new_resource.pool_cookbook variables( fpm_pool_name: new_resource.pool_name, fpm_pool_user: new_resource.user, @@ -59,40 +85,38 @@ fpm_pool_chdir: new_resource.chdir, fpm_pool_additional_config: new_resource.additional_config ) - notifies :restart, "service[#{node['php']['fpm_service']}]" + notifies :restart, "service[#{new_resource.service}]" end end action :uninstall do - # Ensure the FPM pacakge is installed, and the service is registered + # Ensure the FPM package is installed, and the service is registered register_fpm_service # Delete the FPM pool. - file "#{node['php']['fpm_pooldir']}/#{new_resource.pool_name}.conf" do + file "#{new_resource.pool_dir}/#{new_resource.pool_name}.conf" do action :delete end end action_class do def install_fpm_package - # Install the FPM pacakge for this platform, if it's available - # Fail the run if it's an unsupported OS (FPM pacakge name not populated) - # also, this is skipped for source - return if node['php']['install_method'] == 'source' + # Install the FPM package for this platform, if it's available + # Fail the run if it's an unsupported OS (FPM package name not populated) - raise 'PHP-FPM package not found (you probably have an unsupported distro)' if node['php']['fpm_package'].nil? + raise 'PHP-FPM package not found (you probably have an unsupported distro)' if new_resource.fpm_package.nil? - file node['php']['fpm_default_conf'] do + file new_resource.default_conf do action :nothing end - package node['php']['fpm_package'] do + package new_resource.fpm_package do action :install - notifies :delete, "file[#{node['php']['fpm_default_conf']}]", :immediately + notifies :delete, "file[#{new_resource.default_conf}]", :immediately end end def register_fpm_service - service node['php']['fpm_service'] do + service new_resource.service do action :enable end end diff --git a/resources/ini.rb b/resources/ini.rb new file mode 100644 index 000000000..f235548e7 --- /dev/null +++ b/resources/ini.rb @@ -0,0 +1,28 @@ +unified_mode true + +property :conf_dir, String, default: lazy { php_conf_dir } +property :ini_template, String, default: lazy { php_ini_template } +property :ini_cookbook, String, default: 'php' +property :directives, Hash, default: {} +property :ext_dir, String, default: lazy { php_ext_dir } + +action :add do + template "#{new_resource.conf_dir}/php.ini" do + source new_resource.ini_template + cookbook new_resource.ini_cookbook + owner 'root' + group 'root' + mode '0644' + manage_symlink_source true + variables( + directives: new_resource.directives, + php_ext_dir: new_resource.ext_dir + ) + end +end + +action :remove do + file "#{new_resource.conf_dir}/php.ini" do + action :delete + end +end diff --git a/resources/install.rb b/resources/install.rb new file mode 100644 index 000000000..9c94faed7 --- /dev/null +++ b/resources/install.rb @@ -0,0 +1,25 @@ +unified_mode true + +property :packages, Array, default: lazy { php_installation_packages } +property :options, [ String, Array ] + +property :conf_dir, String, default: lazy { php_conf_dir } +property :ini_template, String, default: lazy { php_ini_template } +property :ini_cookbook, String, default: 'php' +property :directives, Hash, default: {} +property :ext_dir, String, default: lazy { php_ext_dir } + +action :install do + package 'Install PHP Packages' do + package_name new_resource.packages + options new_resource.options + end + + php_ini 'ini' do + conf_dir new_resource.conf_dir + ini_template new_resource.ini_template + ini_cookbook new_resource.ini_cookbook + directives new_resource.directives + ext_dir new_resource.ext_dir + end +end diff --git a/resources/pear.rb b/resources/pear.rb index ffe8a287b..655747368 100644 --- a/resources/pear.rb +++ b/resources/pear.rb @@ -29,6 +29,11 @@ property :preferred_state, String, default: 'stable' property :binary, String, default: 'pear' property :priority, [String, nil] +property :enable_mod, String, default: lazy { php_enable_mod } +property :disable_mod, String, default: lazy { php_disable_mod } +property :pecl, String, default: lazy { php_pecl } +property :conf_dir, String, default: lazy { php_conf_dir } +property :ext_conf_dir, String, default: lazy { php_ext_conf_dir } def current_installed_version(new_resource) version_check_cmd = "#{new_resource.binary} -d" @@ -52,12 +57,12 @@ def grep_for_version(stdout, package) # Horde_Url -n/a-/(1.0.0beta1 beta) Horde Url class # Horde_Url 1.0.0beta1 (beta) 1.0.0beta1 Horde Url class version = m.split(/\s+/)[1].strip - version = if version.split(%r{/\//})[0] =~ /.\./ + version = if version.split(%r{///})[0] =~ /.\./ # 1.1.4/(1.1.4 stable) - version.split(%r{/\//})[0] + version.split(%r{///})[0] else # -n/a-/(1.0.0beta1 beta) - version.split(%r{/(.*)\/\((.*)/}).last.split(/\s/)[0] + version.split(%r{/(.*)/\((.*)/}).last.split(/\s/)[0] end end version @@ -74,7 +79,9 @@ def grep_for_version(stdout, package) build_essential # If we specified a version, and it's not the current version, move to the specified version - install_version = new_resource.version unless new_resource.version.nil? || new_resource.version == current_resource.version + unless new_resource.version.nil? || new_resource.version == current_resource.version + install_version = new_resource.version + end # Check if the version we want is already installed versions_match = candidate_version == current_installed_version(new_resource) @@ -134,14 +141,19 @@ def expand_options(options) end def candidate_version - candidate_version_cmd = "#{new_resource.binary} -d " - candidate_version_cmd << "preferred_state=#{new_resource.preferred_state}" - candidate_version_cmd << " search#{expand_channel(new_resource.channel)}" - candidate_version_cmd << " #{new_resource.package_name}" - p = shell_out(candidate_version_cmd) - response = nil - response = grep_for_version(p.stdout, new_resource.package_name) if p.stdout =~ /\.?Matched packages/i - response + base_url = "https://#{new_resource.channel || new_resource.binary + '.php.net'}/" + package_version_url = "/rest/r/#{new_resource.package_name.downcase}/allreleases.xml" + # url = "https://#{new_resource.channel || new_resource.binary + '.php.net'}/rest/r/#{new_resource.package_name.downcase}/allreleases.xml" + versions_response = Chef::HTTP.new(base_url).get(package_version_url) + + require 'nokogiri' + doc = Nokogiri::XML(versions_response) + doc.remove_namespaces! + rows = doc.xpath('//r') + rows.each do |r| + next unless r.at_xpath('.//s').content == new_resource.preferred_state + break r.at_xpath('.//v').content + end end def install_package(name, version, **opts) @@ -152,7 +164,10 @@ def install_package(name, version, **opts) command << " #{prefix_channel(new_resource.channel)}#{name}" command << "-#{version}" if version && !version.empty? pear_shell_out(command) - manage_pecl_ini(name, :create, new_resource.directives, new_resource.zend_extensions, new_resource.priority) if pecl? + if pecl? + manage_pecl_ini(name, :create, new_resource.directives, new_resource.zend_extensions, + new_resource.priority) + end enable_package(name) end @@ -163,7 +178,10 @@ def upgrade_package(name, version) command << " #{prefix_channel(new_resource.channel)}#{name}" command << "-#{version}" if version && !version.empty? pear_shell_out(command) - manage_pecl_ini(name, :create, new_resource.directives, new_resource.zend_extensions, new_resource.priority) if pecl? + if pecl? + manage_pecl_ini(name, :create, new_resource.directives, new_resource.zend_extensions, + new_resource.priority) + end enable_package(name) end @@ -178,14 +196,14 @@ def remove_package(name, version) end def enable_package(name) - execute "#{node['php']['enable_mod']} #{name}" do - only_if { platform?('ubuntu') && ::File.exist?(node['php']['enable_mod']) } + execute "#{new_resource.enable_mod} #{name}" do + only_if { platform?('ubuntu') && ::File.exist?(new_resource.enable_mod) } end end def disable_package(name) - execute "#{node['php']['disable_mod']} #{name}" do - only_if { platform?('ubuntu') && ::File.exist?(node['php']['disable_mod']) } + execute "#{new_resource.disable_mod} #{name}" do + only_if { platform?('ubuntu') && ::File.exist?(new_resource.disable_mod) } end end @@ -210,11 +228,11 @@ def removing_package? def extension_dir @extension_dir ||= begin - # Consider using "pecl config-get ext_dir". It is more cross-platform. - # p = shell_out("php-config --extension-dir") - p = shell_out("#{node['php']['pecl']} config-get ext_dir") - p.stdout.strip - end + # Consider using "pecl config-get ext_dir". It is more cross-platform. + # p = shell_out("php-config --extension-dir") + p = shell_out("#{new_resource.pecl} config-get ext_dir") + p.stdout.strip + end end def get_extension_files(name) @@ -222,13 +240,13 @@ def get_extension_files(name) # use appropriate binary when listing pecl packages list_binary = if new_resource.channel == 'pecl.php.net' - node['php']['pecl'] + new_resource.pecl else new_resource.binary end p = shell_out("#{list_binary} list-files #{name}") - p.stdout.each_line.grep(/^src\s+.*\.so$/i).each do |line| + p.stdout.each_line.grep(/^(src|ext)\s+.*\.so$/i).each do |line| files << line.split[1] end @@ -249,7 +267,7 @@ def pecl? else false end - elsif grep_for_version(shell_out(node['php']['pecl'] + search_args).stdout, new_resource.package_name) + elsif grep_for_version(shell_out(new_resource.pecl + search_args).stdout, new_resource.package_name) true else raise "Package #{new_resource.package_name} not found in either PEAR or PECL." @@ -272,14 +290,14 @@ def manage_pecl_ini(name, action, directives, zend_extensions, priority) end ] - directory node['php']['ext_conf_dir'] do + directory new_resource.ext_conf_dir do owner 'root' group 'root' mode '0755' recursive true end - template "#{node['php']['ext_conf_dir']}/#{name}.ini" do + template "#{new_resource.ext_conf_dir}/#{name}.ini" do source 'extension.ini.erb' cookbook 'php' owner 'root' @@ -294,8 +312,8 @@ def manage_pecl_ini(name, action, directives, zend_extensions, priority) action action end - execute "#{node['php']['enable_mod']} #{name}" do - creates "#{node['php']['conf_dir']}/conf.d/#{name}" + execute "#{new_resource.enable_mod} #{name}" do + creates "#{new_resource.conf_dir}/conf.d/#{name}" only_if { platform_family? 'debian' } end end diff --git a/resources/pear_channel.rb b/resources/pear_channel.rb index 9a8920843..68ca0a022 100644 --- a/resources/pear_channel.rb +++ b/resources/pear_channel.rb @@ -28,18 +28,14 @@ action :discover do unless exists? Chef::Log.info("Discovering pear channel #{new_resource}") - execute "#{new_resource.binary} channel-discover #{new_resource.channel_name}" do - action :run - end + execute "#{new_resource.binary} channel-discover #{new_resource.channel_name}" end end action :add do unless exists? Chef::Log.info("Adding pear channel #{new_resource} from #{new_resource.channel_xml}") - execute "#{new_resource.binary} channel-add #{new_resource.channel_xml}" do - action :run - end + execute "#{new_resource.binary} channel-add #{new_resource.channel_xml}" end end @@ -55,9 +51,7 @@ action :remove do if exists? Chef::Log.info("Deleting pear channel #{new_resource}") - execute "#{new_resource.binary} channel-delete #{new_resource.channel_name}" do - action :run - end + execute "#{new_resource.binary} channel-delete #{new_resource.channel_name}" end end @@ -68,7 +62,9 @@ # @return [Boolean] does the channel need to be updated def update_needed? begin - return true if shell_out("#{new_resource.binary} search -c #{new_resource.channel_name} NNNNNN").stdout =~ /channel-update/ + if shell_out("#{new_resource.binary} search -c #{new_resource.channel_name} NNNNNN").stdout =~ /channel-update/ + return true + end rescue Chef::Exceptions::CommandTimeout # CentOS can hang on 'pear search' if a channel needs updating Chef::Log.info("Timed out checking if channel-update needed...forcing update of pear channel #{new_resource.channel_name}") diff --git a/spec/libraries/helpers_spec.rb b/spec/libraries/helpers_spec.rb new file mode 100644 index 000000000..946420137 --- /dev/null +++ b/spec/libraries/helpers_spec.rb @@ -0,0 +1,66 @@ +require 'spec_helper' +require_relative '../../libraries/helpers' + +RSpec.describe Php::Cookbook::Helpers do + class DummyClass < Chef::Node + include Php::Cookbook::Helpers + end + + subject { DummyClass.new } + + describe '#php_version' do + before do + allow(subject).to receive(:[]).with('platform_family').and_return(platform_family) + allow(subject).to receive(:[]).with('platform').and_return(platform) + allow(subject).to receive(:[]).with('platform_version').and_return(platform_version) + end + + context 'rhel' do + let(:platform_family) { 'rhel' } + let(:platform) { nil } + let(:platform_version) { nil } + it { expect(subject.php_version).to eq '7.2' } + end + + context 'amazon' do + let(:platform_family) { 'amazon' } + let(:platform) { nil } + let(:platform_version) { nil } + it { expect(subject.php_version).to eq '8.2' } + end + + context 'debian' do + let(:platform_family) { 'debian' } + + context 'debian 10' do + let(:platform) { 'debian' } + let(:platform_version) { '10' } + it { expect(subject.php_version).to eq '7.3' } + end + + context 'debian 11' do + let(:platform) { 'debian' } + let(:platform_version) { '11' } + it { expect(subject.php_version).to eq '7.4' } + end + + context 'ubuntu 18.04' do + let(:platform) { 'ubuntu' } + let(:platform_version) { '18.04' } + it { expect(subject.php_version).to eq '7.2' } + end + + context 'ubuntu 20.04' do + let(:platform) { 'ubuntu' } + let(:platform_version) { '20.04' } + it { expect(subject.php_version).to eq '7.4' } + end + + context 'ubuntu 22.04' do + let(:platform) { 'ubuntu' } + let(:platform_version) { '22.04' } + it { expect(subject.php_version).to eq '8.1' } + end + end + end +end diff --git a/spec/recipes/default_spec.rb b/spec/recipes/default_spec.rb deleted file mode 100644 index 5f8748d7a..000000000 --- a/spec/recipes/default_spec.rb +++ /dev/null @@ -1,76 +0,0 @@ -require 'spec_helper' - -shared_examples_for 'php' do - it 'installs php and pear' do - expect(chef_run).to install_package packages - end - - it 'creates php.ini' do - expect(chef_run).to create_template php_ini_path - end -end - -describe 'php::default' do - context 'on amazon linux 2' do - platform 'amazon', '2' - - let(:packages) { %w(php php-devel php-cli php-pear) } - let(:php_ini_path) { '/etc/php.ini' } - - it_should_behave_like 'php' - end - - context 'on centos 7' do - platform 'centos', '7' - - let(:packages) { %w(php php-devel php-cli php-pear) } - let(:php_ini_path) { '/etc/php.ini' } - - it_should_behave_like 'php' - end - - context 'on debian 9' do - platform 'debian', '9' - - let(:packages) { ['php7.0-cgi', 'php7.0', 'php7.0-dev', 'php7.0-cli', 'php-pear'] } - let(:php_ini_path) { '/etc/php/7.0/cli/php.ini' } - - it_should_behave_like 'php' - end - - context 'on debian 10' do - platform 'debian', '10' - - let(:packages) { %w(php-cgi php php-dev php-cli php-pear) } - let(:php_ini_path) { '/etc/php/7.3/cli/php.ini' } - - it_should_behave_like 'php' - end - - context 'on ubuntu 16.04' do - platform 'ubuntu', '16.04' - - let(:packages) { ['php7.0-cgi', 'php7.0', 'php7.0-dev', 'php7.0-cli', 'php-pear'] } - let(:php_ini_path) { '/etc/php/7.0/cli/php.ini' } - - it_should_behave_like 'php' - end - - context 'on ubuntu 18.04' do - platform 'ubuntu', '18.04' - - let(:packages) { ['php7.2-cgi', 'php7.2', 'php7.2-dev', 'php7.2-cli', 'php-pear'] } - let(:php_ini_path) { '/etc/php/7.2/cli/php.ini' } - - it_should_behave_like 'php' - end - - context 'on ubuntu 20.04' do - platform 'ubuntu', '20.04' - - let(:packages) { ['php7.4-cgi', 'php7.4', 'php7.4-dev', 'php7.4-cli', 'php-pear'] } - let(:php_ini_path) { '/etc/php/7.4/cli/php.ini' } - - it_should_behave_like 'php' - end -end diff --git a/templates/centos/php.ini.erb b/templates/centos/php.ini.erb index a9e5d16bf..b892ad27e 100644 --- a/templates/centos/php.ini.erb +++ b/templates/centos/php.ini.erb @@ -526,7 +526,7 @@ doc_root = user_dir = ; Directory in which the loadable extensions (modules) reside. -extension_dir = "<%= node['php']['ext_dir'] %>" +extension_dir = "<%= @php_ext_dir %>" ; Whether or not to enable the dl() function. The dl() function does NOT work ; properly in multithreaded servers, such as IIS or Zeus, and is automatically diff --git a/templates/default/php.ini.erb b/templates/default/php.ini.erb index 3d0fe7f2b..bb28b5d08 100644 --- a/templates/default/php.ini.erb +++ b/templates/default/php.ini.erb @@ -1475,8 +1475,8 @@ session.cache_expire = 180 ; trans sid support is disabled by default. ; Use of trans sid may risk your users' security. ; Use this option with caution. -; - User may send URL contains active session ID -; to other person via. email/irc/etc. +; - User may send URL that contains active session ID +; to other person via email/irc/etc. ; - URL that contains active session ID may be stored ; in publicly accessible computer. ; - User may access your site with the same session ID diff --git a/templates/redhat/php.ini.erb b/templates/redhat/php.ini.erb index a9e5d16bf..b892ad27e 100644 --- a/templates/redhat/php.ini.erb +++ b/templates/redhat/php.ini.erb @@ -526,7 +526,7 @@ doc_root = user_dir = ; Directory in which the loadable extensions (modules) reside. -extension_dir = "<%= node['php']['ext_dir'] %>" +extension_dir = "<%= @php_ext_dir %>" ; Whether or not to enable the dl() function. The dl() function does NOT work ; properly in multithreaded servers, such as IIS or Zeus, and is automatically diff --git a/templates/ubuntu/php.ini.erb b/templates/ubuntu/php.ini.erb index 9d47d75eb..37bb9409b 100644 --- a/templates/ubuntu/php.ini.erb +++ b/templates/ubuntu/php.ini.erb @@ -1542,10 +1542,10 @@ session.cache_expire = 180 ; trans sid support is disabled by default. ; Use of trans sid may risk your users security. ; Use this option with caution. -; - User may send URL contains active session ID -; to other person via. email/irc/etc. +; - User may send URL that contains active session ID +; to other person via email/irc/etc. ; - URL that contains active session ID may be stored -; in publically accessible computer. +; in publicly accessible computer. ; - User may access your site with the same session ID ; always using URL stored in browser's history or bookmarks. ; http://php.net/session.use-trans-sid diff --git a/test/cookbooks/test/metadata.rb b/test/cookbooks/test/metadata.rb index 6b3bc6863..82f857e35 100644 --- a/test/cookbooks/test/metadata.rb +++ b/test/cookbooks/test/metadata.rb @@ -7,3 +7,6 @@ depends 'php' depends 'apt' +depends 'ondrej_ppa_ubuntu' +depends 'yum-epel' +depends 'yum-remi-chef', '>= 5.0.1' diff --git a/test/cookbooks/test/recipes/community.rb b/test/cookbooks/test/recipes/community.rb index b8f88759d..75146f8d9 100644 --- a/test/cookbooks/test/recipes/community.rb +++ b/test/cookbooks/test/recipes/community.rb @@ -1,34 +1,49 @@ -node.default['php']['fpm_ini_control'] = false +# Set constants +set_conf_dir = nil +set_conf_dir = if platform_family?('rhel', 'amazon') + '/etc/opt/remi/php80' + else + '/etc/php/8.2' + end -if platform_family?('rhel', 'amazon') - node.default['php']['packages'] = %w(php80 php80-php-devel php80-php-cli php80-php-pear) - node.default['php']['conf_dir'] = '/etc/opt/remi/php80' - node.default['php']['ext_conf_dir'] = '/etc/opt/remi/php80/php.d' - node.default['php']['fpm_package'] = 'php80-php-fpm' - node.default['php']['fpm_service'] = 'php80-php-fpm' - node.default['php']['fpm_pooldir'] = '/etc/opt/remi/php80/php-fpm.d' - node.default['php']['fpm_default_conf'] = '/etc/opt/remi/php80/php-fpm.d/www.conf' - node.default['php']['pear'] = '/usr/bin/php80-pear' +apt_update 'update' - lib_dir = node['kernel']['machine'] =~ /x86_64/ ? 'lib64' : 'lib' - node.default['php']['ext_dir'] = "/opt/remi/php80/root/#{lib_dir}/php/modules" -elsif platform_family?('debian') - node.default['php']['packages'] = %w(php8.2 php8.2-cgi php8.2-cli php8.2-dev php-pear) - node.default['php']['conf_dir'] = '/etc/php/8.2/' - node.default['php']['ext_conf_dir'] = '/etc/php/8.2/mods-available' - node.default['php']['fpm_package'] = 'php8.2-fpm' - node.default['php']['fpm_service'] = 'php8.2-fpm' - node.default['php']['fpm_conf_dir'] = '/etc/php/8.2/fpm' - node.default['php']['fpm_pooldir'] = '/etc/php/8.2/fpm/pool.d' - node.default['php']['fpm_default_conf'] = '/etc/php/8.2/fpm/pool.d/www.conf' - node.default['php']['fpm_socket'] = '/var/run/php/php8.2-fpm.sock' +# Start of the old community_package recipe --- +if platform_family?('rhel') + include_recipe 'yum-remi-chef::remi' +elsif platform?('ubuntu') + # ondrej no longer supports Ubuntu <20.04 + if platform_version.to_i < 20 + Chef::Log.fatal 'Skipping run - Ubuntu <20.04 is not supported by the ondrej ppa' + return + end + include_recipe 'ondrej_ppa_ubuntu' +elsif platform?('debian') + # use sury repo for debian (https://deb.sury.org/) + apt_repository 'sury-php' do + uri 'https://packages.sury.org/php/' + key 'https://packages.sury.org/php/apt.gpg' + components %w(main) + end +# Amazon Linux isn't supported by Remi +elsif platform_family?('amazon') + Chef::Log.fatal 'Skipping run - Amazon Linux is not supported by Remi' + return end -node.default['php']['install_method'] = 'community_package' +php_install 'Install PHP from community repo' do + conf_dir set_conf_dir + if platform_family?('rhel', 'amazon') + lib_dir = node['kernel']['machine'] =~ /x86_64/ ? 'lib64' : 'lib' -apt_update 'update' + packages %w(php80 php80-php-devel php80-php-cli php80-php-xml php80-php-pear) + ext_dir "/opt/remi/php80/root/#{lib_dir}/php/modules" + else + packages %w(php8.2 php8.2-cgi php8.2-cli php8.2-dev php8.2-xml php-pear) + end +end -include_recipe 'php' +# End of old community_package recipe --- # README: The Remi repo intentionally avoids installing the binaries to # the default paths. It comes with a /opt/remi/php80/enable profile @@ -39,7 +54,7 @@ to '/usr/bin/php80' end - link '/usr/bin/php-pear' do + link '/usr/bin/pear' do to '/usr/bin/php80-pear' end @@ -54,28 +69,45 @@ # Create a test pool php_fpm_pool 'test-pool' do - action :install + fpm_ini_control true + if platform_family?('rhel', 'amazon') + service 'php80-php-fpm' + fpm_conf_dir '/etc/opt/remi/php80/php-fpm.d' + listen '/var/run/php-test-fpm.sock' + pool_dir '/etc/opt/remi/php80/php-fpm.d' + fpm_package 'php80-php-fpm' + default_conf '/etc/opt/remi/php80/php-fpm.d/www.conf' + else + service 'php8.2-fpm' + fpm_conf_dir '/etc/php/8.2/fpm' + listen '/var/run/php/php8.2-fpm.sock' + pool_dir '/etc/php/8.2/fpm/pool.d' + fpm_package 'php8.2-fpm' + default_conf '/etc/php/8.2/fpm/pool.d/www.conf' + end end # Add PEAR channel php_pear_channel 'pear.php.net' do - binary node['php']['pear'] action :update end # Install https://pear.php.net/package/HTTP2 -php_pear 'HTTP2' do - binary node['php']['pear'] -end +php_pear 'HTTP2' # Add PECL channel php_pear_channel 'pecl.php.net' do - binary node['php']['pear'] action :update end # Install https://pecl.php.net/package/sync php_pear 'sync-binary' do + conf_dir set_conf_dir + if platform_family?('rhel', 'amazon') + ext_conf_dir '/etc/opt/remi/php80/php.d' + else + ext_conf_dir '/etc/php/8.2/mods-available' + end package_name 'sync' binary 'pecl' priority '50' diff --git a/test/cookbooks/test/recipes/default.rb b/test/cookbooks/test/recipes/default.rb index a17f1811d..036587b66 100644 --- a/test/cookbooks/test/recipes/default.rb +++ b/test/cookbooks/test/recipes/default.rb @@ -1,11 +1,9 @@ apt_update 'update' -include_recipe 'php' +php_install 'php' # Create a test pool -php_fpm_pool 'test-pool' do - action :install -end +php_fpm_pool 'test-pool' # Add PEAR channel php_pear_channel 'pear.php.net' do diff --git a/test/cookbooks/test/recipes/source.rb b/test/cookbooks/test/recipes/source.rb deleted file mode 100644 index 4d99c8d4f..000000000 --- a/test/cookbooks/test/recipes/source.rb +++ /dev/null @@ -1,7 +0,0 @@ -apt_update 'update' - -node.default['php']['install_method'] = 'source' -node.default['php']['pear'] = '/usr/local/bin/pear' -node.default['php']['url'] = 'https://ftp.osuosl.org/pub/php/' # the default site blocks github actions boxes - -include_recipe 'php' diff --git a/test/integration/resource/inspec/php_spec.rb b/test/integration/resource/inspec/php_spec.rb index 53c175de0..e7ec8429b 100644 --- a/test/integration/resource/inspec/php_spec.rb +++ b/test/integration/resource/inspec/php_spec.rb @@ -3,8 +3,8 @@ end describe command('pear list-channels') do - its('stdout') { should match /pear\.php\.net/ } - its('stdout') { should match /pecl\.php\.net/ } + its('stdout') { should match(/pear\.php\.net/) } + its('stdout') { should match(/pecl\.php\.net/) } end describe command('php --ri sync') do @@ -13,7 +13,7 @@ unless os[:family] == 'redhat' describe command('php -i') do - its('stdout') { should match /50-sync/ } + its('stdout') { should match(/50-sync/) } end # Check if we didn't accidentally pull in Apache as a dependency (#311) diff --git a/test/integration/resource_community/inspec/php_spec.rb b/test/integration/resource_community/inspec/php_spec.rb index 72dfccf45..9e2fc5a8c 100644 --- a/test/integration/resource_community/inspec/php_spec.rb +++ b/test/integration/resource_community/inspec/php_spec.rb @@ -1,13 +1,13 @@ describe command('php -v') do its('exit_status') { should eq 0 } - its('stdout') { should match /PHP 8/ } + its('stdout') { should match(/PHP 8/) } end -pear_cmd = os.debian? ? 'pear' : 'php-pear' +pear_cmd = os.debian? ? 'pear' : 'php80-pear' describe command("#{pear_cmd} list-channels") do - its('stdout') { should match /pear\.php\.net/ } - its('stdout') { should match /pecl\.php\.net/ } + its('stdout') { should match(/pear\.php\.net/) } + its('stdout') { should match(/pecl\.php\.net/) } end describe command('php --ri sync') do @@ -16,7 +16,7 @@ unless os[:family] == 'redhat' describe command('php -i') do - its('stdout') { should match /50-sync/ } + its('stdout') { should match(/50-sync/) } end # Check if we didn't accidentally pull in Apache as a dependency (#311) diff --git a/test/integration/source_install/inspec/php_spec.rb b/test/integration/source_install/inspec/php_spec.rb deleted file mode 100644 index 8f3e08b77..000000000 --- a/test/integration/source_install/inspec/php_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -describe command('php -v') do - its('exit_status') { should eq 0 } -end - -describe command('pear list-channels') do - its('stdout') { should match /pear\.php\.net/ } - its('stdout') { should match /pecl\.php\.net/ } -end