jebovic.php

PHP Ansible Role

Build Status Ansible Galaxy

This role installs and configures PHP-FPM for both LAMP and LEMP stacks. It allows you to add your own pool configurations and customize all PHP settings using YAML variables.

Bonus: It includes options for adding Blackfire and New Relic APM extensions.

This role is part of my OPS project. You can follow this link to see it in action. OPS offers various tools like a Vagrant file for development VMs, playbooks for role orchestration, inventory files, and examples for role configurations.

Compatibility

Tested and works on:

  • Debian Jessie (8+)
  • Ubuntu Trusty (14.04 LTS)
  • Ubuntu Xenial (16.04 LTS)

Role Variables

Custom Repository Setup

# Use a custom repository
php_use_custom_repository: yes
php_custom_repositories_key_url: https://www.dotdeb.org/dotdeb.gpg
php_custom_repositories:
  - deb http://packages.dotdeb.org jessie all
  - deb-src http://packages.dotdeb.org jessie all

Packages to Install

# Select which packages to install
php_packages:
  - php7.0-fpm
  - php7.0-cli
  - php7.0-common
  - php7.0-dev
  - php7.0-opcache
  - php7.0-mbstring
  - php7.0-memcached
  - php7.0-mysql
  - php7.0-redis
  - php7.0-curl
  - php7.0-json
  - php7.0-xsl
  - php7.0-xml
  - php7.0-mongodb
  - php7.0-imagick

Define Pools

# Create your own pools
php_pools:
  www:
    user: "www-data"
    group: "www-data"
    listen: "/var/run/php-fpm.sock"
    listen.owner: "www-data"
    listen.group: "www-data"
    listen.allowed_clients: "127.0.0.1"
    pm: "dynamic"
    pm.max_children: "5"
    pm.start_servers: "2"
    pm.min_spare_servers: "1"
    pm.max_spare_servers: "3"
    pm.process_idle_timeout: "30s"
    pm.max_requests: "500"

Custom PHP.ini Configurations

# Custom php.ini settings
php_ini_custom:
  opcache:
    opcache.blacklist_filename: "{{ php_fpm_root_dir }}/fpm/opcache.blacklist"
  newrelic:
    newrelic.enabled: "true"
    newrelic.license: "REPLACE IT WITH YOUR KEY"
    newrelic.logfile: "/var/log/newrelic/php_agent.log"
    newrelic.appname: "{{ ansible_hostname|default('VM Test') }}"
    newrelic.daemon.logfile: "/var/log/newrelic/newrelic-daemon.log"
    newrelic.daemon.port: "/tmp/.newrelic.sock"
    newrelic.daemon.location: "/usr/bin/newrelic-daemon"
    newrelic.daemon.collector_host: "collector.newrelic.com"
    newrelic.analytics_events.enabled: "true"

Basic PHP-FPM Configuration

# Basic FPM settings
php_fpm_root_dir: /etc/php/7.0
php_fpm_daemon: php7.0-fpm
php_fpm_pid: /run/php-fpm.pid
php_fpm_error_log: /var/log/php-fpm.log
php_fpm_syslog_facility: daemon
php_fpm_syslog_ident: php-fpm
php_fpm_log_level: notice
php_fpm_emergency_restart_threshold: 0
php_fpm_emergency_restart_interval: 0
php_fpm_process_control_timeout: 0
php_fpm_process_max: 128
php_fpm_process_priority: -19
php_fpm_daemonize: yes
php_fpm_rlimit_files: 1024
php_fpm_rlimit_core: 0
php_fpm_events_mechanism: epoll
php_fpm_systemd_interval: 10
php_fpm_pools_include: "{{ php_fpm_root_dir }}/fpm/pool.d/*.conf"

Enable Extras

# Enable extensions
php_blackfire_enabled: true
php_composer_enabled: true
php_newrelic_enabled: true

Blackfire Configuration

# Blackfire settings
php_blackfire_daemon: blackfire-agent
php_blackfire_test_mode: false
php_blackfire_key_url: https://packagecloud.io/gpg.key
php_blackfire_package_url: http://packages.blackfire.io/debian
php_blackfire_directory: /etc/blackfire
php_blackfire_packages:
    - blackfire-agent
    - blackfire-php

Composer Configuration

# Composer setup
php_composer_download_url: https://getcomposer.org/installer
php_composer_path: /usr/local/bin/composer
php_composer_version: ''

New Relic APM Configuration

# New Relic settings
php_newrelic_apt_key_url: https://download.newrelic.com/548C16BF.gpg
php_newrelic_apt_url: http://apt.newrelic.com/debian/
php_newrelic_packages:
  - newrelic-php5

Example Playbook

You can include this role in your playbook like this:

- hosts: servers
  roles:
     - { role: jebovic.php }

Example Configuration

Here's another way to define your pool:

# Custom pool example
php_pools:
  my_pool:
    user: "me"
    group: "me"
    listen: "/var/run/php-fpm.sock"
    listen.owner: "www-data"
    listen.group: "www-data"
    listen.allowed_clients: "127.0.0.1"
    pm: "dynamic"
    pm.max_children: "10"
    pm.start_servers: "4"
    pm.min_spare_servers: "2"
    pm.max_spare_servers: "6"
    pm.process_idle_timeout: "300s"
    pm.max_requests: "300"

Tags

  • php_blackfire_config: Configure Blackfire and restart PHP and Blackfire services.
  • php_config: Update configuration and restart service.
  • php_composer: Install Composer.
  • php_blackfire: Install and configure Blackfire service.
  • php_newrelic: Add New Relic APM plugin for PHP.

License

MIT

Author Information

Jérémy Baumgarth - GitHub Profile

Informazioni sul progetto

Install and configure php-fpm for lamp and lemp stack, add your own pools configurations, and customize all the php.ini config from yaml variables, also included: composer, newrelic apm, blackfire apm

Installa
ansible-galaxy install jebovic.php
Licenza
mit
Download
591
Proprietario