24 Commits
2.0 ... freebsd

Author SHA1 Message Date
Emilien Mantel
4611a5a795 Merge branch 'master' into freebsd 2018-03-18 21:47:24 +01:00
Emilien Mantel
9e59ba5b47 Fix vagrantfile for FreeBSD 2018-03-18 21:46:47 +01:00
Emilien Mantel
9aa0f76c03 Support FreeBSD 11/12 2018-03-18 21:29:47 +01:00
Emilien Mantel
e87d158424 Manage Ubuntu 16.04/18.04 2018-03-18 19:30:21 +01:00
Emilien Mantel
5878040e84 Mass cleanup and drop jessie support 2018-03-18 17:28:57 +01:00
Emilien Mantel
8e53b9cd80 Donation 2017-12-09 17:06:41 +01:00
Emilien Mantel
cbceba6897 We can't uninstall xdebug, so disabling it! 2017-11-28 09:17:19 +01:00
Emilien Mantel
d836862837 Uninstall xdebug 2017-11-28 08:31:28 +01:00
Emilien Mantel
df8b58b46a Manages status/ping path in FPM pools 2017-11-22 17:02:51 +01:00
Emilien Mantel
de41097cde Vagrant: sudo -> become 2017-11-22 17:00:20 +01:00
Emilien Mantel
71721d1afc Sury manages now PHP 7.2 (rc5) 2017-11-10 12:28:13 +01:00
Emilien Mantel
3d7c68e700 Optimize ini configuration 2017-11-10 12:19:39 +01:00
Emilien Mantel
6d4a7e1a08 Remove invalid ansible tags 2017-06-19 17:31:41 +02:00
Emilien Mantel
f8ddae5064 Check managed php version by OS - Fixes #9 2017-06-14 17:35:51 +02:00
Emilien Mantel
f38aa400b3 Load default PHP version per OS release 2017-06-13 11:51:51 +02:00
Emilien Mantel
8758a9b7dc Fix long term idempotence: fpm pkg present state 2017-06-09 09:28:16 +02:00
E Mantel
2a6b921b5e Update README
Add doc/links about extra PHP version
2017-06-06 16:31:19 +02:00
Emilien Mantel
1bce22acbd Travis CI with vagrant + docker 2017-06-06 16:27:11 +02:00
Emilien Mantel
7f7087cdb2 Ignore warning on test.yml 2017-03-16 18:31:16 +01:00
Emilien Mantel
2987051153 Manages PHP 7.1 2017-03-16 18:23:39 +01:00
Emilien Mantel
7727e19da9 Restart PHP-FPM when new packages are installed 2017-03-16 16:10:18 +01:00
Emilien Mantel
bc501c9e25 ansible_managed breaks priority on phpdismod 2016-12-12 12:17:47 +01:00
Emilien Mantel
9111165a7c APT change status update:
- updating cache is not a change
- packages are 'present' (was latest) state
2016-12-08 17:38:10 +01:00
Emilien Mantel
ef9242f2fb Fix mods-available directory for PHP7 2016-08-25 18:09:33 +02:00
36 changed files with 514 additions and 227 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
.vagrant* .vagrant*
*.swp *.swp
*.retry *.retry
*.log

View File

