PHP7 Implementation

pull/5/head
Emilien Mantel 2016-01-22 15:57:29 +01:00
parent d1d258a809
commit ee228b05b6
19 changed files with 97 additions and 63 deletions

11
Vagrantfile vendored
View File

@ -6,11 +6,10 @@
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
vms = [ vms = [
[ "wheezy-php54", "deb/wheezy-amd64" , "192.168.33.87" ], [ "jessie-php-5.6", "deb/jessie-amd64", "192.168.33.88", "php-5.6" ],
[ "jessie-php56", "deb/jessie-amd64", "192.168.33.88" ], [ "jessie-php-7.0", "deb/jessie-amd64", "192.168.33.89", "php-7.0" ],
[ "jessie-php70", "deb/jessie-amd64", "192.168.33.89" ], [ "stretch-php-5.6", "sharlak/debian_stretch_64", "192.168.33.90", "php-5.6" ],
[ "stretch-php56", "sharlak/debian_stretch_64", "192.168.33.90" ], [ "stretch-php-7.0", "sharlak/debian_stretch_64", "192.168.33.91", "php-7.0" ]
[ "stretch-php70", "sharlak/debian_stretch_64", "192.168.33.91" ]
] ]
config.vm.provider "virtualbox" do |v| config.vm.provider "virtualbox" do |v|
@ -25,7 +24,7 @@ Vagrant.configure("2") do |config|
m.vm.provision "ansible" do |ansible| m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml" ansible.playbook = "tests/test.yml"
ansible.groups = { "test" => [ vm[0] ] } ansible.groups = { vm[3] => [ vm[0] ] }
ansible.verbose = 'vv' ansible.verbose = 'vv'
ansible.sudo = true ansible.sudo = true
end end

View File

@ -1,5 +1,6 @@
--- ---
php_version: '5.6'
php_install_fpm: true php_install_fpm: true
php_install_xdebug: false php_install_xdebug: false
php_extra_packages: [] php_extra_packages: []
@ -15,7 +16,7 @@ php_ini:
php_ini_fpm: [] php_ini_fpm: []
php_ini_cli: [] php_ini_cli: []
# OpCache settings (PHP >= 5.5) # OpCache settings
php_opcache_enable: "1" php_opcache_enable: "1"
php_opcache_enable_cli: "0" php_opcache_enable_cli: "0"
php_opcache_memory_consumption: "96" php_opcache_memory_consumption: "96"
@ -92,7 +93,7 @@ php_xdebug_var_display_max_depth: '3'
# PHP-FPM # PHP-FPM
php_fpm_poold: php_fpm_poold:
- pool_name: 'www' - pool_name: 'www'
listen: '/var/run/php5-fpm.sock' listen: '{{ php_default_fpm_sock }}'
pm: 'dynamic' pm: 'dynamic'
pm_max_children: 250 pm_max_children: 250
pm_start_servers: 10 pm_start_servers: 10

View File

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

View File

@ -1,10 +1,10 @@
--- ---
galaxy_info: galaxy_info:
author: Emilien Mantel author: Emilien Mantel
description: Install and configure PHP (+ FPM is wanted) description: Install and configure PHP 5.6/7.0 (+ FPM is wanted)
company: company:
license: GPLv2 license: GPLv2
min_ansible_version: 1.8 min_ansible_version: 2.0
platforms: platforms:
- name: Debian - name: Debian
versions: versions:

View File

@ -1,16 +1,21 @@
--- ---
- name: APT | Install PHP-FPM - name: APT | Install PHP-FPM
apt: pkg=php5-fpm state=latest apt: pkg={{ php_fpm_service }} state=latest
- name: LINEINFILE | PHP configuration - name: LINEINFILE | PHP configuration
lineinfile: dest=/etc/php5/fpm/php.ini regexp='^;?{{ item.key }}' line='{{ item.key }} = {{ item.value }}' lineinfile: >
dest='{{ php_etc_dir }}/fpm/php.ini'
regexp='^;?{{ item.key }}'
line='{{ item.key }} = {{ item.value }}'
with_flattened: with_flattened:
- php_ini - php_ini
- 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: src=etc/php5/fpm/pool.d/pool.conf.j2 dest=/etc/php5/fpm/pool.d/{{ item.pool_name }}.conf template: >
src=etc/__php__/fpm/pool.d/pool.conf.j2
dest='{{ php_etc_dir }}/fpm/pool.d/{{ 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,40 +1,43 @@
--- ---
- name: ASSERT | Check variables
assert:
that: "php_version in php_managed_versions"
- name: INCLUDE_VARS | Related to PHP version
include_vars: "php-{{ php_version }}.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=latest update_cache=yes cache_valid_time=3600
with_flattened: with_flattened:
- php_packages - php_packages
- php_extra_packages - php_extra_packages
# Note: only needed for PHP5x + Xdebug
- name: COMMAND | Get PHP extension dir - name: COMMAND | Get PHP extension dir
command: php-config --extension-dir command: php-config --extension-dir
changed_when: false changed_when: false
register: php_extension_dir register: php_extension_dir
when: php_version == '5.6'
- name: INCLUDE | PHP-FPM - name: INCLUDE | PHP-FPM
include: fpm.yml include: fpm.yml
when: php_install_fpm when: php_install_fpm
- name: LINEINFILE | PHP configuration - name: LINEINFILE | PHP configuration
lineinfile: dest=/etc/php5/cli/php.ini regexp='^;?{{ item.key }}' line='{{ item.key }} = {{ item.value }}' lineinfile: >
dest='{{ php_etc_dir }}/cli/php.ini'
regexp='^;?{{ item.key }}'
line='{{ item.key }} = {{ item.value }}'
with_flattened: with_flattened:
- php_ini - php_ini
- php_ini_cli - php_ini_cli
# Note: Xdebug is not packaged on PHP7.0
- name: INCLUDE | Xdebug - name: INCLUDE | Xdebug
include: xdebug.yml include: xdebug.yml
when: php_install_xdebug when: php_install_xdebug and php_version == 5
- name: SHELL | Get PHP version on apt - name: APT | Install and configure opcache
shell: php -v | head -n 1 | awk '{ print $2 }' include: opcache.yml
register: php_apt_version
changed_when: false
- name: APT | Install and configure php-apcu / opcache (PHP 5.5+ only)
include: php55min.yml
when: php_apt_version.stdout|version_compare('5.5', 'ge', False)
- name: APT | Install and configure php-apc (PHP 5.4 max only)
include: php54max.yml
when: php_apt_version.stdout|version_compare('5.5', 'lt', False)

