Puppet module to manage PHP

Related tags

Testing puppet-php
Overview

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;
Comments
  • Fixed bug with the process priority

    Fixed bug with the process priority

    I've created this PR as a follow up after #25. There was a problem when PR #25 was manually merged. The setting $process_priority should be a setting for each PHP-FPM pool. Not the daemon.

    Consider using Githubs merge function to avoid these kind of errors in the future.

    opened by Nyholm 6
  • notify fpm service if an .ini file changed or php module installed

    notify fpm service if an .ini file changed or php module installed

    notify the fpm service => reload if there are changes to:

    • php.ini's
    • modules (installed, removed)
    • modules .ini files

    for example if you install the module "ldap" - this will now results in:

    Notice: /Stage[main]/Website::Typo3/Php::Module[ldap]/Package[php5-ldap]/ensure: ensure changed 'purged' to 'present' Info: /Package[php5-ldap]: Scheduling refresh of Service[php5-fpm]

    and the module is immediately loaded - otherwise you have to reload the fpm deamon manually (nobody wants that..)

    opened by khaefeli 4
  • Allow override of fpm package name

    Allow override of fpm package name

    This matches my other recent pull requests to allow overriding the php-fpm package name with parameters. This adds options for specifying package name to both php::fpm::daemon and php::fpm:conf

    opened by jeffsheltren 4
  • uploadprogress extension fails

    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.

    opened by richardbporter 4
  • Added process.priority

    Added process.priority

    You may now set a priority on a pool. With this feature you may have one low priority pool for background processes and a other pool with normal priority for your webpage visitors.

    Here is a link to that feature request: https://bugs.php.net/bug.php?id=62160

    This was added in PHP 5.4.4 if I'm not mistaken.

    opened by Nyholm 3
  • Update module::ini to allow specifying RPM pkgname directly

    Update module::ini to allow specifying RPM pkgname directly

    This changes the logic in module::ini so that calling classes can specify a package name directly without having to worry about what $phhp_package_name might be. This gives the ability to use this module for e.g. php53u from IUS without having to manually override params.pp.

    I understand this isn't ideal as it changes functionality slightly, but I think it's worth it to make it a bit more flexible.

    opened by jeffsheltren 3
  • Parameterize classes

    Parameterize classes

    I did some work to better parameterize the classes so that the class parameters can be more easily overridden using Hiera. Are you open to something like this? I'd prefer not to maintain my own fork.

    I don't have a Debian box handy, so I left a couple of the parameter defaults as 'TODO' -- that'll need to be corrected.

    I made a couple other changes while I was at it, so if you would prefer me to split those out into separate PRs, I'm happy to do so. Specifically:

    • Added an option to manage the httpd php.conf file or not -- default in params.pp is true so that the default behavior doesn't change.
    • Added an option to not automatically restart apache for php.ini changes. Again, this defaults to true (will restart apache), so that the default behavior doesn't change.
    opened by jeffsheltren 3
  • Changed always_populate_raw_post_data to Off which is the default from p...

    Changed always_populate_raw_post_data to Off which is the default from p...

    The default value of 'always_populate_raw_post_data' is "0" (off) according to http://php.net/manual/en/ini.list.php. I adjusted the template to show the value as the default (Off) rather than On.

    opened by bschonec 2
  • Issue with service php5-fpm reload on Ubuntu 14.04

    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

    opened by SergK 2
  • Problem with php5-fpm.sock permissions

    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?

    opened by nomasprime 2
  • Added in support for php-memcache in a similar way php-apc is supported.

    Added in support for php-memcache in a similar way php-apc is supported.

    When attempting to install the memcache and memcached PHP modules through the puppet-php module, the naming differs just enough that they cannot be located. This patch aims to provide support for php memcache(d) in the same way that apc is supported.

    opened by typhonius 2
  • Added pcre_jit parameter

    Added pcre_jit parameter

    Added pcre_jit parameter.

    PCRE Whether PCRE's just-in-time compilation is going to be used. Available since PHP 7.0.0., default value "1"

    Source: https://www.php.net/manual/en/pcre.configuration.php#ini.pcre.jit

    opened by carbrich 1
  • Cannot add a new extension to php.ini

    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 %>

    opened by Harsh1-1 0
  • Systemd on-demand socket-based activation

    Systemd on-demand socket-based activation

    Provides support for creating systemd socket-based activation of on-demand PHP-FPM daemons.

    Defines php::fpm::systemd-socket-conf that will create the corresponding systemd .socket and .service configurations. Multiple pools may be created using separate sockets/services so that rolling, zero-downtime restarts of PHP-FPM may be accomplished.

    Tested on CentOS7 and Debian Jessie.

    Based heavily on http://thanatos.be/2014/04/12/php-fpm-ondemand.html

    opened by gchaix 0
  • Can't override params

    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
    
    opened by dsbaars 0
