Code Monkey home page Code Monkey logo

puppet-php's Introduction

puppet-php

Overview

Install PHP packages and configure PHP INI files, for using PHP from the CLI, the Apache httpd module or FastCGI.

The module is very Red Hat Enterprise Linux focused, as the defaults try to 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::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
  • php::ini : Definition to create php.ini files
  • php::mod_php5 : Simple class to install PHP's Apache httpd module
  • php::module : Definition to manage separately packaged PHP modules
  • php::module::ini : Definition to manage the ini files of separate modules

Examples

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

php::ini { '/etc/php.ini':
  display_errors => 'On',
  memory_limit   => '256M',
}
php::ini { '/etc/httpd/conf/php.ini':
  mail_add_x_header => 'Off',
  # For the parent directory
  require           => Package['httpd'],
}

Install the latest version of the PHP command line interface in your OS's package manager (e.g. Yum for RHEL):

include '::php::cli'

Install version 5.3.3 of the PHP command line interface :

class { 'php::cli': ensure => '5.3.3' }

Install the PHP Apache httpd module, using its own php configuration file (you will need mod_env in apache for this to work) :

class { 'php::mod_php5': inifile => '/etc/httpd/conf/php.ini' }

Install PHP modules which don't have any configuration :

php::module { [ 'ldap', 'mcrypt' ]: }

Configure PHP modules, which must be installed with php::module first :

php::module { [ 'pecl-apc', 'xml' ]: }
php::module::ini { 'pecl-apc':
  settings => {
    'apc.enabled'      => '1',
    'apc.shm_segments' => '1',
    'apc.shm_size'     => '64',
  }
}
php::module::ini { 'xmlreader': pkgname => 'xml' }
php::module::ini { 'xmlwriter': ensure => 'absent' }

Install PHP FastCGI Process Manager with a single pool to be used with nginx. Note that we reuse the 'www' name to overwrite the example configuration :

include '::php::fpm::daemon'
php::fpm::conf { 'www':
  listen  => '127.0.0.1:9001',
  user    => 'nginx',
  # For the user to exist
  require => Package['nginx'],
}

Then from the nginx configuration :

# PHP FastCGI backend
upstream wwwbackend {
  server 127.0.0.1:9001;
}
# Proxy PHP requests to the FastCGI backend
location ~ \.php$ {
  # Don't bother PHP if the file doesn't exist, return the built in
  # 404 page (this also avoids "No input file specified" error pages)
  if (!-f $request_filename) { return 404; }
  include /etc/nginx/fastcgi.conf;
  fastcgi_pass wwwbackend;
}
# Try to send all non-existing files to the main /index.php
# (typically if you have a PHP framework requiring this)
location @indexphp {
  if (-f $document_root/index.php) { rewrite .* /index.php last; }
}
try_files $uri @indexphp;

puppet-php's People

Contributors

3flex avatar erikwebb avatar forgodssake avatar heskyji avatar jeffsheltren avatar jeroenmoors avatar joshuaspence avatar kronos-pbrideau avatar masonm avatar nickschuch avatar nyholm avatar thias avatar xcompass avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

puppet-php's Issues

error trying downgrade version php-fpm

in centos-6.5-i386

