sous-chefs / sous-chefs/php

shell_out() without { default_env: false } param causes pecl install to fail

Open
#256 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug hacktoberfest Priority: Medium
Dominant language
HTML
Stars
454
Forks
480
Avg merge
5h 35m
Merged PRs (30d)
1

Description

👻 (Not A) Brief Description

When trying to install PHP7.2 from SCL on CentOS 7, installing a pecl package (imagick for example) using the php_pear resource fails because the dependencies cannot be found even when they are installed. But SSH-ing into the machine and running pecl install imagick via command line, runs without issue.

I think I've narrowed down the problem to the usage of shell_out() and how it handles the PATH environment variable. Calling it without the { default_env: false } flag causes the chef-client to inject /opt/chef/embedded/bin to the beginning of the $PATH so that when command runs, it picks up the pkg-config embedded in Chef instead of the one installed on the system.

Calling shell_out() without the flag: checking for pkg-config... /opt/chef/embedded/bin/pkg-config

Calling shell_out() with the flag: checking for pkg-config... /usr/bin/pkg-config

I can't figure out why it works without problems when using the default php version installed by CentOS, but either way I think that php_pear should explicitly tell chef-client to not muck with $PATH for consistency. Even the execute resource uses this flag to have the output match what you would see if you were to run it manually via command line (See: https://github.com/chef/chef/blob/master/lib/chef/resource/execute.rb#L72).

I'm not sure if this would break for other platforms, but it seems to work fine when updating calls to shell_out() to include this flag. Example below:

def pear_shell_out(command)
  p = shell_out!(command, { default_env: false })
  # pear/pecl commands return a 0 on failures...we'll grep for it
  p.invalid! if p.stdout.split('\n').last =~ /^ERROR:.+/i
  p
end

For reference:

🥞 Cookbook version

7.0.0

👩‍🍳 Chef-Infra Version

Chef 14.2+

EDIT (2020-02-20):

I'm not sure how to comment further so I'm making an edit here...

Sorry, I wasn't clear. The default_env flag is true by default in Chef 14. The fix that I suggested is to modify the pear_shell_out() method (https://github.com/sous-chefs/php/blob/master/resources/pear.rb#L187) to call shell_out()! with { default_env: false } flag.

The problem only occurs when using a PHP version provided in SCL (e.g.: CentOS 7 running PHP7.2 from SCL). In order to install PHP7.2 I've overridden a lot of the default attributes.

Overrides for reference:

override['php']['packages'] = %w(rh-php72 rh-php72-php-devel rh-php72-php-json rh-php72-php-ldap rh-php72-php-mbstring rh-php72-php-mysqlnd rh-php72-php-opcache rh-php72-php-pdo rh-php72-php-xml)
override['php']['pear'] = '/opt/rh/rh-php72/root/bin/pear'
override['php']['conf_dir'] = '/etc/opt/rh/rh-php72'
override['php']['ext_conf_dir'] = '/etc/opt/rh/rh-php72/php.d'
override['php']['ext_dir'] = '/opt/rh/rh-php72/root/usr/lib64/php/modules'
override['php']['fpm_package'] = 'rh-php72-php-fpm'
override['php']['fpm_pooldir'] = '/etc/opt/rh/rh-php72/php-fpm.d'
override['php']['fpm_default_conf'] = '/etc/opt/rh/rh-php72/php-fpm.d/www.conf'
override['php']['fpm_service'] = 'rh-php72-php-fpm'

To be clear, when using the default PHP that is provided by CentOS 7 (i.e.: without using SCL), there are no issues. I've tested the fix and it works fine for my use case, but I'm not sure if it will break on other platforms.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading resources/pear.rb, especially pear_shell_out, and compare its shell_out! invocation with the execute resource behavior described in the issue. Reproduce the pecl install failure with PHP 7.2 from CentOS SCL, then verify that the resource works with the system pkg-config without regressing default CentOS PHP behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
devops
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.