Skip to content
This repository was archived by the owner on Jun 11, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions lib/facter/php_fact_web_ini_file_path.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# The path to the php.ini file for apache appears to be the first null terminated string
# in the module binary after the null terminated string "PHP_CONFIG_FILE_PATH". This may
# or may not hold for other versions of php, so a sanity check to make sure that the
# directory is an existing file.
# The location of the module binary is obtained from the module's *php5*.load file
# included in Apache's config file determined from rules borrowed from
# example42/puppet-apache


apache_conf_path = '/etc/httpd/conf/httpd.conf'
if /Ubuntu|Debian|Mint/i.match(Facter.value("operatingsystem"))
apache_conf_path = '/etc/apache2/apache2.conf'
elsif /SLES|OpenSuSE/i.match(Facter.value("operatingsystem"))
apache_conf_path = '/etc/apache2/httpd.conf'
elsif Facter.value("operatingsystem") == 'freebsd'
apache_conf_path = '/usr/local/etc/apache20/httpd.conf'
end

find_php_ini_path_shell_command =
"if [ -f '" + apache_conf_path + "' ] ; then " +
'ls -d $( ' +
'grep -azA 1 ' +
"'^PHP_CONFIG_FILE_PATH\$' " +
'$( ' +
"sed -e 's/\\s*\$//' -e 's/^.*\\s//' " +
'$( ' +
'ls -1 $( ' +
"echo -n '" + apache_conf_path + "' | " +
"sed -e 'sx/[^/]*\$xx' ; " +
'echo -n / ; ' +
"grep 'mod.*\\.load\$' '" + apache_conf_path + "' | " +
"sed -e 's/\\s*\$//' -e 's/^.*\\s//' " +
') | ' +
'grep php5 ' +
') ' +
') | ' +
"tr '\\000' '\\012' | " +
"grep '^/' " +
') 2> /dev/null ; ' +
'fi'


Facter.add("php_fact_web_ini_file_path") do
setcode do
result = nil
begin
result = Facter::Util::Resolution.exec(find_php_ini_path_shell_command) || nil
if result
result = (result + '/php.ini')
end
rescue
end
result
end
end
9 changes: 8 additions & 1 deletion manifests/ini.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@
$target = 'extra.ini',
$sapi_target = 'all',
$service = $php::service,
$config_dir = $php::config_dir
$config_dir = $php::config_dir,
$web_config_dir = $php::web_config_dir
) {

include php

file { "${web_config_dir}/conf.d/${target}":
ensure => 'present',
content => template("php/${template}"),
require => Package['php'],
notify => Service[$service],
}
$http_sapi = $::operatingsystem ? {
/(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => '/apache2/',
default => '/',
Expand Down
20 changes: 16 additions & 4 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,22 @@
/(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => '/etc/php5',
default => '/etc/php.d',
}

$config_file = $::operatingsystem ? {
/(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => '/etc/php5/apache2/php.ini',
default => '/etc/php.ini',

if $::php_fact_web_ini_file_path =~ /\/conf\.d\/php\.ini$/ {
$web_config_dir = regsubst($::php_fact_web_ini_file_path, '/conf\.d/php\.ini$', '')
} elsif $::operatingsystem =~ /(?i:Ubuntu)/ {
$web_config_dir = '/etc/php5/apache2'
} else {
$web_config_dir = $config_dir
}

if $::php_fact_web_ini_file_path != '' {
$config_file = $::php_fact_web_ini_file_path
} else {
$config_file = $::operatingsystem ? {
/(?i:Ubuntu|Debian|Mint|SLES|OpenSuSE)/ => '/etc/php5/apache2/php.ini',
default => '/etc/php.ini',
}
}

$config_file_mode = $::operatingsystem ? {
Expand Down