When I try to set specific version of php-fpm for and older one, fail because php-common is already installed in a newer version. even in a fresh installation (I'm using it in vagrant).

this is my class, it works if I don't try force the version number

class appsrv {
    require yum::repo::remi
    require yum::repo::epel
    require yum::repo::remi_php55
    # For the user to exist
    require websrv
    package { 'libtidy':
        ensure  => present,
    }
    package { 'libtidy-devel':
        ensure  => present,
    } 
    package { 'php-tidy':
        ensure  => present,
    }
    package { 'yum-allowdowngrade':
        ensure  => present,
    }
    php::module { [ 'pecl-apcu',
                'pear',
                'pdo',
                'mysqlnd',
                'pgsql',
                'pecl-mongo',
                'pecl-sqlite',
                'mbstring',
                'mcrypt',
                'xml',
                'pecl-memcached',
                'gd',
                'soap']:
                notify  => Service['php-fpm'],
                }

    php::fpm::conf { 'www':
      listen  => '127.0.0.1:9001',
      user    => 'nginx',
      pm_status_path => '/status',
    }~>File['/var/log/php-fpm']

    class { php::fpm::daemon:
        ensure => '5.4.35', 
        log_owner => 'nginx',
        log_group => 'nginx',
        log_dir_mode => '0775',
    }
    php::ini { '/etc/php.ini':
      short_open_tag             => 'On',
      asp_tags                   => 'Off',
      date_timezone             =>'America/Mexico_City',
      error_reporting           => 'E_ALL',
      display_errors            => 'On',
      html_errors               => 'On',
      notify  => Service['php-fpm'],
    }
    file { '/var/log/php-fpm/www-error.log':
      ensure => "file",
      owner  => "nginx",
      group  => "nginx",
      mode   => 664
    }
    file { '/var/log/php-fpm/error.log':
      ensure => "file",
      owner  => "root",
      group  => "nginx",
      mode   => 664,
    }
}

and this is the error (the relevant part only)

Execution of '/usr/bin/yum -d 0 -e 0 -y install php-fpm-5.4.35' returned 1: Error: Package: php-fpm-5.4.35-1.el6.remi.i686 (remi)
           Requires: php-common(x86-32) = 5.4.35-1.el6.remi
           Installed: php-common-5.5.20-2.el6.remi.i686 (@remi-php55)
               php-common(x86-32) = 5.5.20-2.el6.remi
           Available: php-common-5.3.3-38.el6.i686 (base)
               php-common(x86-32) = 5.3.3-38.el6
           Available: php-common-5.3.3-40.el6_6.i686 (updates)
               php-common(x86-32) = 5.3.3-40.el6_6
           Available: php-common-5.4.35-1.el6.remi.i686 (remi)
               php-common(x86-32) = 5.4.35-1.el6.remi
           Available: php-common-5.4.36-1.el6.remi.i686 (remi)
               php-common(x86-32) = 5.4.36-1.el6.remi
           Available: php-common-5.5.19-2.el6.remi.i686 (remi-php55)
               php-common(x86-32) = 5.5.19-2.el6.remi
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

'20-apc.ini' formatted ini files

On debian, the ini files are named as '20-apc.ini' (they have a priority number).

When using your module, files are always created as 'apc.ini' and there is no way to change this.

Example:
php::module::ini { 'apc':
settings => {
'apc.enabled' => '1',
'apc.shm_segments' => '1',
'apc.shm_size' => '128M',
}
}

Produces '/etc/php5/conf.d/apc.ini'. Installing packaging php-apc already produced the file '/etc/php5/conf.d/20-apc.ini' with just the following line: extension=apc.so

Netto effect: 2 files in the config directory and messages such as "PHP Warning: Module 'apc' already loaded in Unknown on line 0" when running the php command.

Proposed solution: allow to specify the output ini filename.

parse error at /manifests/fpm/conf.pp

puppet parser validate puppet-modules/php/manifests/fpm/conf.pp
Error: Could not parse for environment production: Syntax error at '{'; expected '}' at php/manifests/fpm/conf.pp:68

if I comment out:

$fpm_package_name_final = $fpm_package_name {
undef => $::php::params::fpm_package_name,
default => $fpm_package_name,
}

everything is working fine.

probably related to #31

Ubuntu does not read /etc/php.ini

This seems to be awful, cause we setup the php.ini file with some custom value, it creates the file @ /etc/php.ini. but when I run php -i it does not read this file, even when running from apache and php-fpm, so how should I get my custom values to be there when I run phpinfo command ?

So far I have noticed it reads only these php.ini which are at this location.

for cli /etc/php5/cli/php.ini
for apache /etc/php5/apache/php.ini
for fpm /etc/php5/fpm/php.ini

PHP Version => 5.5.9-1ubuntu4.14

System => Linux wordpress 3.13.0-49-generic #81-Ubuntu SMP Tue Mar 24 19:29:48 UTC 2015 x86_64
Build Date => Oct 28 2015 01:31:23
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
Scan this dir for additional .ini files => /etc/php5/cli/conf.d
Additional .ini files parsed => /etc/php5/cli/conf.d/05-opcache.ini,
/etc/php5/cli/conf.d/10-pdo.ini,
/etc/php5/cli/conf.d/20-apcu.ini,
/etc/php5/cli/conf.d/20-curl.ini,
/etc/php5/cli/conf.d/20-gd.ini,
/etc/php5/cli/conf.d/20-intl.ini,
/etc/php5/cli/conf.d/20-json.ini,
/etc/php5/cli/conf.d/20-ldap.ini,
/etc/php5/cli/conf.d/20-memcached.ini,
/etc/php5/cli/conf.d/20-mysql.ini,
/etc/php5/cli/conf.d/20-mysqli.ini,
/etc/php5/cli/conf.d/20-pdo_mysql.ini,
/etc/php5/cli/conf.d/20-readline.ini,
/etc/php5/cli/conf.d/20-ssh2.ini,
/etc/php5/cli/conf.d/20-xmlrpc.ini```

pecl-xdebug requires absolute path to /usr/lib64/php/modules

having this in manifest

php::module { [ 'pecl-xdebug' ]: }
php::module::ini { 'pecl-xdebug':
  zend     => true,
  settings => {
    'xdebug.profiler_output_dir'     => '/tmp/xdebug/',
}

produces the file /etc/php.d/xdebug.ini with content:

; NOTICE : File auto-generated by puppet, do not edit
; Enable xdebug extension module
zend_extension=xdebug.so

; Custom settings
xdebug.profiler_output_dir=/tmp/xdebug/

but with this config xdebug is not working, it's not get loaded

but with this in config file

zend_extension=/usr/lib64/php/modules/xdebug.so

it's working as expected

php::mod_php5 doesn't work with debian conf-available and a2enconf

Debian now seems to use a similar technique for configuration files as it already does for modules and sites: a2enconf allows to enable(speak: symlink) config files residing in /etc/apache2/conf-available/.
So it is not ensured that the directory conf.d exists anymore.
This makes puppet fail:

Error: /Stage[main]/Php::Mod_php5/File[/etc/apache2/conf.d/php.conf]/ensure: change from absent to file failed: Could not set 'file' on ensure: No such file or directory - /etc/apache2/conf.d/php.conf20140617-9548-e4ko7 at 26:/tmp/vagrant-puppet-1/modules-0/php/manifests/mod_php5.pp

A workaround would be to create this directory manually.

Dependency issue

I am getting the following error when trying to use this module to install php5-cli:

/Stage[main]/Php::Ini[/etc/php5/cli/php.ini]/File[/etc/php5/cli/php.ini]/ensure) change from absent to file failed: Could not set 'file on ensure: cannot generate tempfile `/etc/php5/cli/php.ini20150831-7938-1j2ducm-9' at /etc/puppet/ext_modules/php/manifests/ini.pp:117

The puppet code is as follows:

class { '::php::cli':
  ensure  => 'latest',
  inifile => '/etc/php5/cli/php.ini',
}

php::ini { '/etc/php5/cli/php.ini':
  // ...
}

The issue seems to be that Package['php5-cli'] depends on File['/etc/php5/cli/php.ini'], which does not exist before the php5-cli package is installed. I actually think that this dependency should be inverted (i.e. that File['/etc/php5/cli/php.ini'] should depend on Package['php5-cli']).

Module not installed

I have the following configuration:-

  php::ini { '/etc/php.ini':
    display_errors             => 'On',
    memory_limit               => '256M',
    post_max_size              => '15M',
    upload_max_filesize        =>'15M',
    date_timezone              => 'America/Menominee',
  }

  class { '::php::cli': }

  class { 'php::mod_php5': inifile => '/etc/php.ini' }

  php::module { [ 'enchant', 'ldap', 'gd', 'mysql']: }

When I did php -m, the following 4 modules weren't listed, thus not installed:

[PHP Modules]
bz2
calendar
Core
ctype
date
ereg
exif
filter
ftp
gettext
gmp
hash
iconv
libxml
openssl
pcntl
pcre
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
standard
tokenizer
xml
zlib

[Zend Modules]

What should I change to get the modules installed and configured? Thank you.

Hiera / Foreman Support

Good day.

First of all I would like to thank you for creating such good module.
Just a small question.
Do you plan to add hiera / foreman support to this module?
If not please consider this ticket as feature request. :)