19
tasks/opcache.yml 100644
View File

@ -0,0 +1,19 @@
---
- name: APT | Install php-apcu
apt: pkg=php5-apcu state=latest
when: php_version == 5
- name: TEMPLATE | Configure APCu
template: >
src=etc/__php__/mods-available/opcache.ini.j2
dest="{{ php_mods_dir }}/opcache.ini"
notify: restart php-fpm
when: php_version == 5
- name: TEMPLATE | Configure APCu
template: >
src=etc/__php__/mods-available/apcu.ini.j2
dest={{ php_mods_dir }}/apcu.ini
notify: restart php-fpm
when: php_version == 5

View File

@ -1,11 +0,0 @@
---
- name: APT | Install php-apcu
apt: pkg=php-apc state=latest
- name: SET_FACT | Set APC
set_fact: php_apc_package="apc"
- name: TEMPLATE | Configure APC
template: src=etc/php5/mods-available/apcu.ini.j2 dest=/etc/php5/mods-available/apc.ini
notify: restart php-fpm

View File

@ -1,14 +0,0 @@
---
- name: APT | Install php-apcu
apt: pkg=php5-apcu state=latest
- name: SET_FACT | Set APCu
set_fact: php_apc_package="apcu"
- name: TEMPLATE | Configure Opcache / APCu
template: src=etc/php5/mods-available/{{ item }}.ini.j2 dest=/etc/php5/mods-available/{{ item }}.ini
with_items:
- apcu
- opcache
notify: restart php-fpm

View File

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

View File

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

View File

@ -1,10 +1,16 @@
--- ---
# On Debian Jessie, we need Dotdeb for PHP 7.0
- hosts: php-7.0
roles:
- role: HanXHX.dotdeb
when: ansible_distribution_major_version | version_compare(8, 'eq')
- hosts: all - hosts: all
vars: vars:
vhost: 'test.local' vhost: 'test.local'
php_extra_packages: php_extra_packages:
- 'php5-memcached' - '{{ php_apt_prefix }}recode'
php_install_xdebug: true php_install_xdebug: true
pre_tasks: pre_tasks:
- name: APT | Install nginx - name: APT | Install nginx
@ -17,10 +23,11 @@
when: nginx_version.stdout | version_compare('1.6', '<', true) when: nginx_version.stdout | version_compare('1.6', '<', true)
- set_fact: nginx_include="fastcgi.conf" - set_fact: nginx_include="fastcgi.conf"
when: nginx_version.stdout | version_compare('1.6', '>=', true) when: nginx_version.stdout | version_compare('1.6', '>=', true)
tasks:
- name: COPY | Vhost - name: COPY | Vhost
copy: > copy: >
dest=/etc/nginx/sites-enabled/{{ vhost }} dest=/etc/nginx/sites-enabled/{{ vhost }}
content='server { server_name {{ vhost }}; root /var/www; location ~ \.php$ { include {{ nginx_include }}; fastcgi_pass unix:/var/run/php5-fpm.sock; } }' content='server { server_name {{ vhost }}; root /var/www; location ~ \.php$ { include {{ nginx_include }}; fastcgi_pass unix:{{ php_default_fpm_sock }}; } }'
notify: reload nginx notify: reload nginx
handlers: handlers:
- name: reload nginx - name: reload nginx
@ -31,10 +38,14 @@
- 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' | head -n 1
changed_when: false changed_when: false
register: p
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 5.*<' | 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 [57].*<' | sed -r 's/<//g'"
changed_when: false changed_when: false
register: c
failed_when: c.stdout == ''

View File

@ -1,11 +1,14 @@
--- ---
php_packages: php_packages:
- php5-cli - '{{ php_apt_prefix }}cli'
- php5-curl - '{{ php_apt_prefix }}curl'
- php5-gd - '{{ php_apt_prefix }}gd'
- php5-mcrypt - '{{ php_apt_prefix }}mcrypt'
- php5-mysqlnd - '{{ php_mysql_package }}'
- php5-intl - '{{ php_apt_prefix }}intl'
- php5-dev - '{{ php_apt_prefix }}dev'
php_managed_versions:
- '5.6'
- '7.0'

8
vars/php-5.6.yml 100644
View File

@ -0,0 +1,8 @@
---
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: 'php-mysqlnd'

8
vars/php-7.0.yml 100644
View File

@ -0,0 +1,8 @@
---
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'