diff --git a/lib/facter/php_fact_web_ini_file_path.rb b/lib/facter/php_fact_web_ini_file_path.rb new file mode 100644 index 0000000..4de79cc --- /dev/null +++ b/lib/facter/php_fact_web_ini_file_path.rb @@ -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 \ No newline at end of file diff --git a/manifests/ini.pp b/manifests/ini.pp index 4854863..5202863 100644 --- a/manifests/ini.pp +++ b/manifests/ini.pp @@ -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 => '/', diff --git a/manifests/params.pp b/manifests/params.pp index 8da0d51..e4f5905 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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 ? {