Giter VIP home page Giter VIP logo

ansible-php-fpm's Introduction

Build Status Ansible Galaxy

php-fpm

This role installs and configures the php-fpm interpreter.

Attention

RedHat support is discontinued in version 2.0.0. Pull requests are welcome.

Requirements

This role requires Ansible 1.4 or higher and tested platforms are listed in the metadata file.

Role Variables

The role uses the following variables:

  • php_fpm_version: PHP version which should be installed. Available: 5.5, 5.6, 7.0, 7.1. Default: 5.6. Attention: PHP 5.5 can be used, but it has reached it's end of life and should be avoided!
  • php_fpm_pools: The list a pools for php-fpm, each pools is a hash with a name entry (used for filename), all the other entries in the hash are pool directives (see http://php.net/manual/en/install.fpm.configuration.php). One level dictionaries nesting is supported, to allow passing environment variables and PHP settings as dictionaries.
  • php_fpm_pool_defaults: A list of default directives used for all php-fpm pools (see http://php.net/manual/en/install.fpm.configuration.php).
  • php_fpm_apt_packages: The list of packages to be installed by the apt module, defaults to [php5-fpm]. module.
  • php_fpm_yum_packages: The list of packages to be installed by the yum module, defaults to [php-fpm].
  • php_fpm_ini: Customization for php-fpm's php.ini as a list of options, each option is a hash using the following structure:
    • option: The name of the option.
    • value: The string value to be associated with the option.
    • section: Section name in INI file.
  • php_fpm_config: Customization for php-fpm's configuration file as a list of options.
  • php_fpm_default_pool:
    • delete: Set to a True value to delete the default pool.
    • name: The filename the default pool configuration file.
  • php_fpm_apt_latest: If set to yes will update the packages to the latest version

Example configuration

- role: php-fpm
  php_fpm_pool_defaults:
    pm: dynamic
    pm.max_children: 5
    pm.start_servers: 2
    pm.min_spare_servers: 1
    pm.max_spare_servers: 3
  php_fpm_pools:
   - name: foo
     user: www-data
     group: www-data
     listen: 8000
     chdir: /
   - name: bar
     user: www-data
     group: www-data
     # Add the host and port in separate variables.
     listen_host: 127.0.0.1
     # Attention: One of listen_port or listen is required!
     listen_port: 8001
     env:
       PATH: "/usr/local/bin:/usr/bin:/bin"
       TMPDIR: "/tmp"
     php_admin_value:
       sendmail_path: "/usr/sbin/sendmail -t -i -f [email protected]"
       error_log: "/var/log/fpm-bar.www.log"
   php_fpm_ini:
   # PHP section directives
   - option: "engine"
     section: "PHP"
     value: "1"
   - option: "error_reporting"
     section: "PHP"
     value: "E_ALL & ~E_DEPRECATED & ~E_STRICT"
   - option: "date.timezone"
     section: "PHP"
     value: "Europe/Berlin"
   # soap section directives
   - option: "soap.wsdl_cache_dir"
     section: "soap"
     value: "/tmp"
   # Pdo_mysql section directives
   - option: "pdo_mysql.cache_size"
     section: "Pdo_mysql"
     value: "2000"
   php_fpm_config:
   - option: "log_level"
     section: "global"
     value: "notice"
   - option: "syslog.facility"
     section: "global"
     value: "daemon"

Example usage

---
# file: task.yml
- hosts: all
  roles:
    - nbz4live.php-fpm
    - {
        role: nbz4live.php-fpm,
        php_fpm_pools:[
          {name: foo, user: www-data, group: www-data, listen: 8000, chdir: /}
        ]
      }
    - role: php-fpm
        php_fpm_pools:
          - name: bar
            user: www-data
            group: www-data
            listen: 9000
            chdir: /

Attention

The process manager configuration (pm, pm.max_children, pm.start_servers, pm.min_spare_servers, pm.max_spare_servers), in the defaults, is only for testing. This values should always be calculated based on the used server resources (hardware, number of pools, other software on the server). Please read the documentation for more information about this directives or follow this guide to calculate best values for your case.

License

BSD

Author Information

ansible-php-fpm's People

Contributors

bitdeli-chef avatar dannydorfel avatar nbz4live avatar pbuyle avatar ricbra avatar sunsongxp avatar till avatar vkill 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-php-fpm's Issues

debian apt_repository not using the right repo ?

Hello,

I had an error while executing the install task for debian jessie.

It works when I use

- name: Add DEB repository (Debian)
  apt_repository: repo='deb https://packages.sury.org/php/ jessie main' state=present filename='ondrej'

instead of stable main .

We also have to get the repo key, as mentioned in the README file : https://packages.sury.org/php/README.txt

is it an issue or do I miss something ?

thanks

Broken default pm settings

This role cannot be installed with default settings on servers with 1 virtual CPU.
regression in wiredcraft-ops@617b52b where

  • pm.max_children is set based on server vcpus
  • pm.max_spare_servers is kept 3

thus when vcpu = 1, max_children is 2, but max_spare is 3
logically PHP FPM does not allow setting max_spare > max_children

either wiredcraft-ops@617b52b should be reverted or default max_spare should be set to 2

@NBZ4live what do you prefer?

Can't apply custom config

Hi,

I'm trying to deploy PHP-FPM custom configuration, however it only deploy the default one. I'd like to override it with custom setting like this:

- name: web
  hosts: web
  user: root
  roles:
    - role: nbz4live.php-fpm
      php_fpm_pools:
        - name: www
          user: www-data
          group: www-data
          listen: "{{fpm_sock_path}}"
          listen.mode: 0660
          pm: dynamic
          pm.max_children: 75
          pm.start_servers: 10
          pm.min_spare_servers: 5
          pm.max_spare_servers: 30
          pm.max_requests: 500
          pm.status_path: /fpm_status
          chdir: /
          slowlog: /var/log/php5-fpm.log.slow
          request_slowlog_timeout: 1s
      php_fpm_ini:
        - option: "date.timezone"
          section: "PHP"
          value: "{{timezone}}"
      php_fpm_default_pool:
        delete: yes
        name: www.conf

However, it's always the default configuration which is called. Here is what I got:

 vagrant provision web1
==> web1: Running provisioner: ansible...

PLAY [web] ******************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [web1]

TASK: [nbz4live.php-fpm | Install the php packages] *************************** 
ok: [web1] => (item=php5-cli,php5-fpm)

TASK: [nbz4live.php-fpm | Copy the PHP configuration file] ******************** 
ok: [web1] => (item={'section': 'PHP', 'option': 'engine', 'value': '1'})
ok: [web1] => (item={'section': 'PHP', 'option': 'error_reporting', 'value': 'E_ALL & ~E_DEPRECATED & ~E_STRICT'})
ok: [web1] => (item={'section': 'ldap', 'option': 'ldap.max_links', 'value': '1'})

TASK: [nbz4live.php-fpm | Copy the FPM configuration file] ******************** 
ok: [web1] => (item={'section': 'global', 'option': 'error_log', 'value': '/var/log/php5-fpm.log'})

TASK: [nbz4live.php-fpm | Delete the default POOL configuration file] ********* 
ok: [web1]

TASK: [nbz4live.php-fpm | Copy the POOL configurations] *********************** 
ok: [web1] => (item={'pool': {'name': 'foo', 'vars': ['user = www-data', 'group = www-data', 'listen = 8000', 'pm = dynamic', 'pm.max_children = 5', 'pm.start_servers = 2', 'pm.min_spare_servers = 1', 'pm.max_spare_servers = 3', 'chdir = /']}})

TASK: [nbz4live.php-fpm | Check php-fpm syntax of configuration files] ******** 
ok: [web1]

TASK: [nbz4live.php-fpm | Start the php5-fpm service] ************************* 
ok: [web1]

PLAY RECAP ******************************************************************** 
web1                       : ok=8    changed=0    unreachable=0    failed=0   

The foo pool configuration is deployed, but not my www one. I tried to change www name without success.

Any idea on what I missed ?

Thanks

include must be the last line in php-fpm.conf

If it isn't, everything after it will be parsed as part of what is above it.

That's bad design in php-fpm, but in the meantime this breaks the php-fpm.conf check every time something is added to it that wasn't present before the include.

Here's an ugly but working workaround:

- name: Copy the FPM configuration file
  ini_file: dest={{ php_fpm_conf }} section="{{ item.section }}" option="{{ item.option }}" value="{{ item.value }}" backup=yes
  with_items: fpm_config
  tags: [configuration,php,fpm]

- name: Delete the include line from the ini file
  ini_file: dest={{ php_fpm_conf }} section=global option=include backup=no state=absent
  with_items: fpm_config
  tags: [configuration,php,fpm]

- name: Readd the include line from the ini file
  ini_file: dest={{ php_fpm_conf }} section=global option=include backup=no state=present value="/etc/php5/fpm/pool.d/*"
  with_items: fpm_config
  notify: 
   - restart php-fpm
  tags: [configuration,php,fpm]

Bug with Python 3

In file templates/pool.conf.j2,
the line {% for directive, value in ((php_fpm_pool_defaults|default(dict())).items() + item.items()) if directive != "name" %} is invalid: dict().items() is not a list anymore, it's an iterator.

Maybe you should replace it by something like {% for directive, value in ((php_fpm_pool_defaults|default(dict()).items()|list) + (item.items()|list)) if directive != "name" %}

New release?

Seems you've changed a number of things since the version that's on Galaxy, so maybe updating the release on Galaxy would be good. The documentation on the repo doesn't match what's on Galaxy at the moment, which is a bit disorienting.

Role doesn't work out-of-the-box on Ubuntu 16.04 (php7)

This is due to the default php_fpm_apt_packages specifying php5-fpm, which is not available on the later versions of Ubuntu. The packages are now available as php-fpm, which then includes php7 dependencies. The same (the 5 is dropped) applies to other packages such as php-cli.

There are a variety of changes required to accommodate php7 - several paths have changed too. It may make sense to add a var to specify whether v5 or v7 should be installed.

Error installing php packages

I have an error: failed: [findyourdressnew] (item=[u'php_fpm_apt_packages']) => {"failed": true, "item": ["php_fpm_apt_packages"], "msg": "No package matching 'php_fpm_apt_packages' is available"}

My playbook for this role:

    - role: nbz4live.php-fpm
      php_fpm_apt_packages:
        - php5-fpm
        - php5-cli
        - php5-imagick
        - php5-memcached
        - php5-gd
        - php5-intl
        - php5-mysql
        - php5-curl
        - php-apc
        - php5-dev
        - php-pear

Create a new release

Thank you for creating this open source library. There have been some merges (#35) which are not available in the latest tag. Could you create a new tag?

How to apply multiple Pools with different PHP-Versions to different servers?

We have about 200 Servers and some should have multiple PHP-versions for different webspaces.

That should be implemented in a Role. How can i do that?

I thought about this structure in the host_vars

webspaces:
  - name: web1
    password: "{{ vault_ssh_web1_password }}"
    php: 5.6
    php_ini:
      - 'memory_limit: 128M'
  - name: web2
    password: "{{ vault_ssh_web2_password }}"
    php: 7.0

and this in the Role webspace

- name: create PHP 7.0 FPM Pools
  debug: msg="{{ item.name }}"
  when: "item.php == 7.0"
  with_items: "{{ webspaces }}"

- name: create PHP 5.6 FPM Pools
  debug: msg="{{ item.name }}"
  when: "item.php == 5.6"
  with_items: "{{ webspaces }}"

but you can't use with_items with roles (ansible/ansible#12623 (comment))

New release

Hey
Thank you for your role
Can you make a new release after the merge of #12 ?

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.