From 711c08d5d7ec594d936ae03b9c4d7b5a4940b679 Mon Sep 17 00:00:00 2001 From: mruzicka Date: Fri, 29 Mar 2013 20:15:20 +0100 Subject: [PATCH] use fastcgi as the mechanism to run php from apache on ubuntu --- modules/php5/files/php5-fpm-fcgi.conf | 3 ++ modules/php5/manifests/apache_module.pp | 50 +++++++++++++++++-- .../wordpress/templates/wordpress.conf.erb | 2 +- 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 modules/php5/files/php5-fpm-fcgi.conf diff --git a/modules/php5/files/php5-fpm-fcgi.conf b/modules/php5/files/php5-fpm-fcgi.conf new file mode 100644 index 0000000..a1471b4 --- /dev/null +++ b/modules/php5/files/php5-fpm-fcgi.conf @@ -0,0 +1,3 @@ +Action php5-fcgi /php5-fcgi +Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi +FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization diff --git a/modules/php5/manifests/apache_module.pp b/modules/php5/manifests/apache_module.pp index d424e99..86a9616 100644 --- a/modules/php5/manifests/apache_module.pp +++ b/modules/php5/manifests/apache_module.pp @@ -3,9 +3,9 @@ include apache2 $php = $::operatingsystem ? { - Ubuntu => 'libapache2-mod-php5', + Ubuntu => 'php5-fpm', CentOS => 'php', - Debian => 'libapache2-mod-php5', + Debian => 'php5-fpm', default => 'php', } @@ -16,5 +16,49 @@ notify => Service['apache2-service'], } - Service['apache2-service'] <~ Php5::Plugin<| |> + case $::operatingsystem { + 'debian', 'ubuntu': { + $php_handler = 'php5-fcgi' + + file { '/etc/apache2/mods-enabled/php5-fpm-fcgi.conf': + ensure => present, + source => 'puppet:///modules/php5/php5-fpm-fcgi.conf', + owner => 'root', + group => 'root', + mode => '0644', + require => Package['apache2'], + notify => Service['apache2-service'], + } + + exec { 'add-multiverse-repo': + command => 'perl -ne \'m|^#\s*(deb(?:-src)?\s+http://.*\s+multiverse\n)|s and print $1\' /etc/apt/sources.list > /etc/apt/sources.list.d/multiverse.list; apt-get update', + path => ['/usr/local/bin', '/bin', '/usr/bin'], + creates => '/etc/apt/sources.list.d/multiverse.list', + } -> Package<| |> + + package { 'libapache2-mod-fastcgi': + ensure => latest, + require => Package['apache2'], + notify => Service['apache2-service'], + } + + apache2::module { ['alias', 'actions', 'fastcgi']: + ensure => 'enabled', + } + + service { 'php5-fpm': + ensure => running, + enable => true, + hasrestart => true, + hasstatus => true, + require => Package['php5-apache_module'], + } <~ Php5::Plugin<| |> + } + + default: { + $php_handler = 'php5-script' + + Service['apache2-service'] <~ Php5::Plugin<| |> + } + } } diff --git a/modules/wordpress/templates/wordpress.conf.erb b/modules/wordpress/templates/wordpress.conf.erb index d4261f1..08643d2 100644 --- a/modules/wordpress/templates/wordpress.conf.erb +++ b/modules/wordpress/templates/wordpress.conf.erb @@ -29,7 +29,7 @@ Alias /<%= instance_alias %> "<%= instance_root %>" # # Cause the specified handler to handle files with a .php extension. # - AddHandler php5-script .php + AddHandler <%= scope.lookupvar('::php5::apache_module::php_handler') %> .php AddType text/html .php #