Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php now supports only php5-fpm. Opcache config added. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
131 changes: 93 additions & 38 deletions modules/php/manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#
# === Parameters
#
# [*php_engine*]
# What php engine to use.
# Expected values: libapache2-mod-php5 or php5-fpm
#
# [*memory_limit]
# PHP memory limit
#
# [*expose_php*]
# Whether to expose php version - X-Powered-By header.
#
# [*fpm_max_children*]
# pm.max_children for pool.d/www.conf. Only if php_engine is php5-fpm.
#
Expand Down Expand Up @@ -53,30 +53,45 @@
# Marji Cermak <[email protected]>
#
class php (
$php_engine = 'mod-php',
$memory_limit = '96M',
$fpm_max_children = 10,
$fpm_start_servers = 4,
$fpm_min_spare_servers = 2,
$fpm_max_spare_servers = 6,
$fpm_logrotate_rotate = 12,
$fpm_logrotate_when = 'weekly',
$php_error_log_path = '/var/log/php5-errors.log',
$php_error_log_mode = '0640',
$ensure_php_debug_pkgs = 'installed'
$memory_limit = '96M',
$post_max_size = '8M',
$upload_max_filesize = '8M',
$expose_php = 'off',
$fpm_max_children = 10,
$fpm_start_servers = 4,
$fpm_min_spare_servers = 2,
$fpm_max_spare_servers = 6,
$fpm_pm_status_path = undef,
$fpm_ping_path = undef,
$fpm_logrotate_rotate = 12,
$fpm_logrotate_when = 'weekly',
$php_error_log_path = '/var/log/php5-errors.log',
$php_error_log_mode = '0640',
$ensure_php_debug_pkgs = 'installed',
$xdebug_max_nesting_level = 100,
$opcache_enable_cli = 0,
$opcache_revalidate_freq = 4,
$opcache_validate_timestamps = 1,
$opcache_max_accelerated_files = 2000,
$opcache_memory_consumption = 64,
$opcache_interned_strings_buffer = 4
) {

if ! ($expose_php in [ 'off', 'on' ]) {
fail('expose_php parameter has wrong value')
}
if ! ($ensure_php_debug_pkgs in [ 'present', 'installed', 'absent', 'purged' ]) {
fail('ensure_php_debug_pkgs parameter has wrong value')
}
case $php_engine {
mod-php: { $php_engine_pkg = 'libapache2-mod-php5' }
php-fpm: { $php_engine_pkg = 'php5-fpm' }
default: { fail("Unrecognised php engine.") }
$xdebug_ini_ensure = $ensure_php_debug_pkgs ? {
/(present|installed)/ => 'present',
default => 'absent',
}


package { [
'php5',
$php_engine_pkg,
'php5-fpm',
'php-pear',
'php5-cli',
'php5-common',
Expand All @@ -89,33 +104,73 @@
ensure => installed,
}

# prevent libapache2-mod-php5 from installing as a dependency:
package { 'libapache2-mod-php5':
ensure => purged
}

package { [
'php5-xdebug',
'php5-xhprof'
]:
]:
ensure => $ensure_php_debug_pkgs,
}

if $php_engine == 'php-fpm' {
service { 'php5-fpm':
ensure => running,
enable => true,
require => Package['php5-fpm'],
subscribe => File['common.ini', 'xdebug.ini', 'opcache.ini'],
}

package { 'libapache2-mod-php5': ensure => purged }
service { 'php5-fpm':
ensure => running,
enable => true,
hasrestart => true,
require => Package['php5-fpm'],
provider => upstart,
}
file { '/etc/php5/fpm/php.ini':
ensure => present,
content => template('php/fpm/php.ini.erb'),
owner => 'root',
group => 'root',
mode => '0644',
notify => Service['php5-fpm'],
require => Package['php5-fpm'],
}

file { '/etc/php5/fpm/pool.d/www.conf':
ensure => present,
content => template('php/fpm/pool.d/www.conf.erb'),
owner => 'root',
group => 'root',
mode => '0644',
notify => Service['php5-fpm'],
require => Package['php5-fpm'],
}
file { '/etc/php5/fpm/pool.d/www.conf':
ensure => present,
content => template('php/fpm/pool.d/www.conf.erb'),
owner => 'root',
group => 'root',
mode => '0644',
notify => Service['php5-fpm'],
require => Package['php5-fpm'],
}

file { 'common.ini':
ensure => present,
path => '/etc/php5/fpm/conf.d/20-common.ini',
content => template('php/conf.d/common.ini.erb'),
owner => 'root',
group => 'root',
mode => '0444',
require => Package['php5-fpm'],
}

file { 'xdebug.ini':
ensure => $xdebug_ini_ensure,
path => '/etc/php5/mods-available/xdebug.ini',
content => template('php/conf.d/xdebug.ini.erb'),
owner => 'root',
group => 'root',
mode => '0444',
require => Package['php5-xdebug'],
}

file { 'opcache.ini':
ensure => present,
path => '/etc/php5/mods-available/opcache.ini',
content => template('php/conf.d/opcache.ini.erb'),
owner => 'root',
group => 'root',
mode => '0444',
require => Package['php5'],
}

if $fpm_logrotate_when {
Expand Down
1 change: 1 addition & 0 deletions modules/php/templates/conf.d/common.ini.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# your_variable = your_value
11 changes: 11 additions & 0 deletions modules/php/templates/conf.d/opcache.ini.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; configuration for php ZendOpcache module
; priority=05
zend_extension=opcache.so
opcache.enable = 1
opcache.enable_cli = <%= @opcache_enable_cli %>
opcache.revalidate_freq = <%= @opcache_revalidate_freq %>
opcache.validate_timestamps = <%= @opcache_validate_timestamps %>
opcache.max_accelerated_files = <%= @opcache_max_accelerated_files %>
opcache.memory_consumption = <%= @opcache_memory_consumption %>
opcache.interned_strings_buffer = <%= @opcache_interned_strings_buffer %>
opcache.fast_shutdown = 1
3 changes: 3 additions & 0 deletions modules/php/templates/conf.d/xdebug.ini.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
; configuration for php xdebug module
zend_extension=xdebug.so
xdebug.max_nesting_level = <%= @xdebug_max_nesting_level %>
Loading