Owner
Matthias Saou
What, Me Worry?
Matthias Saou
PHP client for Selenium/WebDriver protocol. Previously facebook/php-webdriver

Php-webdriver library is PHP language binding for Selenium WebDriver, which allows you to control web browsers from PHP.

php-webdriver 4.7k Jan 3, 2023
The modern, simple and intuitive PHP unit testing framework.

atoum PHP version atoum version 5.3 -> 5.6 1.x -> 3.x 7.2 -> 8.x 4.x (current) A simple, modern and intuitive unit testing framework for PHP! Just lik

atoum 1.4k Nov 29, 2022
Full-stack testing PHP framework

Codeception Modern PHP Testing for everyone Codeception is a modern full-stack testing framework for PHP. Inspired by BDD, it provides an absolutely n

Codeception Testing Framework 4.6k Jan 7, 2023
Faker is a PHP library that generates fake data for you

Faker Faker is a PHP library that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in

FakerPHP 2.7k Dec 27, 2022
Mock HTTP requests on the server side in your PHP unit tests

HTTP Mock for PHP Mock HTTP requests on the server side in your PHP unit tests. HTTP Mock for PHP mocks the server side of an HTTP request to allow in

InterNations GmbH 386 Dec 27, 2022
AST based PHP Mutation Testing Framework

Infection - Mutation Testing framework Please read documentation here: infection.github.io Twitter: @infection_php Discord: https://discord.gg/ZUmyHTJ

Infection - Mutation Testing Framework for PHP 1.8k Jan 2, 2023
:heavy_check_mark: PHP Test Framework for Freedom, Truth, and Justice

Kahlan is a full-featured Unit & BDD test framework a la RSpec/JSpec which uses a describe-it syntax and moves testing in PHP one step forward. Kahlan

Kahlan 1.1k Jan 2, 2023
Event driven BDD test framework for PHP

The highly extensible, highly enjoyable, PHP testing framework. Read more at peridot-php.github.io or head over to the wiki. Building PHAR Peridot's p

Peridot 327 Jan 5, 2023
PHP Mocking Framework

Phake Phake is a framework for PHP that aims to provide mock objects, test doubles and method stubs. Phake was inspired by a lack of flexibility and e

Phake 469 Dec 2, 2022
BDD test framework for PHP

BDD test framework for PHP, inspired by Jasmine and RSpec. Features a familiar syntax, and a watch command to automatically re-run specs during develo

Daniel St. Jules 286 Nov 12, 2022
Mock built-in PHP functions (e.g. time(), exec() or rand())

PHP-Mock: mocking built-in PHP functions PHP-Mock is a testing library which mocks non deterministic built-in PHP functions like time() or rand(). Thi

null 331 Jan 3, 2023
A MySQL engine written in pure PHP

PHP MySQL Engine PHP MySQL Engine is a library for PHP that allows you to test database-driven applications with an in-memory simulation of MySQL 5.6.

Vimeo 529 Jan 4, 2023
SpecBDD Framework for PHP

phpspec The main website with documentation is at http://www.phpspec.net. Installing Dependencies Dependencies are handled via composer: wget -nc http

PHPSpec Framework 1.8k Dec 30, 2022
The PHP Unit Testing framework.

PHPUnit PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks. Installat

Sebastian Bergmann 18.8k Jan 4, 2023
Highly opinionated mocking framework for PHP 5.3+

Prophecy Prophecy is a highly opinionated yet very powerful and flexible PHP object mocking framework. Though initially it was created to fulfil phpsp

PHPSpec Framework 8.5k Jan 3, 2023
PHP unit testing framework with built in mocks and stubs. Runs in the browser, or via the command line.

Enhance PHP A unit testing framework with mocks and stubs. Built for PHP, in PHP! Quick Start: Just add EnhanceTestFramework.php and you are ready to

Enhance PHP 67 Sep 12, 2022
Library that provides collection, processing, and rendering functionality for PHP code coverage information.

phpunit/php-code-coverage Provides collection, processing, and rendering functionality for PHP code coverage information. Installation You can add thi

Sebastian Bergmann 8.5k Jan 5, 2023
A PHP library for mocking date and time in tests

ClockMock Slope s.r.l. ClockMock provides a way for mocking the current timestamp used by PHP for \DateTime(Immutable) objects and date/time related f

Slope 44 Dec 7, 2022