Skip to content

Commit

Permalink
Create a entry point class and enable customized php name
Browse files Browse the repository at this point in the history
In order to install other version of php than OS provided, we need to
customize the php package name, e.g. php54, php56

To install customized version of php, install third party repo first,
e.g. IUS, then using

    class { 'php': php_name => 'php54' }
  • Loading branch information
xcompass committed Dec 17, 2014
1 parent 9ea9906 commit 403b23c
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 18 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ change everything in ways which are typical for RHEL, but it also works on
Debian based distributions (such as Ubuntu), and support for others should
be easy to add.

* `php` : The entry point of the module
* `php::cli` : Simple class to install PHP's Command Line Interface
* `php::fpm::daemon` : Simple class to install PHP's FastCGI Process Manager
* `php::fpm::conf` : PHP FPM pool configuration definition
Expand All @@ -20,6 +21,10 @@ be easy to add.

## Examples

Declaring the `php` class

include php

Create `php.ini` files for different uses, but based on the same template :

php::ini { '/etc/php.ini':
Expand Down
2 changes: 1 addition & 1 deletion manifests/cli.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
class php::cli (
$ensure = 'installed',
$inifile = '/etc/php.ini',
$cli_package_name = $::php::params::cli_package_name,
) inherits ::php::params {
$cli_package_name = "${::php::php_name}${::php::params::cli_package_suffix}"
package { $cli_package_name:
ensure => $ensure,
require => File[$inifile],
Expand Down
2 changes: 1 addition & 1 deletion manifests/common.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# We can't use a virtual resource, since we have no central place to put it.
#
class php::common (
$common_package_name = $::php::params::common_package_name,
) inherits ::php::params {
$common_package_name = "${::php::php_name}${::php::params::common_package_suffix}"
package { $common_package_name: ensure => 'installed' }
}
2 changes: 1 addition & 1 deletion manifests/fpm/daemon.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#
class php::fpm::daemon (
$ensure = 'present',
$fpm_package_name = $::php::params::fpm_package_name,
$log_level = 'notice',
$emergency_restart_threshold = '0',
$emergency_restart_interval = '0',
Expand All @@ -18,6 +17,7 @@
$log_group = false,
$log_dir_mode = '0770',
) inherits ::php::params {
$fpm_package_name = "${::php::php_name}-fpm"

# Hack-ish to default to user for group too
$log_group_final = $log_group ? {
Expand Down
4 changes: 0 additions & 4 deletions manifests/ini.pp
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,9 @@
$soap_wsdl_cache_dir = '/tmp',
$soap_wsdl_cache_ttl = '86400',
) {

include '::php::common'

file { $title:
ensure => $ensure,
content => template($template),
}

}

4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class php (
$php_name = $::php::params::php_package_name,
) inherits ::php::params {
}
2 changes: 1 addition & 1 deletion manifests/mod_php5.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$inifile = '/etc/php.ini',
) inherits ::php::params {

package { $php_package_name:
package { $::php::php_name:
ensure => $ensure,
require => File[$inifile],
notify => Service[$httpd_service_name],
Expand Down
4 changes: 2 additions & 2 deletions manifests/module.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

# Manage the incorrect named php-apc package under Debians
if ($title == 'apc') {
$package = $::php::params::php_apc_package_name
$package = "${::php::php_name}${::php::params::php_apc_package_name}"
} else {
# Hack to get pkg prefixes to work, i.e. php56-mcrypt title
$package = $title ? {
/^php/ => $title,
default => "${::php::params::php_package_name}-${title}"
default => "${::php::php_name}-${title}"
}
}

Expand Down
4 changes: 2 additions & 2 deletions manifests/module/ini.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
# Package name
$ospkgname = $pkgname ? {
/^php/ => "${pkgname}",
false => "${::php::params::php_package_name}-${title}",
default => "${::php::params::php_package_name}-${pkgname}",
false => "${::php::php_name}-${title}",
default => "${::php::php_name}-${pkgname}",
}
}

Expand Down
11 changes: 5 additions & 6 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
case $::osfamily {
'Debian': {
$php_package_name = 'php5'
$php_apc_package_name = 'php-apc'
$common_package_name = 'php5-common'
$cli_package_name = 'php5-cli'
$php_apc_package_suffix = '-apc'
$php_conf_dir = '/etc/php5/conf.d'
$fpm_package_name = 'php5-fpm'
$fpm_service_name = 'php5-fpm'
Expand All @@ -18,9 +16,7 @@
}
default: {
$php_package_name = 'php'
$php_apc_package_name = 'php-pecl-apc'
$common_package_name = 'php-common'
$cli_package_name = 'php-cli'
$php_apc_package_suffix = '-pecl-apc'
$php_conf_dir = '/etc/php.d'
$fpm_package_name = 'php-fpm'
$fpm_service_name = 'php-fpm'
Expand All @@ -33,4 +29,7 @@
$httpd_conf_dir = '/etc/httpd/conf.d'
}
}

$common_package_suffix = '-common'
$cli_package_suffix = '-cli'
}
1 change: 1 addition & 0 deletions tests/cli.pp
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include php
php::ini { '/etc/php.ini': }
include php::cli
1 change: 1 addition & 0 deletions tests/fpm/conf.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include php
include php::fpm::daemon
php::fpm::conf { 'www': ensure => absent }
php::fpm::conf { 'customer1':
Expand Down
1 change: 1 addition & 0 deletions tests/fpm/daemon.pp
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include php
include php::fpm::daemon
1 change: 1 addition & 0 deletions tests/mod_php5.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include php
php::ini { '/etc/php-httpd.ini': }
service { 'httpd': }
package { 'httpd': ensure => installed }
Expand Down
1 change: 1 addition & 0 deletions tests/module.pp
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include php
php::module { [ 'ldap', 'mcrypt', 'xml' ]: }

0 comments on commit 403b23c

Please sign in to comment.