Skip to content

Commit

Permalink
Merge pull request #906 from jweisner/php_value
Browse files Browse the repository at this point in the history
Implement php_value and php_flag
  • Loading branch information
Morgan Haskel committed Dec 19, 2014
2 parents e4ee780 + 42b488f commit 4f6acff
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,10 @@ Sets [PassengerStartTimeout](https://www.phusionpassenger.com/documentation/User

Sets [PassengerPreStart](https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html#PassengerPreStart), the URL of the application if pre-starting is required.

#####`php_flags & values`

Allows per-vhost setting [`php_value`s or `php_flag`s](http://php.net/manual/en/configuration.changes.php). These flags or values can be overwritten by a user or an application. Defaults to '[]'.

#####`php_admin_flags & values`

Allows per-vhost setting [`php_admin_value`s or `php_admin_flag`s](http://php.net/manual/en/configuration.changes.php). These flags or values cannot be overwritten by a user or an application. Defaults to '[]'.
Expand Down Expand Up @@ -1791,6 +1795,10 @@ Sets the value for the [PassengerEnabled](http://www.modrails.com/documentation/
```

*Note:* Be aware that there is an [issue](http://www.conandalton.net/2010/06/passengerenabled-off-not-working.html) using the PassengerEnabled directive with the PassengerHighPerformance directive.

######`php_value` and `php_flag`

`php_value` sets the value of the directory, and `php_flag` uses a boolean to configure the directory. Further information can be found [here](http://php.net/manual/en/configuration.changes.php).

######`php_admin_value` and `php_admin_flag`

Expand Down
13 changes: 13 additions & 0 deletions manifests/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
$suphp_addhandler = $::apache::params::suphp_addhandler,
$suphp_engine = $::apache::params::suphp_engine,
$suphp_configpath = $::apache::params::suphp_configpath,
$php_flags = {},
$php_values = {},
$php_admin_flags = {},
$php_admin_values = {},
$no_proxy_uris = [],
Expand Down Expand Up @@ -733,6 +735,17 @@
}
}

# Template uses:
# - $php_values
# - $php_flags
if ($php_values and ! empty($php_values)) or ($php_flags and ! empty($php_flags)) {
concat::fragment { "${name}-php":
target => "${priority_real}-${filename}.conf",
order => 220,
content => template('apache/vhost/_php.erb'),
}
}

# Template uses:
# - $php_admin_values
# - $php_admin_flags
Expand Down
6 changes: 5 additions & 1 deletion spec/acceptance/mod_php_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class { 'apache::mod::php': }
end
end

context "custom extensions, php_admin_flag, and php_admin_value" do
context "custom extensions, php_flag, php_value, php_admin_flag, and php_admin_value" do
it 'succeeds in puppeting php' do
pp= <<-EOS
class { 'apache':
Expand All @@ -65,6 +65,8 @@ class { 'apache::mod::php':
apache::vhost { 'php.example.com':
port => '80',
docroot => '/var/www/php',
php_values => { 'include_path' => '.:/usr/share/pear:/usr/bin/php', },
php_flags => { 'display_errors' => 'on', },
php_admin_values => { 'open_basedir' => '/var/www/php/:/usr/share/pear/', },
php_admin_flags => { 'engine' => 'on', },
}
Expand All @@ -83,6 +85,8 @@ class { 'apache::mod::php':
end

describe file("#{vhost_dir}/25-php.example.com.conf") do
it { is_expected.to contain " php_flag display_errors on" }
it { is_expected.to contain " php_value include_path .:/usr/share/pear:/usr/bin/php" }
it { is_expected.to contain " php_admin_flag engine on" }
it { is_expected.to contain " php_admin_value open_basedir /var/www/php/:/usr/share/pear/" }
end
Expand Down
11 changes: 11 additions & 0 deletions templates/vhost/_directories.erb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@
<%- if directory['passenger_enabled'] and directory['passenger_enabled'] != '' -%>
PassengerEnabled <%= directory['passenger_enabled'] %>
<%- end -%>
<%- if directory['php_flags'] and ! directory['php_flags'].empty? -%>
<%- directory['php_flags'].each do |flag,value| -%>
<%- value = if value =~ /true|yes|on|1/i then 'on' else 'off' end -%>
php_flag <%= "#{flag} #{value}" %>
<%- end -%>
<%- end -%>
<%- if directory['php_values'] and ! directory['php_values'].empty? -%>
<%- directory['php_values'].each do |key,value| -%>
php_value <%= "#{key} #{value}" %>
<%- end -%>
<%- end -%>
<%- if directory['php_admin_flags'] and ! directory['php_admin_flags'].empty? -%>
<%- directory['php_admin_flags'].each do |flag,value| -%>
<%- value = if value =~ /true|yes|on|1/i then 'on' else 'off' end -%>
Expand Down
12 changes: 12 additions & 0 deletions templates/vhost/_php.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% if @php_values and not @php_values.empty? -%>
<%- @php_values.sort.each do |key,value| -%>
php_value <%= key %> <%= value %>
<%- end -%>
<% end -%>
<% if @php_flags and not @php_flags.empty? -%>
<%- @php_flags.sort.each do |key,flag| -%>
<%-# normalize flag -%>
<%- if flag =~ /true|yes|on|1/i then flag = 'on' else flag = 'off' end -%>
php_flag <%= key %> <%= flag %>
<%- end -%>
<% end -%>

0 comments on commit 4f6acff

Please sign in to comment.