Thanks,
Mikhail

uploadprogress extension fails

Hi - Quick question, should I be able to install the pecl-uploadprogress extension with this module? I'm having trouble and just want to know if its something I'm doing wrong. It looks like the module is trying to install "php-pecl-uploadprogress" when it seems like it should just be "pecl-uploadprogress"

Thanks.

error with dots in parameters

Hi,

try setting session.secure_cookie with this:

php::ini { '/etc/php.ini':
session.secure_cookie => '1',
}

gives error about the dot.

Any workaround?

(Duplicated) Ensure /var/log/php-fpm directory exist

Hi, when using ::php::fpm::daemon together with ::php::fpm::conf, it we didn't ensure the /var/log/php-fpm directory, slowlog can't be written into the directory, and therefore php-fpm cannot start.

Puppet log:
Debug: /Stage[main]/Php::Fpm::Daemon/File[/var/log/php-fpm]: Nothing to manage: no ensure and the resource doesn't exist

PHP log:
[10-Mar-2014 09:25:59] ERROR: Unable to create or open slowlog(/var/log/php-fpm/www2-slow.log): No such file or directory (2)

Allow override of php::params

Presently I have had to edit the module to change package names, which should not be needed. Would like the ability to override params.

Using php 5.5

Is there a way to make it download php 5.5 instead of 5.3?

