voxpupuli / puppet-php

Generic Puppet module to manage PHP on many platforms
http://forge.puppet.com/puppet/php
MIT License
87 stars 268 forks source link

RHEL8: keeps installing php7.2.4 #684

Open abctaylor opened 1 year ago

abctaylor commented 1 year ago

Hello - after trying many hacks and tricks in previous issues submitted, this still appears to be very non-trivial to do, and the php_version setting is essentially useless. How can a different version of PHP be installed? No matter what you enter for php_version, it still chooses something different.

Affected Puppet, Ruby, OS and module versions/distributions

How to reproduce (e.g Puppet code you use)

  class { '::php::globals':
    php_version => '8.2',
    config_root => '/etc/php/8.2',
  }->class { '::php':
    manage_repos   => false,
    package_prefix => 'php82-php-',
    settings       => {
      'PHP/max_execution_time'  => '90',
      'PHP/max_input_time'      => '300',
      'PHP/memory_limit'        => '1G',
      'PHP/post_max_size'       => '1G',
      'PHP/upload_max_filesize' => '10G',
      'Date/date.timezone'      => 'Europe/London',
    },
  }

What are you seeing

PHP 7.2.4 gets installed, no matter what.

What behaviour did you expect instead

PHP 8.2 gets installed

abctaylor commented 1 year ago

The issue is because the OS' default repo (e.g. rhel-8-for-x86_64-appstream-rpms) takes preference, and this has an older RPM than Remi.

jlemire3 commented 1 month ago

I know this is an older issue, but it's still open and relevant, so I wanted to post a workaround for anyone having trouble with this installing PHP 7 instead of PHP 8.

I understand that Oracle Linux isn't officially supported by the module, and that RHEL 7 is the only "officially" supported version, but the module works in Oracle Linux 8 aside from the package issues.

My current environment consists of: Puppet: 8 Agent version: 8.6.0 Module version: 10.2.0 OS: Oracle Linux 8.10 PHP Version: 8.3 (Remi)

With Oracle Linux 8, the default AppStream repo wants to use 7.4 by default, but also has 8.2 available to use. Unfortunately trying to specify PHP 8.2 in the PHP module has the same problems as this issue, and it will not install anything newer than 7.2.4.

I have been trying to install PHP 8.3 using this module and I've had it working for months by manually creating the remi-release repository and setting my default DNF module for PHP to php:remi-8.3. This would set the expected version of PHP as the default module to install, and installations would use 8.3, but it would cause corrective changes every run because the PHP module would conflict with my manual packages trying to change it back to PHP 7.

This worked for my needs, but it was frustrating having the corrective changes every run, so I spent some time playing with configurations until I found a way to have the php module install the correct package versions on its own without having to introduce corrective changes.

In hindsight, the cleanest workaround to this issue was staring me right in my face by using php::globals to overwrite the package information. It took a lot of reading through the code trying to reverse engineer how the package management stuff was actually working, and I was misunderstanding how to use php::globals for awhile too. I spent quite a bit of time trying to get the php class parameter 'package_prefix' working but to no avail. What ultimately got everything working right was setting 'rhscl_mode' to 'remi' and 'php_version' to 'php83' in php::globals, and making sure to the remi repository is installed before I let the php module run.

My workaround is still not perfect and ultimately it would be great to get this code fixed so this isn't necessary, but here is the code I have running in my production environment to enable this:

# Installs the following 3 repos in '/etc/yum.repos.d/': remi-modular.repo, remi.repo, remi-safe.repo
package { 'remi-release':
  ensure   => 'present',
  source   => 'https://rpms.remirepo.net/enterprise/remi-release-8.rpm',
  provider => 'dnf',
}
class { 'php::globals':
  php_version => "php83",
  rhscl_mode  => 'remi',
  require         => [Package['remi-release']],
}
-> class { 'php':
  ensure                => $ensure,
  manage_repos   => false,
  fpm                    => true,
  composer          => true,
}