Skip to content

Commit

Permalink
Adding php5 module configuration. Includes overriding a few parameter…
Browse files Browse the repository at this point in the history
…s from the php.ini defaults without editing that file; 'off-by-default', with the ability to turn on php for <Directory> or <Location>. Access control by host or ip is done via the standard access.pp controls.
  • Loading branch information
sharumpe committed Dec 4, 2014
1 parent 2982a2d commit 59f0894
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 1 deletion.
2 changes: 1 addition & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
$packageName = "apache2"

$jkPackageName = "apache2-mod_jk"
$php5PackageName = "apache2-mod_php5"
$phpPackageName = "apache2-mod_php5"

$sysconfigPath = "/etc/sysconfig/apache2"

Expand Down
50 changes: 50 additions & 0 deletions manifests/php.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class apache2::php
(
$phpMemoryLimit,
$phpErrorLog = "/var/log/apache2/php-error_log",
$phpExposePhp = "off",
$phpTimezone = "America/Los_Angeles",
$appDirs = []
)
{
include apache2::params

#validate_re( $phpMemoryLimit, "^[0..9]+[MmGg]" )
validate_string( $phpMemoryLimit )
validate_string( $phpErrorLog )
validate_re( $phpExposePhp, "^(on|off)" )
validate_string( $phpTimezone )
validate_array( $appDirs )

# install the package
package { $params::phpPackageName :
ensure => latest,
}

# include the module
apache2::enableModule{ 'php5':
require => Package[ $params::phpPackageName ],
}

# Pick the template path we're going to use
$mod_path = get_module_path('apache2')
$specific = "$mod_path/templates/$operatingsystem/$operatingsystemrelease$params::phpConfigPath.erb"
$default = "$mod_path/templates/default$params::phpConfigPath.erb"

# write the config file
file { $params::phpConfigPath :
ensure => file,
content => inline_template( file( $specific, $default ) ),
notify => $apache2::serviceNotify,
require => Package[ $params::phpPackageName ],
}

# if any apps were specified, create them
class { 'apache2::php::app' : }
if ( is_array( $appDirs ) and size( $appDirs ) > 0 ) {
apache2::php::addAppDir{ $appDirs : }
}
if ( is_array( $appLocs ) and size( $appLocs ) > 0 ) {
apache2::php::addAppLoc{ $appLocs : }
}
}
68 changes: 68 additions & 0 deletions manifests/php/app.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
class apache2::php::app
{
concat { $params::phpAppsConfigPath :
ensure => present,
notify => $apache2::serviceNotify,
require => Package[ $params::phpPackageName ],
}


concat::fragment { "$params::phpAppsConfigPath-fragment-pre" :
target => $params::phpAppsConfigPath,
order => 01,
content => "<IfModule mod_php5.c>\n",
}

concat::fragment { "$params::phpAppsConfigPath-fragment-post" :
target => $params::phpAppsConfigPath,
order => 99,
content => "</IfModule>\n",
}
}

define apache2::php::addAppDir
(
$appDir = $name
)
{
include apache2::params

validate_string( $appDir )

# Pick the template path we're going to use
$mod_path = get_module_path('apache2')
$specific = "$mod_path/templates/$operatingsystem/$operatingsystemrelease$params::phpAppsConfigPath-appDir-frag.erb"
$default = "$mod_path/templates/default$params::phpAppsConfigPath-appDir-frag.erb"

# write the config file
concat::fragment { $appDir :
target => $params::phpAppsConfigPath,
order => 10,
content => inline_template( file( $specific, $default ) ),
}

}

define apache2::php::addAppLoc
(
$appLoc = $name
)
{
include apache2::params

validate_string( $appLoc )

# Pick the template path we're going to use
$mod_path = get_module_path('apache2')
$specific = "$mod_path/templates/$operatingsystem/$operatingsystemrelease$params::phpAppsConfigPath-appLoc-frag.erb"
$default = "$mod_path/templates/default$params::phpAppsConfigPath-appLoc-frag.erb"

# write the config file
concat::fragment { $appLoc :
target => $params::phpAppsConfigPath,
order => 10,
content => inline_template( file( $specific, $default ) ),
}

}

18 changes: 18 additions & 0 deletions templates/default/etc/apache2/conf.d/php5.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<IfModule mod_php5.c>
<% if @phpMemoryLimit -%>
# Set the memory limit
php_admin_value memory_limit <%= @phpMemoryLimit %>
<% end -%>

# Don't tell folks we're using php
php_admin_value expose_php <%= @phpExposePhp %>

# Set the timezone
php_value date.timezone <%= @phpTimezone %>

# Where is the error_log?
php_value error_log <%= @phpErrorLog %>

# Include the application definition file.
IncludeOptional /etc/apache2/conf.d/php5Apps.conf.inc
</IfModule>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Directory "<%= @appDir -%>*">
# see conf.d/access.conf for other access controls
AddHandler application/x-httpd-php .php
</Directory>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Location "/<%= @appLoc -%>*">
# see conf.d/access.conf for other access controls
AddHandler application/x-httpd-php .php
</Location>

0 comments on commit 59f0894

Please sign in to comment.