Problem with php5-fpm.sock permissions

I've set-up as another user using the example from the readme:

include php::fpm::daemon
php::fpm::conf { 'www':
  listen  => '127.0.0.1:9001',
  user    => 'nginx',
  # For the user to exist
  require => Package['nginx'],
}

The problem is php5-fpm.sock is still owned by the www-data user. Is something I can change with this module or should I be looking elsewhere?

Can't override params

I'm trying to override params so I can use it with Ubuntu 16.04 (and PHP 7.0), but it keeps looking for php 5 packages. Maybe the use of basedirs is a good idea you don't have to change every path?

php::cli::inifile: /etc/php/7.0/cli/php.ini
php::fpm::daemon::package_name: php7.0-fpm
php::fpm::daemon::service_name: php7.0-fpm
php::fpm::daemon::fpm_pool_dir: /etc/php/7.0/fpm/pool.d
php::fpm::daemon::fpm_conf_dir: /etc/php/7.0/fpm/conf.d
php::params::fpm_package_name:: php7.0-fpm
php::fpm::conf::package_name: php7.0-fpm
php::fpm::conf::service_name: php7.0-fpm
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Invalid relationship: File[/etc/php5/fpm/pool.d/icingaweb2.conf] { require => Package[php5-fpm] }, because Package[php5-fpm] doesn't seem to be in the catalog

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find resource 'Service[php5-fpm]' for relationship from 'File[/etc/php/7.0/cli/php.ini]' on node monitoring

max_input_vars is missing in parameter list

The php in parameter max_input_vars (available since 5.3.9) is missing, causes:
Error: Invalid parameter max_input_vars at

--- ini.pp.orig 2013-12-09 15:36:23.620999946 +0100
+++ ini.pp  2013-12-09 15:36:51.653999946 +0100
@@ -37,6 +37,7 @@
   $expose_php                 = 'On',
   $max_execution_time         = '30',
   $max_input_time             = '60',
