Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select PHP version on RedHat #414

Open
benoistlaurent opened this issue Mar 25, 2024 · 3 comments
Open

Select PHP version on RedHat #414

benoistlaurent opened this issue Mar 25, 2024 · 3 comments

Comments

@benoistlaurent
Copy link

benoistlaurent commented Mar 25, 2024

Description

If I'm not mistaken, one cannot select the PHP version to install on RedHat.

Why is it important?

This is critically important to me because I am developing this role that installs a website that requires PHP >= 7.4 (namely dokuwiki).

Now, in my opinion, my ansible-role-dokuwiki is totally responsible for installing the PHP version it requires.

Right now, this is done by selecting the appropriate module before running the php role:

ansible-role-dokuwiki/tasks/main.yml:

- name: Selects PHP:7.4 (RedHat)
  command: "dnf module enable -y php:7.4"
  when: ansible_os_family == "RedHat"

- name: Install php
  include_role: 
    name: geerlingguy.php

Also, my role defines geerlingguy.php as a dependency in meta/main.yml.

Problem

As ansible runs the dependencies before the current role tasks, it results in a bug due to RedHat's (rightful) refusal to select a different PHP version after installing certain packages.

Proposed solution

  1. Defining php_default_version_redhat in defaults/main.yml
  2. Include this in tasks/main.yml
- name: Set the default PHP version for RedHat-based OSes.
  command: "dnf module enable -y php:{{ php_default_version_redhat }}"  
  when: php_default_version_redhat is defined and ansible_os_family == 'RedHat'

Workaround

The workaround would be to select the appropriate PHP module in the playbook that runs ansible-role-dokuwiki:

server-setup.yml:

---
- hosts: all
  pre_tasks:
   - name: Selects PHP:7.4 (RedHat)
     command: "dnf module enable -y php:7.4"
     when: ansible_os_family == "RedHat"

  roles:
    - ansible-role-dokuwiki

This is not acceptable for me, as, again, to me, ansible-role-dokuwiki is suppose to install the adequate version of PHP, depending on the dokuwiki version the user is ultimately installing.

benoistlaurent added a commit to benoistlaurent/ansible-role-php that referenced this issue Mar 26, 2024
@brendongitx
Copy link

+1 this would be a good addition to the role.

In my circumstance I needed to install php8.1 which required an extra step to add in the remi repo

        - name: Install remi repository
          ansible.builtin.include_role:
            name: geerlingguy.repo-remi

        - name: Enable php:remi-8.1
           command: "dnf module enable -y php:remi-8.1"

Copy link

github-actions bot commented Sep 7, 2024

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

@github-actions github-actions bot added the stale label Sep 7, 2024
@cratakama
Copy link

cratakama commented Oct 3, 2024

@benoistlaurent and @brendon-stephens,
The activation of the dnf module remi:php-<version> is done by another role : geerlingguy.php-versions. This role will select a PHP version and populate some facts that will be used by geerlingguy.php.
Run it prior to an install on Debian based and RHEL systems (which have very different ways to install PHP, especially with custom repos for non default versions)

Here's an example for a FPM deployment on a Rocky 9 system, using remi repo and with the php version in a variable.

- name: "Ensure PHP is deployed"
  hosts: "target"
  become: true
  vars: 
    php_version: '8.3'
    php_packages_extra:
      - "php{{ php_version | replace('.', '') }}-php-imap"
      - "php{{ php_version | replace('.', '') }}-php-imagick"
      - "php{{ php_version | replace('.', '') }}-php-xml"
      - "php{{ php_version | replace('.', '') }}-php-zip"
      - "php{{ php_version | replace('.', '') }}-php-mbstring"
  roles:
    - role: geerlingguy.repo-remi
      when: ansible_os_family == 'RedHat'
    - role: geerlingguy.php-versions
      vars:
        php_version: "{{ php_version }}"
    - role: geerlingguy.php
      vars:
        php_fpm_pools: "{{ php_fpm_pools }}"
        php_packages: "{{ __php_packages | map('regex_replace', '^', 'php' + php_version | replace('.', '') + '-') | list }}"
        php_packages_extra: "{{ php_packages_extra }}"
        php_enable_webserver: false
        php_enable_php_fpm: true
        php_conf_paths:
          - "/etc/opt/remi/php{{ php_version | replace('.', '') }}"
        php_extension_conf_paths: "/etc/opt/remi/php{{ php_version | replace('.', '') }}/mods-available"
        php_fpm_daemon: "php{{ php_version | replace('.', '') }}-php-fpm"
        php_fpm_conf_path: "/etc/opt/remi/php{{ php_version | replace('.', '') }}/php-fpm.conf"
        php_fpm_pool_conf_path: /etc/opt/remi/php{{ php_version | replace('.', '') }}/php-fpm.d/www.conf
        php_fpm_handler_state: "reloaded"

The extra vars on geerlingguy.php allows me to set the conf paths so I can have multiple versions of PHP on the same host.
Note that you'll need to setup the FPM listener to a socket file in different directories depending on your install, if like me you don't want to use a TCP port for that.

Hope it helped.

@github-actions github-actions bot removed the stale label Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants