example42 / puppet-php

A puppet module for php. According to Example42 NextGen spec.
Other
45 stars 62 forks source link

PHP5-FPM conf and Nginx vhost bug #62

Closed shivapoudel closed 9 years ago

shivapoudel commented 10 years ago

I am using netmanagers/puppet-nginx and example42/puppet-php for vagrant machine. I have installed the php module like this:

group { 'puppet': ensure => present }

Exec { path => [ '/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/' ] }
File { owner => 0, group => 0, mode => 0644 }

class { 'apt':
    always_apt_update => true,
}

Class['::apt::update'] -> Package <|
    title != 'python-software-properties'
    and title != 'software-properties-common'
|>

# Package Configurations.
$sysPackages = ['vim', 'ntp']
package { $sysPackages:
    ensure => 'installed',
}

# Apache Web-Server Configurations.
class { 'apache':
  disable => true
}

# Nginx Web-Server Configurations.
class { 'nginx':
    worker_connections      => 4096,
    keepalive_timeout       => 120,
    client_max_body_size    => '1024m',
    types_hash_max_size     => '2048',
}

nginx::resource::vhost { 'axisthemes.dev' :
    fastcgi => present,
    www_root => '/var/www/axisthemes',
}

# PHP Module Configurations.
class { 'php':
    service => 'nginx',
}

class { 'php::devel':
    require => Class['php'],
}

$phpModules = ['fpm', 'gd', 'imagick', 'mysql', 'cli', 'common', 'curl', 'intl', 'mcrypt', 'cgi', 'memcache']
php::module { $phpModules: }

$peclModules = ['xdebug']
php::pecl::module { $peclModules: }

I want to use the default fastcgi template and won't prefer to build my own. So the problem is that I receive 502 Bad Gateway. I figure out that the /etc/php5/fpm/pool.d/www.conf has this kind of setting:

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php5-fpm.sock ### Note-1: we have to deal with this line.

But puppet-nginx will generate this kind of setting:

  location ~ \.php$ {
    try_files $uri =404;

    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    ### Note-2: this line won't match Note-1.
    fastcgi_pass  unix:/var/run/php5-fpm-www-data.sock; 

    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO        $fastcgi_script_name;
    include fastcgi_params;
  }

This above is generated from puppet-nginx/templates/vhost/vhost_fastcgi.erb:

  location ~ \.php$ {
    try_files $uri =404;

    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_pass  unix:/var/run/php5-fpm-<%= @real_owner %>.sock;

    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO        $fastcgi_script_name;
    include fastcgi_params;
  }

So the solution to get rid of 502 Bad Gateway is inject <%= @real_owner %> in /etc/php5/fpm/pool.d/www.conf like this:

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php5-fpm-<%= @real_owner %>.sock ### Note-1: This is the solution how to achieve this kind of settings.