@@ -1,16 +1,45 @@
env: env:
- PLATFORM=debian-jessie-php-5.6 - PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.0,<2.1'
- PLATFORM=debian-jessie-php-7.0 - PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.0,<2.1'
- PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.1,<2.2'
- PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.1,<2.2'
- PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.2,<2.3'
- PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.2,<2.3'
- PLATFORM='docker-debian-stretch-php70' ANSIBLE_VERSION='ansible>=2.3,<2.4'
- PLATFORM='docker-debian-stretch-php71' ANSIBLE_VERSION='ansible>=2.3,<2.4'
- PLATFORM='docker-ubuntu-xenial-php70' ANSIBLE_VERSION='ansible>=2.0,<2.1'
- PLATFORM='docker-ubuntu-xenial-php70' ANSIBLE_VERSION='ansible>=2.1,<2.2'
- PLATFORM='docker-ubuntu-xenial-php70' ANSIBLE_VERSION='ansible>=2.2,<2.3'
- PLATFORM='docker-ubuntu-xenial-php70' ANSIBLE_VERSION='ansible>=2.3,<2.4'
- PLATFORM='docker-ubuntu-bionic-php72' ANSIBLE_VERSION='ansible>=2.0,<2.1'
- PLATFORM='docker-ubuntu-bionic-php72' ANSIBLE_VERSION='ansible>=2.1,<2.2'
- PLATFORM='docker-ubuntu-bionic-php72' ANSIBLE_VERSION='ansible>=2.2,<2.3'
- PLATFORM='docker-ubuntu-bionic-php72' ANSIBLE_VERSION='ansible>=2.3,<2.4'
sudo: required sudo: required
dist: trusty
language: python language: python
services: services:
- docker - docker
before_install:
- wget https://releases.hashicorp.com/vagrant/2.0.1/vagrant_2.0.1_x86_64.deb
- sudo dpkg -i vagrant_2.0.1_x86_64.deb
install:
- pip install "$ANSIBLE_VERSION"
script: script:
- docker build -f tests/$PLATFORM.Dockerfile -t test-$PLATFORM . && docker run --name $PLATFORM test-$PLATFORM - VAGRANT_DEFAULT_PROVIDER=docker vagrant up $PLATFORM
- >
VAGRANT_DEFAULT_PROVIDER=docker vagrant provision $PLATFORM
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
- VAGRANT_DEFAULT_PROVIDER=docker vagrant status
notifications: notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/ webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@@ -1,17 +1,37 @@
Ansible PHP (+FPM) role for Debian Ansible PHP (+FPM) role for Debian / Ubuntu / FreeBSD
================================== =====================================================
[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.php-blue.svg)](https://galaxy.ansible.com/HanXHX/php) [![Build Status](https://travis-ci.org/HanXHX/ansible-php.svg?branch=master)](https://travis-ci.org/HanXHX/ansible-php) [![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.php-blue.svg)](https://galaxy.ansible.com/HanXHX/php) [![Build Status](https://travis-ci.org/HanXHX/ansible-php.svg?branch=master)](https://travis-ci.org/HanXHX/ansible-php)
Install PHP (php-fpm optional) on Debian Jessie/Stretch. Manage APCu, Opcache, Xdebug. Install PHP (php-fpm optional) on Debian / Ubuntu. Manage APCu, Opcache, Xdebug.
Managed versions: 5.6 and 7.0 Managed OS / Versions
---------------------
| OS | PHP 7.0 | PHP 7.1 | PHP 7.2 |
|:---------------------:|:------------:|:-------------:|:------------:|
| Debian Strech (9) | Yes | Yes (Sury) | Yes (Sury) |
| Ubuntu Xenial (16.04) | Yes | No | No |
| Ubuntu Bionic (18.04) | No | No | Yes |
| FreeBSD 11 | Yes | Yes | Yes |
| FreeBSD 12 | Yes | Yes | Yes |
Links:
- [Dotdeb](https://www.dotdeb.org)
- [Sury](https://deb.sury.org/)
Requirements Requirements
------------ ------------
If you need PHP-FPM, you must install a webserver with FastCGI support. You can use my [nginx role](https://github.com/HanXHX/ansible-nginx). If you need PHP-FPM, you must install a webserver with FastCGI support. You can use my [nginx role](https://github.com/HanXHX/ansible-nginx).
On Debian Jessie, if you want PHP7.0, you must use [Dotdeb](https://www.dotdeb.org). You can use my [dotdeb role](https://github.com/HanXHX/ansible-debian-dotdeb).
FreeBSD limitations
-------------------
- It doesn't split ini file for FPM/CLI. It's hardcoded as `/usr/local/etc/php.ini`.
- It can't manage multiple PHP versions at the time (like old Debian versions)
- You must explicitely set xdebug package name (use `pkg search xdebug` to find the good one)
Role Variables Role Variables
-------------- --------------
@@ -20,7 +40,7 @@ You should look at [default vars](defaults/main.yml).
### Writable vars ### Writable vars
- `php_version`: 5.6 (default) or 7.0 - `php_version`: 7.0, 7.1, 7.2
- `php_install_fpm`: boolean, install and manage php-fpm (default is true) - `php_install_fpm`: boolean, install and manage php-fpm (default is true)
- `php_install_xdebug`: boolean, install [Xdebug](http://xdebug.org) - `php_install_xdebug`: boolean, install [Xdebug](http://xdebug.org)
- `php_extra_packages`: additional php packages to install (default is an empty list). - `php_extra_packages`: additional php packages to install (default is an empty list).
@@ -142,20 +162,31 @@ Example Playbook
roles: roles:
- { role: HanXHX.php } - { role: HanXHX.php }
### Debian Jessie with PHP 7.0 CLI (no FPM) ### Debian Stretch with PHP 7.2 CLI (no FPM)
- hosts: jessie-servers - hosts: servers
roles: roles:
- { role: HanXHX.dotdeb } - { role: HanXHX.sury }
- { role: HanXHX.php, php_version: '7.0', php_install_fpm: false } - { role: HanXHX.php, php_version: '7.2', php_install_fpm: false }
License License
------- -------
GPLv2 GPLv2
Donation
--------
If this code helped you, or if youve used them for your projects, feel free to buy me some :beers:
- Bitcoin: `1BQwhBeszzWbUTyK4aUyq3SRg7rBSHcEQn`
- Ethereum: `0x63abe6b2648fd892816d87a31e3d9d4365a737b5`
- Litecoin: `LeNDw34zQLX84VvhCGADNvHMEgb5QyFXyD`
- Monero: `45wbf7VdQAZS5EWUrPhen7Wo4hy7Pa7c7ZBdaWQSRowtd3CZ5vpVw5nTPphTuqVQrnYZC72FXDYyfP31uJmfSQ6qRXFy3bQ`
No crypto-currency? :star: the project is also a way of saying thank you! :sunglasses:
Author Information Author Information
------------------ ------------------
- Twitter: [@hanxhx_](https://twitter.com/hanxhx_) - Twitter: [@hanxhx_](https://twitter.com/hanxhx_)
- All issues, pull-requests are welcome :)

84
Vagrantfile vendored
View File

@@ -5,31 +5,79 @@
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
vms = [ vms_debian = [
[ "jessie-php-5.6", "debian/contrib-jessie64", "192.168.33.88", "5.6" ], { :name => "debian-stretch-php70", :box => "debian/stretch64", :vars => { }},
[ "jessie-php-7.0", "debian/contrib-jessie64", "192.168.33.89", "7.0" ], { :name => "debian-stretch-php71", :box => "debian/stretch64", :vars => { "php_version": '7.1' }},
[ "stretch-php-5.6", "sharlak/debian_stretch_64", "192.168.33.90", "5.6" ], { :name => "debian-stretch-php72", :box => "debian/stretch64", :vars => { "php_version": '7.2' }},
[ "stretch-php-7.0", "sharlak/debian_stretch_64", "192.168.33.91", "7.0" ] { :name => "ubuntu-xenial-php70", :box => "ubuntu/xenial64", :vars => { }},
{ :name => "ubuntu-bionic-php72", :box => "ubuntu/bionic64", :vars => { }},
] ]
config.vm.provider "virtualbox" do |v| vms_freebsd = [
v.cpus = 1 { :name => "freebsd-11", :box => "freebsd/FreeBSD-11.1-STABLE", :vars => {} },
v.memory = 256 { :name => "freebsd-12", :box => "freebsd/FreeBSD-12.0-CURRENT", :vars => {} }
]
conts = [
{ :name => "docker-debian-stretch-php70", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { }},
{ :name => "docker-debian-stretch-php71", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "php_version": '7.1' }},
{ :name => "docker-debian-stretch-php72", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "php_version": '7.2' }},
{ :name => "docker-ubuntu-xenial-php70", :docker => "hanxhx/vagrant-ansible:ubuntu16.04", :vars => { }},
{ :name => "docker-ubuntu-bionic-php72", :docker => "hanxhx/vagrant-ansible:ubuntu18.04", :vars => { }},
]
config.vm.network "private_network", type: "dhcp"
conts.each do |opts|
config.vm.define opts[:name] do |m|
m.vm.provider "docker" do |d|
d.image = opts[:docker]
d.remains_running = true
d.has_ssh = true
end end
vms.each do |vm|
config.vm.define vm[0] do |m|
m.vm.box = vm[1]
m.vm.network "private_network", ip: vm[2]
m.vm.provision "ansible" do |ansible| m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml" ansible.playbook = "tests/test.yml"
ansible.verbose = 'vv' ansible.verbose = 'vv'
ansible.sudo = true ansible.become = true
ansible.extra_vars = { ansible.extra_vars = opts[:vars]
php_version: vm[3]
}
end end
end end
end end
vms_debian.each do |opts|
config.vm.define opts[:name] do |m|
m.vm.box = opts[:box]
m.vm.provider "virtualbox" do |v|
v.cpus = 1
v.memory = 256
end
m.vm.provision "shell", inline: "apt-get update && apt-get install -y ifupdown python"
m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml"
ansible.verbose = 'vv'
ansible.become = true
ansible.extra_vars = opts[:vars]
end
end
end
vms_freebsd.each do |opts|
config.vm.base_mac = "080027D14C66"
config.vm.define opts[:name] do |m|
m.vm.box = opts[:box]
m.vm.provider "virtualbox" do |v, override|
override.ssh.shell = "csh"
v.cpus = 2
v.memory = 512
end
m.vm.provision "shell", inline: "pkg install -y python bash"
m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml"
ansible.verbose = 'vv'
ansible.become = true
ansible.extra_vars = opts[:vars].merge({ "ansible_python_interpreter": '/usr/local/bin/python' })
end
end
end
end end

View File

@@ -1,20 +1,18 @@
--- ---
php_version: '5.6' php_version: '{{ php_default_version }}'
php_install_fpm: true php_install_fpm: true
php_install_xdebug: false php_install_xdebug: false
php_extra_packages: [] php_extra_packages: []
php_xdebug_package: null
# php.ini config # php.ini config
php_ini: php_ini:
- key: 'date.timezone' 'date.timezone': 'Europe/Paris'
value: 'Europe/Paris' 'expose_php': 'Off'
- key: 'expose_php' 'memory_limit': '256M'
value: 'Off' php_ini_fpm: {}
- key: 'memory_limit' php_ini_cli: {}
value: '256M'
php_ini_fpm: []
php_ini_cli: []
# OpCache settings # OpCache settings
php_opcache_enable: "1" php_opcache_enable: "1"
@@ -100,3 +98,5 @@ php_fpm_poold:
pm_min_spare_servers: 10 pm_min_spare_servers: 10
pm_max_spare_servers: 20 pm_max_spare_servers: 20
# Hack
php_default_version: 'NONE'

View File

@@ -1,5 +1,7 @@
--- ---
- name: restart php-fpm - name: restart php-fpm
service: name='{{ php_fpm_service }}' state=restarted service:
name: '{{ php_fpm_service }}'
state: restarted
when: php_install_fpm when: php_install_fpm

View File

@@ -1,19 +1,31 @@
--- ---
galaxy_info: galaxy_info:
author: Emilien Mantel author: Emilien Mantel
description: Install and configure PHP 5.6/7.0 (+ FPM is wanted) description: Install and configure PHP 7.0/7.1/7.2 (+ FPM is wanted)
company: company:
license: GPLv2 license: GPLv2
min_ansible_version: 1.9 min_ansible_version: 2.0
platforms: platforms:
- name: Debian - name: Debian
versions: versions:
- jessie - stretch
- name: Ubuntu
versions:
- xenial
- bionic
- name: FreeBSD
versions:
- 11.0
- 11.1
- 12.0
galaxy_tags: galaxy_tags:
- development - development
- web - web
- php - php
- php-fpm
- php7 - php7
- debian - debian
- ubuntu
- freebsd
dependencies: [] dependencies: []

View File

@@ -1,21 +1,29 @@
--- ---
- name: APT | Install PHP-FPM - name: APT | Install PHP-FPM for Debian based systems
apt: pkg={{ php_fpm_service }} state=latest apt:
pkg: "{{ php_fpm_service }}"
state: "{{ 'present' if php_install_fpm else 'absent' }}"
when: ansible_os_family == 'Debian'
- name: SERVICE | Enable service on FreeBSD
service:
name: "{{ php_fpm_service }}"
enabled: "{{ 'yes' if php_install_fpm else 'no' }}"
when: ansible_os_family == 'FreeBSD'
- name: LINEINFILE | PHP configuration - name: LINEINFILE | PHP configuration
lineinfile: > lineinfile:
dest='{{ php_etc_dir }}/fpm/php.ini' dest: '{{ php_cli_ini }}'
regexp='^;?{{ item.key }}' regexp: '^;?{{ item.key }}'
line='{{ item.key }} = {{ item.value }}' line: '{{ item.key }} = {{ item.value }}'
with_flattened: create: yes
- "{{ php_ini }}" with_dict: "{{ php_ini | combine(php_ini_fpm) }}"
- "{{ php_ini_fpm }}"
notify: restart php-fpm notify: restart php-fpm
- name: TEMPLATE | Deploy pool configuration - name: TEMPLATE | Deploy pool configuration
template: > template:
src=etc/__php__/fpm/pool.d/pool.conf.j2 src: etc/__php__/fpm/pool.d/pool.conf.j2
dest='{{ php_etc_dir }}/fpm/pool.d/{{ item.pool_name }}.conf' dest: '{{ php_fpm_pool_dir }}/{{ item.pool_name }}.conf'
with_items: "{{ php_fpm_poold }}" with_items: "{{ php_fpm_poold }}"
notify: restart php-fpm notify: restart php-fpm

View File

@@ -1,35 +1,44 @@
--- ---
- name: ASSERT | Check variables - name: INCLUDE_VARS | Related to OS family
assert: include_vars: "OS_Family_{{ ansible_os_family }}.yml"
that: "php_version in php_managed_versions"
- name: INCLUDE_VARS | Related to PHP version - name: INCLUDE_VARS | Related to OS version
include_vars: "php-{{ php_version }}.yml" include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml"
- name: APT | Install PHP packages - name: APT | Install PHP packages
apt: pkg={{ item }} state=latest update_cache=yes cache_valid_time=3600 apt:
pkg: "{{ item }}"
state: present
update_cache: yes
cache_valid_time: 3600
with_flattened: with_flattened:
- "{{ php_packages }}" - "{{ php_packages }}"
- "{{ php_extra_packages }}" - "{{ php_extra_packages }}"
notify: restart php-fpm
when: ansible_os_family == 'Debian'
- name: PKGNG | Install PHP packages
pkgng:
name: "{{ item }}"
with_flattened:
- "{{ php_packages }}"
- "{{ php_extra_packages }}"
notify: restart php-fpm
when: ansible_os_family == 'FreeBSD'
- name: INCLUDE | PHP-FPM - name: INCLUDE | PHP-FPM
include: fpm.yml include: fpm.yml
when: php_install_fpm
- name: LINEINFILE | PHP configuration - name: LINEINFILE | PHP CLI configuration
lineinfile: > lineinfile:
dest='{{ php_etc_dir }}/cli/php.ini' dest: '{{ php_cli_ini }}'
regexp='^;?{{ item.key }}' regexp: '^;?{{ item.key }}'
line='{{ item.key }} = {{ item.value }}' line: '{{ item.key }} = {{ item.value }}'
with_flattened: with_dict: "{{ php_ini | combine(php_ini_cli) }}"
- "{{ php_ini }}"
- "{{ php_ini_cli }}"
- name: INCLUDE | Xdebug - name: INCLUDE | Xdebug
include: xdebug.yml include: xdebug.yml
when: php_install_xdebug
- name: APT | Install and configure opcache - name: APT | Install and configure opcache
include: opcache.yml include: opcache.yml

View File

@@ -1,20 +1,37 @@
--- ---
- name: APT | Install APCu - block:
apt: pkg="{{ php_apt_prefix }}apcu" state=present
- name: APT | Install Opcache - name: APT | Install APCu
apt: pkg="{{ php_apt_prefix }}opcache" state=present apt:
when: php_version | version_compare('7.0', 'ge') pkg: "{{ php_package_prefix }}apcu"
- name: TEMPLATE | Configure APCu - name: APT | Install Opcache
template: > apt:
src=etc/__php__/mods-available/opcache.ini.j2 pkg: "{{ php_package_prefix }}opcache"
dest="{{ php_mods_dir }}/opcache.ini"
when: ansible_os_family == 'Debian'
- block:
- name: PKGNG | Install APCu
pkgng:
name: "php{{ php_version | replace('.', '') }}-pecl-APCu"
- name: PKGNG | Install Opcache
pkgng:
name: "{{ php_package_prefix }}opcache"
when: ansible_os_family == 'FreeBSD'
- name: TEMPLATE | Configure Opcache
template:
src: "etc/__php__/mods-available/opcache.ini.j2"
dest: "{{ php_mods_dir }}/opcache.ini"
notify: restart php-fpm notify: restart php-fpm
- name: TEMPLATE | Configure APCu - name: TEMPLATE | Configure APCu
template: > template:
src=etc/__php__/mods-available/apcu.ini.j2 src: "etc/__php__/mods-available/apcu.ini.j2"
dest={{ php_mods_dir }}/apcu.ini dest: "{{ php_mods_dir }}/apcu.ini"
notify: restart php-fpm notify: restart php-fpm

View File

@@ -1,21 +1,41 @@
--- ---
- name: APT | Install php-xdebug - block:
apt: >
pkg="{{ php_apt_prefix }}xdebug"
state=latest
update_cache=yes
cache_valid_time=3600
- name: SHELL | Get Xdebug version - name: APT | Install xdebug
shell: dpkg -l | awk '$2 ~ /xdebug$/ { print $3 }' apt:
changed_when: false pkg: "{{ php_xdebug_package }}"
register: xdebug_version state: present
update_cache: yes
cache_valid_time: 3600
when: ansible_os_family == 'Debian'
- name: TEMPLATE | Deploy module configurations - name: PKGNG | Install xdebug
template: > pkgng:
src=etc/__php__/mods-available/xdebug.ini.j2 name: "{{ php_xdebug_package }}"
dest={{ php_mods_dir }}/xdebug.ini when: ansible_os_family == 'FreeBSD' and php_xdebug_package is defined
owner=root
mode=0644 - name: TEMPLATE | Deploy module configurations
template:
src: "etc/__php__/mods-available/xdebug.ini.j2"
dest: "{{ php_mods_dir }}/xdebug.ini"
owner: root
mode: 0644
notify: restart php-fpm notify: restart php-fpm
when: php_install_xdebug
- block:
- name: APT | Uninstall xdebug
apt:
pkg: "{{ php_xdebug_package }}"
state: absent
when: ansible_os_family == 'Debian'
- name: PKGNG | Install xdebug
pkgng:
name: "{{ php_xdebug_package }}"
when: ansible_os_family == 'FreeBSD' and php_xdebug_package is defined
when: not php_install_xdebug

View File

@@ -20,8 +20,8 @@
; Unix user/group of processes ; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group ; Note: The user is mandatory. If the group is not set, the default user's group
; will be used. ; will be used.
user = {{ item.user | default('www-data') }} user = {{ item.user | default(php_default_user_group) }}
group = {{ item.group | default('www-data') }} group = {{ item.group | default(php_default_user_group) }}
; The address on which to accept FastCGI requests. ; The address on which to accept FastCGI requests.
; Valid syntaxes are: ; Valid syntaxes are:
@@ -46,8 +46,8 @@ listen = {{ item.listen }}
; BSD-derived systems allow connections regardless of permissions. ; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user ; Default Values: user and group are set as the running user
; mode is set to 0660 ; mode is set to 0660
listen.owner = {{ item.listen_owner | default('www-data') }} listen.owner = {{ item.listen_owner | default(php_default_user_group) }}
listen.group = {{ item.listen_owner | default('www-data') }} listen.group = {{ item.listen_owner | default(php_default_user_group) }}
;listen.mode = 0660 ;listen.mode = 0660
; When POSIX Access Control Lists are supported you can set them using ; When POSIX Access Control Lists are supported you can set them using
; these options, value is a comma separated list of user/group names. ; these options, value is a comma separated list of user/group names.
@@ -231,7 +231,11 @@ pm.max_spare_servers = {{ item.pm_max_spare_servers }}
; anything, but it may not be a good idea to use the .php extension or it ; anything, but it may not be a good idea to use the .php extension or it
; may conflict with a real PHP file. ; may conflict with a real PHP file.
; Default Value: not set ; Default Value: not set
;pm.status_path = /status {% if item.status_path is defined %}
pm.status_path = {{ item.status_path }}
{% else %}
;pm.status.path = /status
{% endif %}
; The ping URI to call the monitoring page of FPM. If this value is not set, no ; The ping URI to call the monitoring page of FPM. If this value is not set, no
; URI will be recognized as a ping page. This could be used to test from outside ; URI will be recognized as a ping page. This could be used to test from outside
@@ -243,12 +247,20 @@ pm.max_spare_servers = {{ item.pm_max_spare_servers }}
; anything, but it may not be a good idea to use the .php extension or it ; anything, but it may not be a good idea to use the .php extension or it
; may conflict with a real PHP file. ; may conflict with a real PHP file.
; Default Value: not set ; Default Value: not set
{% if item.ping_path is defined %}
ping.path = {{ item.ping_path }}
{% else %}
;ping.path = /ping ;ping.path = /ping
{% endif %}
; This directive may be used to customize the response of a ping request. The ; This directive may be used to customize the response of a ping request. The
; response is formatted as text/plain with a 200 response code. ; response is formatted as text/plain with a 200 response code.
; Default Value: pong ; Default Value: pong
{% if item.ping_response is defined %}
ping.response = {{ item.ping_response }}
{% else %}
;ping.response = pong ;ping.response = pong
{% endif %}
; The access log file ; The access log file
; Default: not set ; Default: not set

View File

@@ -1,7 +1,3 @@
;
; {{ ansible_managed }}
;
extension=apcu.so extension=apcu.so
; apc.enabled can be set to 0 to disable APC ; apc.enabled can be set to 0 to disable APC
@@ -23,3 +19,7 @@ apc.file_update_protection={{ php_apc_file_update_protection }}
apc.slam_defense={{ php_apc_slam_defense }} apc.slam_defense={{ php_apc_slam_defense }}
; Verification with ctime will avoid problems caused by programs such as svn or rsync by making sure inodes haven't changed since the last stat ; Verification with ctime will avoid problems caused by programs such as svn or rsync by making sure inodes haven't changed since the last stat
apc.stat_ctime={{ php_apc_stat_ctime }} apc.stat_ctime={{ php_apc_stat_ctime }}
;
; {{ ansible_managed }}
;

View File

@@ -1,7 +1,3 @@
;
; {{ ansible_managed }}
;
; configuration for php ZendOpcache module ; configuration for php ZendOpcache module
; priority=05 ; priority=05
zend_extension=opcache.so zend_extension=opcache.so
@@ -15,3 +11,7 @@ opcache.max_wasted_percentage={{ php_opcache_max_wasted_percentage }}
opcache.validate_timestamps={{ php_opcache_validate_timestamps }} opcache.validate_timestamps={{ php_opcache_validate_timestamps }}
opcache.revalidate_freq={{ php_opcache_revalidate_freq }} opcache.revalidate_freq={{ php_opcache_revalidate_freq }}
opcache.max_file_size={{ php_opcache_max_file_size }} opcache.max_file_size={{ php_opcache_max_file_size }}
;
; {{ ansible_managed }}
;

View File

@@ -1,14 +1,7 @@
; --------------------------------------
; {{ ansible_managed }}
; --------------------------------------
; configuration for php xdebug module ; configuration for php xdebug module
; priority=20 ; priority=20
zend_extension=xdebug.so zend_extension=xdebug.so
{% if xdebug_version.stdout|version_compare('2.3', 'gt') %}
{% endif %}
xdebug_auto_trace={{ php_xdebug_auto_trace }} xdebug_auto_trace={{ php_xdebug_auto_trace }}
xdebug_cli_color={{ php_xdebug_cli_color }} xdebug_cli_color={{ php_xdebug_cli_color }}
xdebug_collect_assignments={{ php_xdebug_collect_assignments }} xdebug_collect_assignments={{ php_xdebug_collect_assignments }}
@@ -33,9 +26,7 @@ xdebug_overload_var_dump={{ php_xdebug_overload_var_dump }}
xdebug_profiler_append={{ php_xdebug_profiler_append }} xdebug_profiler_append={{ php_xdebug_profiler_append }}
xdebug_profiler_enable={{ php_xdebug_profiler_enable }} xdebug_profiler_enable={{ php_xdebug_profiler_enable }}
xdebug_profiler_enable_trigger={{ php_xdebug_profiler_enable_trigger }} xdebug_profiler_enable_trigger={{ php_xdebug_profiler_enable_trigger }}
{% if xdebug_version.stdout|version_compare('2.3', 'gt') %}
xdebug_profiler_enable_trigger_value={{ php_xdebug_profiler_enable_trigger_value }} xdebug_profiler_enable_trigger_value={{ php_xdebug_profiler_enable_trigger_value }}
{% endif %}
xdebug_profiler_output_dir={{ php_xdebug_profiler_output_dir }} xdebug_profiler_output_dir={{ php_xdebug_profiler_output_dir }}
xdebug_profiler_output_name={{ php_xdebug_profiler_output_name }} xdebug_profiler_output_name={{ php_xdebug_profiler_output_name }}
xdebug_remote_autostart={{ php_xdebug_remote_autostart }} xdebug_remote_autostart={{ php_xdebug_remote_autostart }}
@@ -52,9 +43,7 @@ xdebug_show_exception_trace={{ php_xdebug_show_exception_trace }}
xdebug_show_local_vars={{ php_xdebug_show_local_vars }} xdebug_show_local_vars={{ php_xdebug_show_local_vars }}
xdebug_show_mem_delta={{ php_xdebug_show_mem_delta }} xdebug_show_mem_delta={{ php_xdebug_show_mem_delta }}
xdebug_trace_enable_trigger={{ php_xdebug_trace_enable_trigger }} xdebug_trace_enable_trigger={{ php_xdebug_trace_enable_trigger }}
{% if xdebug_version.stdout|version_compare('2.3', 'gt') %}
xdebug_trace_enable_trigger_value={{ php_xdebug_trace_enable_trigger_value }} xdebug_trace_enable_trigger_value={{ php_xdebug_trace_enable_trigger_value }}
{% endif %}
xdebug_trace_format={{ php_xdebug_trace_format }} xdebug_trace_format={{ php_xdebug_trace_format }}
xdebug_trace_options={{ php_xdebug_trace_options }} xdebug_trace_options={{ php_xdebug_trace_options }}
xdebug_trace_output_dir={{ php_xdebug_trace_output_dir }} xdebug_trace_output_dir={{ php_xdebug_trace_output_dir }}
@@ -63,3 +52,6 @@ xdebug_var_display_max_children={{ php_xdebug_var_display_max_children }}
xdebug_var_display_max_data={{ php_xdebug_var_display_max_data }} xdebug_var_display_max_data={{ php_xdebug_var_display_max_data }}
xdebug_var_display_max_depth={{ php_xdebug_var_display_max_depth }} xdebug_var_display_max_depth={{ php_xdebug_var_display_max_depth }}
; --------------------------------------
; {{ ansible_managed }}
; --------------------------------------

View File

@@ -1,5 +0,0 @@
FROM williamyeh/ansible:debian8-onbuild
RUN apt-get update
CMD ["sh", "tests/test.sh", "5.6"]

View File

@@ -1,5 +0,0 @@
FROM williamyeh/ansible:debian8-onbuild
RUN apt-get update
CMD ["sh", "tests/test.sh", "7.0"]

View File

@@ -1 +0,0 @@
php_version: '5.6'

View File

@@ -1 +0,0 @@
php_version: '7.0'

View File

@@ -0,0 +1,9 @@
---
- name: APT | Install DotDeb key
apt_key:
url: 'http://www.dotdeb.org/dotdeb.gpg'
- name: APT | Add Dotdeb repository
apt_repository:
repo: 'deb http://packages.dotdeb.org {{ ansible_distribution_release }} all'

View File

@@ -0,0 +1,9 @@
---
- name: APT | Install Sury key
apt_key:
url: 'https://packages.sury.org/php/apt.gpg'
- name: APT | Add Sury repository
apt_repository:
repo: 'deb https://packages.sury.org/php/ {{ ansible_distribution_release }} main'

View File

@@ -0,0 +1,23 @@
---
- name: SET_FACT | Prepare test vars
set_fact:
__nginx_conf: /etc/nginx/nginx.conf
- name: APT | Install packages
apt:
pkg: "{{ item }}"
update_cache: yes
cache_valid_time: 3600
with_items:
- apt-transport-https
- ca-certificates
- curl
- lsb-release
- nginx
- name: INCLUDE | Sury
include: Debian/sury.yml
when: >
ansible_distribution_major_version | version_compare(9, 'eq') and
php_version | version_compare('7.1', 'ge')

View File

@@ -0,0 +1,13 @@
---
- name: SET_FACT | Prepare test vars
set_fact:
__nginx_conf: /usr/local/etc/nginx/nginx.conf
php_xdebug_package: 'php72-pecl-xdebug26'
- name: PKGNG | Install packages
pkgng:
name: "{{ item }}"
with_items:
- curl
- nginx

View File

@@ -1,7 +0,0 @@
localhost
[php-5.6]
localhost
[php-7.0]
localhost

View File

@@ -0,0 +1,36 @@
events {
worker_connections 1024;
}
user {{ php_default_user_group }};
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
server_name {{ vhost }};
root /var/www;
{% if php_fpm_poold.0.status_path is defined %}
location = {{ php_fpm_poold.0.status_path }} {
include fastcgi.conf;
fastcgi_pass unix:{{ php_default_fpm_sock }};
}
{% endif %}
{% if php_fpm_poold.0.ping_path is defined %}
location = {{ php_fpm_poold.0.ping_path }} {
include fastcgi.conf;
fastcgi_pass unix:{{ php_default_fpm_sock }};
}
{% endif %}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass unix:{{ php_default_fpm_sock }};
}
}
}

View File

@@ -1,23 +0,0 @@
#!/bin/sh
# Thanks to https://servercheck.in/blog/testing-ansible-roles-travis-ci-github
DIR=$( dirname $0 )
PLAYBOOK="$DIR/test.yml"
ANSIBLE_ARG="localhost"
set -ev
ansible --version
# Check syntax
ansible-playbook -i localhost, -c local --syntax-check -vv $PLAYBOOK
# Check role
ansible-playbook -i localhost, -c local -e "php_version=$1" --become -vv $PLAYBOOK
# Check indempotence
ansible-playbook -i localhost, -c local -e "php_version=$1" --become -vv $PLAYBOOK \
| grep -q 'changed=0.*failed=0' \
&& (echo 'Idempotence test: pass' && exit 0) \
|| (echo 'Idempotence test: fail' && exit 1)

View File

@@ -4,52 +4,92 @@
vars: vars:
vhost: 'test.local' vhost: 'test.local'
php_extra_packages: php_extra_packages:
- '{{ php_apt_prefix }}recode' - '{{ php_package_prefix }}recode'
php_install_xdebug: true php_install_xdebug: true
php_ini_fpm:
display_errors: 'Off'
php_ini_cli:
error_reporting: 'E_ALL'
php_fpm_poold:
- pool_name: 'www'
listen: '{{ php_default_fpm_sock }}'
pm: 'dynamic'
pm_max_children: 250
pm_start_servers: 10
pm_min_spare_servers: 10
pm_max_spare_servers: 20
status_path: '/status'
ping_path: '/ping'
ping_response: 'ok'
pre_tasks: pre_tasks:
- name: APT | Install DotDeb key
apt_key: url='http://www.dotdeb.org/dotdeb.gpg' state=present - name: INCLUDE | Pre tasks related to OS
when: > include: "includes/pre_{{ ansible_os_family }}.yml"
ansible_distribution_major_version | version_compare(8, 'eq') and
php_version | version_compare('7.0', 'ge')
- name: APT | Add Dotdeb repository for Jessie + PHP7
apt_repository: repo='deb http://packages.dotdeb.org jessie all' state=present
when: >
ansible_distribution_major_version | version_compare(8, 'eq') and
php_version | version_compare('7.0', 'ge')
- name: APT | Install nginx
apt: pkg=nginx state=present update_cache=yes cache_valid_time=3600
- name: SHELL | Get nginx version
shell: nginx -V 2>&1 | awk -F '/' '/nginx version/ { print $2 }'
register: nginx_version
changed_when: false
- set_fact: nginx_include="fastcgi_params"
when: nginx_version.stdout | version_compare('1.6', '<', true)
- set_fact: nginx_include="fastcgi.conf"
when: nginx_version.stdout | version_compare('1.6', '>=', true)
tasks: tasks:
- name: COPY | Vhost
copy: > - name: TEMPLATE | Nginx site config
dest=/etc/nginx/sites-enabled/{{ vhost }} template:
content='server { server_name {{ vhost }}; root /var/www; location ~ \.php$ { include {{ nginx_include }}; fastcgi_pass unix:{{ php_default_fpm_sock }}; } }' src: "templates/nginx.conf.j2"
dest: "{{ __nginx_conf }}"
notify: reload nginx notify: reload nginx
- name: COMMAND | Fix nginx config
command: "cp {{ __nginx_conf | dirname }}/fastcgi_params {{ __nginx_conf | dirname }}/fastcgi.conf"
args:
creates: "{{ __nginx_conf | dirname }}/fastcgi.conf"
notify: reload nginx
- name: LINEINFILE | Fix nginx config (second step)
lineinfile:
regexp: '^fastcgi_param\s+SCRIPT_FILENAME'
line: "fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;"
dest: "{{ __nginx_conf | dirname }}/fastcgi.conf"
notify: reload nginx
handlers: handlers:
- name: reload nginx - name: reload nginx
service: name=nginx state=reloaded service:
name: nginx
state: reloaded
roles: roles:
- ../../ - ../../
post_tasks: post_tasks:
- name: SHELL | Test php-cli - name: SHELL | Test php-cli
shell: php -i | grep '^PHP Version' | head -n 1 shell: php -i | grep '^PHP Version => {{ php_version }}' | head -n 1
changed_when: false changed_when: false
register: p register: p
failed_when: p.stdout == '' failed_when: p.stdout == ''
- name: FILE | Create /var/www - name: FILE | Create /var/www
file: dest=/var/www state=directory file:
dest: /var/www
state: directory
- name: COPY | Add phpinfo - name: COPY | Add phpinfo
copy: dest=/var/www/phpinfo.php content='<?php phpinfo();' copy:
dest: /var/www/phpinfo.php
content: '<?php phpinfo();'
- name: SHELL | Check vhost - name: SHELL | Check vhost
shell: "curl -v -H 'Host: {{ vhost }}' http://127.0.0.1/phpinfo.php 2> /dev/null | grep h1 | grep -o 'PHP Version [57].*<' | sed -r 's/<//g'" shell: "curl -v -H 'Host: {{ vhost }}' http://127.0.0.1/phpinfo.php 2> /dev/null | grep h1 | grep -o 'PHP Version {{ php_version }}' | sed -r 's/<//g'"
args:
warn: false
changed_when: false changed_when: false
register: c register: c
failed_when: c.stdout == '' failed_when: c.stdout == ''
- name: URI | Check ping
uri:
url: "http://localhost{{ php_fpm_poold.0.ping_path }}"
when: php_fpm_poold.0.ping_path is defined
- name: URI | Check status
uri:
url: "http://localhost{{ php_fpm_poold.0.status_path }}"
when: php_fpm_poold.0.status_path is defined

1
vars/Debian-stretch.yml Normal file
View File

@@ -0,0 +1 @@
php_default_version: '7.0'

View File

@@ -0,0 +1 @@
php_default_version: '7.2'

23
vars/OS_Family_Debian.yml Normal file
View File

@@ -0,0 +1,23 @@
---
php_packages:
- '{{ php_package_prefix }}cli'
- '{{ php_package_prefix }}curl'
- '{{ php_package_prefix }}gd'
- '{{ php_package_prefix }}mysql'
- '{{ php_package_prefix }}intl'
php_xdebug_package: 'php-xdebug'
php_package_prefix: 'php{{ php_version }}-'
php_mods_dir: '/etc/php/{{ php_version }}/mods-available'
php_fpm_pool_dir: '/etc/php/{{ php_version }}/fpm/pool.d'
php_fpm_service: 'php{{ php_version }}-fpm'
php_default_fpm_sock: '/var/run/php/php{{ php_version }}-fpm.sock'
php_cli_ini: '/etc/php/{{ php_version }}/cli/php.ini'
php_fpm_ini: '/etc/php/{{ php_version }}/fpm/php.ini'
php_default_user_group: 'www-data'

View File

@@ -0,0 +1,20 @@
---
php_packages:
- '{{ php_package_prefix }}curl'
- '{{ php_package_prefix }}gd'
- '{{ php_package_prefix }}mysqli'
- '{{ php_package_prefix }}intl'
php_package_prefix: 'php{{ php_version | replace(".", "") }}-'
php_mods_dir: '/usr/local/etc/php'
php_fpm_pool_dir: '/usr/local/etc/php-fpm.d'
php_fpm_service: 'php-fpm'
php_default_fpm_sock: '/var/run/php-fpm.sock'
php_cli_ini: '/usr/local/etc/php.ini'
php_fpm_ini: '/usr/local/etc/php.ini'
php_default_user_group: 'www'

1
vars/Ubuntu-bionic.yml Normal file
View File

@@ -0,0 +1 @@
php_default_version: '7.2'

1
vars/Ubuntu-xenial.yml Normal file
View File

@@ -0,0 +1 @@
php_default_version: '7.0'

View File

@@ -1,13 +0,0 @@
---
php_packages:
- '{{ php_apt_prefix }}cli'
- '{{ php_apt_prefix }}curl'
- '{{ php_apt_prefix }}gd'
- '{{ php_apt_prefix }}mcrypt'
- '{{ php_mysql_package }}'
- '{{ php_apt_prefix }}intl'
php_managed_versions:
- '5.6'
- '7.0'

View File

@@ -1,8 +0,0 @@
---
php_apt_prefix: 'php5-'
php_etc_dir: '/etc/php5'
php_fpm_service: 'php5-fpm'
php_default_fpm_sock: '/var/run/php5-fpm.sock'
php_mods_dir: '/etc/php5/mods-available'
php_mysql_package: 'php5-mysqlnd'

View File

@@ -1,8 +0,0 @@
---
php_apt_prefix: 'php7.0-'
php_etc_dir: '/etc/php/7.0'
php_fpm_service: 'php7.0-fpm'
php_default_fpm_sock: '/var/run/php/php7.0-fpm.sock'
php_mods_dir: '/etc/php/mods-available'
php_mysql_package: 'php7.0-mysql'