Enabling PHP 7.4 on CentOS 7 with Puppet

September 17, 2019 – Samuli Seppänen

The PHP version comes in default CentOS 7 repositories is rather horribly outdated. This is problematic when running WordPress, which has to be upgraded constantly, and really old PHP versions may not be accepted, security-patched or not. The solution is to get updated PHP from the remi yum repositories. There are two sets of PHP packages as described here:

  • Install updated packages that replace the old PHP 5 packages (i.e. names are the same)
  • Install PHP 7.4 alongside old PHP 5 packages

The former is what we're interested here, as it in requires less modifications in Puppet code.

Manual installation of the remi repository is pretty straightforward. But when you're managing WordPress and PHP with Puppet, things get a bit more tricky. Here's an example from our WordPress profile on how to enable PHP 7.4:

# The remi repository release package contains tons of repository
# configurations and converting all of those to Puppet code would be tedious,
# require managing GPG keys manually and offer little benefit. So, we install
# the package, get rid of the repositories we don't want and customize the
# repositories we do want with the yumrepo resource.
#
package { 'remi-release':
ensure => 'present',
name => 'remi-release',
provider => 'rpm',
source => 'https://rpms.remirepo.net/enterprise/remi-release-7.rpm',
}

# We need this to ensure that remi PHP 7.4 packages are preferred over the
# old PHP 5.x packages available in other repositories. The default priority
# is 99, and we set remi packages to priority 50. The lower priority wins.
package { 'yum-plugin-priorities':
ensure => 'present',
}

$yumrepo_defaults = {
'ensure' => 'present',
'enabled' => true,
'gpgcheck' => true,
'priority' => 50,
'require' => [ Package['remi-release'], Package['yum-plugin-priorities'] ],
}

yumrepo { 'remi-safe':
descr => 'Safe Remi RPM repository for Enterprise Linux 7',
mirrorlist => 'http://cdn.remirepo.net/enterprise/7/safe/mirror',
* => $yumrepo_defaults,
}

yumrepo { 'remi-php74':
descr => 'Remi PHP 7.4 RPM repository for Enterprise Linux 7',
mirrorlist => 'http://cdn.remirepo.net/enterprise/7/php74/mirror',
* => $yumrepo_defaults,
}

# Disable unwanted remi repos
['glpi91','glpi92','glpi93','glpi94','modular','php54','php70','php71','php72','php73'].each |$repo| {
file { "/etc/yum.repos.d/remi-${repo}.repo":
ensure => 'absent',
require => Package['remi-release'],
}
}

If you use puppetlabs-apache to manage Apache modules you need to modify the class parameters for ::apache::mod:php as well:

class { '::apache::mod::php':
php_version => '7',
}

This ensures that the PHP 7 module is enabled instead of the PHP 5 version: the latter won't be installed at all and trying to start httpd will fail.

...

Want to talk to an expert?

If you want to reach us, just send us a message or book a free call!
Categories

Tags

#aad #Access #acl #alertmanager #ansible #ansible module development #Apache #API #augeas #authentication #authorization #automation #automatization #aws #azure #backup #bash #bitbucket #buildbot #cache #centos #cloud #cloud-init #cloudflare #cloudfront #cluster #connectionsJpa #control repo #custom fact #database #debian #devops #digital sovereignty #DNS #docker #domain mode #duplo #ejabberd #email #encryption #erb #europe #eyaml #fabric #facter #facts #fargate #fedora #file #finnish #foreman #freeipa #git #github #gitlab #gnome #google #grafana #hammer #hiera #IAM #import #infinispan #Infrastructure as Code #ipmi #irc #jboss #jdk #jenkins #JMESPath #kanban #keycloak #librarian-puppet #librenms #linkedin #Linux #Location #loop #marketing #mautic #Mellon #mfa #monitoring #mysql #nagios #network-manager #oauth #oauth2 #office365 #open source #openvpn #oxygen #packer #paranormal #pdk #people #php #pkcs7 #pomodoro #Powershell #preseed #presentation #profiles #prometheus #provisioning #puppet #puppet-bolt #puppet-litmus #puppetboard #puppetdb #Puppetfile #puppetserver #puppet types and providers #pxeboot #qemu #quality #r10k #recruitment #redirect #Restrict #Reverse Proxy #roles #rspec #ruby #SAML #sem #shell #showsql #snmp #snmpd #software developement #spam #ssh #sso #standardization #systemd #systemd-resolved #teams #terraform #ubuntu #user-data #vagrant #vanity awards #variable #vim #virtualbox #visualstudio #webdevelopment #wildfly #Windows #wireguard #wordpress #workflow #x11 #xmpp #zimbra
We are
 Puppeteers
menucross-circle