+  $max_input_vars        = '1000',
   $memory_limit               = '128M',
   $error_reporting            = 'E_ALL & ~E_DEPRECATED',
   $display_errors             = 'Off',

Issue with service php5-fpm reload on Ubuntu 14.04

Hi,
I have an issue on:

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:    14.04
Codename:   trusty

package:

ii  php5-fpm    5.5.9+dfsg-1ubuntu4.5      amd64    server-side, HTML-embedded scripting language (FPM-CGI binary)

It seems that customize service reload doesn't work correctly, I'd propose to put restart:
https://github.com/thias/puppet-php/blob/master/manifests/fpm/daemon.pp#L34

- restart   => "service ${fpm_service_name} reload",
+ restart   => "service ${fpm_service_name} restart",
root@slave-08:/etc/php5/fpm/pool.d# ps auxwwf |grep php
root     22795  0.0  0.0  10464   920 pts/2    S+   09:51   0:00                          \_ grep --color=auto php
root     21503  0.0  0.7 315644 16232 ?        Ss   09:49   0:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)                    
www-data 21506  0.0  0.6 317748 12328 ?        S    09:49   0:00  \_ php-fpm: pool www                                                       
www-data 21507  0.0  0.6 317748 12328 ?        S    09:49   0:00  \_ php-fpm: pool www                                                       
www-data 21508  0.0  0.7 319548 16192 ?        S    09:49   0:00  \_ php-fpm: pool www                                                       
www-data 21509  0.0  0.7 319548 16040 ?        S    09:49   0:00  \_ php-fpm: pool www                                                       
www-data 21510  0.0  0.9 319812 19176 ?        S    09:49   0:00  \_ php-fpm: pool www                                                       
www-data 21801  0.0  0.5 317748 12184 ?        S    09:50   0:00  \_ php-fpm: pool www                                                       
root@slave-08:/etc/php5/fpm/pool.d# service php5-fpm reload
root@slave-08:/etc/php5/fpm/pool.d# ps auxwwf |grep php
root     22891  0.0  0.0  10464   916 pts/2    S+   09:51   0:00                          \_ grep --color=auto php
www-data 21506  0.0  0.7 319644 15156 ?        S    09:49   0:00 php-fpm: pool www                                                       
www-data 21507  0.0  0.7 319292 15024 ?        S    09:49   0:00 php-fpm: pool www                                                       
www-data 21508  0.0  0.8 319548 16408 ?        S    09:49   0:00 php-fpm: pool www                                                       
www-data 21509  0.0  0.7 319548 16040 ?        S    09:49   0:00 php-fpm: pool www                                                       
www-data 21510  0.0  0.9 319812 19592 ?        S    09:49   0:00 php-fpm: pool www                                                       
www-data 21801  0.0  0.7 319292 15500 ?        S    09:50   0:00 php-fpm: pool www                                            

Thank you

Cannot add a new extension to php.ini

Hi, I want to add this extension 'rdkafka.so' to my php.ini file, Can you please define this in ini.pp file ?
extension=''
and in template file:
extension = <%= extension %>

Could not find dependency File[/etc/php5/cli/php.ini] for Package[php5-cli]

Hi,
I'm running into something unexpected.

I'm using Ubuntu 13.10 and when running the php::cli command it breaks.
The php.ini is not in /etc/php.ini so I gave the 'inifile' for the correct location.

class { 'php::cli':
  inifile => '/etc/php5/cli/php.ini'
}

However it still fails with

Error: Could not find dependency File[/etc/php5/cli/php.ini] for Package[php5-cli] at /tmp/vagrant-puppet-1/modules-0/php/manifests/cli.pp:16

However the file is there:

# ls -lsa /etc/php5/cli/php.ini
68 -rw-r--r-- 1 root root 69593 Dec 11 20:25 /etc/php5/cli/php.ini

Is my lack of knowledge of puppet kicking me here (sorry for that) or did i found a little one :-)

Many thanks in advance,
Wessel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.