From d1d258a809dd4478b280c2ee9f3b04c7f1e90af8 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Fri, 22 Jan 2016 12:10:48 +0100 Subject: [PATCH 01/19] vagrant boxes many php and debian versions --- Vagrantfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 6d038a4..9db1cc6 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -6,8 +6,11 @@ Vagrant.configure("2") do |config| vms = [ - [ "debian-wheezy", "deb/wheezy-amd64" , "192.168.33.87" ], - [ "debian-jessie", "deb/jessie-amd64", "192.168.33.88" ] + [ "wheezy-php54", "deb/wheezy-amd64" , "192.168.33.87" ], + [ "jessie-php56", "deb/jessie-amd64", "192.168.33.88" ], + [ "jessie-php70", "deb/jessie-amd64", "192.168.33.89" ], + [ "stretch-php56", "sharlak/debian_stretch_64", "192.168.33.90" ], + [ "stretch-php70", "sharlak/debian_stretch_64", "192.168.33.91" ] ] config.vm.provider "virtualbox" do |v| From ee228b05b62ec2b3258ed47951ea889ec0604e6b Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Fri, 22 Jan 2016 15:57:29 +0100 Subject: [PATCH 02/19] PHP7 Implementation --- Vagrantfile | 11 +++---- defaults/main.yml | 5 +-- handlers/main.yml | 2 +- meta/main.yml | 4 +-- tasks/fpm.yml | 11 +++++-- tasks/main.yml | 31 ++++++++++--------- tasks/opcache.yml | 19 ++++++++++++ tasks/php54max.yml | 11 ------- tasks/php55min.yml | 14 --------- .../{php5 => __php__}/fpm/pool.d/pool.conf.j2 | 0 .../mods-available/apcu.ini.j2 | 0 .../mods-available/opcache.ini.j2 | 0 .../mods-available/xdebug.ini.j2 | 0 tests/group_vars/php-5.6 | 1 + tests/group_vars/php-7.0 | 1 + tests/test.yml | 17 ++++++++-- vars/main.yml | 17 +++++----- vars/php-5.6.yml | 8 +++++ vars/php-7.0.yml | 8 +++++ 19 files changed, 97 insertions(+), 63 deletions(-) create mode 100644 tasks/opcache.yml delete mode 100644 tasks/php54max.yml delete mode 100644 tasks/php55min.yml rename templates/etc/{php5 => __php__}/fpm/pool.d/pool.conf.j2 (100%) rename templates/etc/{php5 => __php__}/mods-available/apcu.ini.j2 (100%) rename templates/etc/{php5 => __php__}/mods-available/opcache.ini.j2 (100%) rename templates/etc/{php5 => __php__}/mods-available/xdebug.ini.j2 (100%) create mode 100644 tests/group_vars/php-5.6 create mode 100644 tests/group_vars/php-7.0 create mode 100644 vars/php-5.6.yml create mode 100644 vars/php-7.0.yml diff --git a/Vagrantfile b/Vagrantfile index 9db1cc6..42396bf 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -6,11 +6,10 @@ Vagrant.configure("2") do |config| vms = [ - [ "wheezy-php54", "deb/wheezy-amd64" , "192.168.33.87" ], - [ "jessie-php56", "deb/jessie-amd64", "192.168.33.88" ], - [ "jessie-php70", "deb/jessie-amd64", "192.168.33.89" ], - [ "stretch-php56", "sharlak/debian_stretch_64", "192.168.33.90" ], - [ "stretch-php70", "sharlak/debian_stretch_64", "192.168.33.91" ] + [ "jessie-php-5.6", "deb/jessie-amd64", "192.168.33.88", "php-5.6" ], + [ "jessie-php-7.0", "deb/jessie-amd64", "192.168.33.89", "php-7.0" ], + [ "stretch-php-5.6", "sharlak/debian_stretch_64", "192.168.33.90", "php-5.6" ], + [ "stretch-php-7.0", "sharlak/debian_stretch_64", "192.168.33.91", "php-7.0" ] ] config.vm.provider "virtualbox" do |v| @@ -25,7 +24,7 @@ Vagrant.configure("2") do |config| m.vm.provision "ansible" do |ansible| ansible.playbook = "tests/test.yml" - ansible.groups = { "test" => [ vm[0] ] } + ansible.groups = { vm[3] => [ vm[0] ] } ansible.verbose = 'vv' ansible.sudo = true end diff --git a/defaults/main.yml b/defaults/main.yml index 54a8155..8d56bde 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,6 @@ --- +php_version: '5.6' php_install_fpm: true php_install_xdebug: false php_extra_packages: [] @@ -15,7 +16,7 @@ php_ini: php_ini_fpm: [] php_ini_cli: [] -# OpCache settings (PHP >= 5.5) +# OpCache settings php_opcache_enable: "1" php_opcache_enable_cli: "0" php_opcache_memory_consumption: "96" @@ -92,7 +93,7 @@ php_xdebug_var_display_max_depth: '3' # PHP-FPM php_fpm_poold: - pool_name: 'www' - listen: '/var/run/php5-fpm.sock' + listen: '{{ php_default_fpm_sock }}' pm: 'dynamic' pm_max_children: 250 pm_start_servers: 10 diff --git a/handlers/main.yml b/handlers/main.yml index 8e4c0d4..2f8d6d2 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,5 +1,5 @@ --- - name: restart php-fpm - action: service name=php5-fpm state=restarted + service: name='{{ php_fpm_service }}' state=restarted when: php_install_fpm diff --git a/meta/main.yml b/meta/main.yml index 23c8e52..831c92d 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,10 +1,10 @@ --- galaxy_info: author: Emilien Mantel - description: Install and configure PHP (+ FPM is wanted) + description: Install and configure PHP 5.6/7.0 (+ FPM is wanted) company: license: GPLv2 - min_ansible_version: 1.8 + min_ansible_version: 2.0 platforms: - name: Debian versions: diff --git a/tasks/fpm.yml b/tasks/fpm.yml index b8f79f9..2ea300e 100644 --- a/tasks/fpm.yml +++ b/tasks/fpm.yml @@ -1,16 +1,21 @@ --- - name: APT | Install PHP-FPM - apt: pkg=php5-fpm state=latest + apt: pkg={{ php_fpm_service }} state=latest - 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: - php_ini - php_ini_fpm notify: restart php-fpm - 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 notify: restart php-fpm diff --git a/tasks/main.yml b/tasks/main.yml index 257cec9..0e3ddf2 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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 apt: pkg={{ item }} state=latest update_cache=yes cache_valid_time=3600 with_flattened: - php_packages - php_extra_packages +# Note: only needed for PHP5x + Xdebug - name: COMMAND | Get PHP extension dir command: php-config --extension-dir changed_when: false register: php_extension_dir + when: php_version == '5.6' - name: INCLUDE | PHP-FPM include: fpm.yml when: php_install_fpm - 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: - php_ini - php_ini_cli +# Note: Xdebug is not packaged on PHP7.0 - name: INCLUDE | Xdebug include: xdebug.yml - when: php_install_xdebug + when: php_install_xdebug and php_version == 5 -- name: SHELL | Get PHP version on apt - shell: php -v | head -n 1 | awk '{ print $2 }' - 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) +- name: APT | Install and configure opcache + include: opcache.yml diff --git a/tasks/opcache.yml b/tasks/opcache.yml new file mode 100644 index 0000000..1a26595 --- /dev/null +++ b/tasks/opcache.yml @@ -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 diff --git a/tasks/php54max.yml b/tasks/php54max.yml deleted file mode 100644 index 22605c4..0000000 --- a/tasks/php54max.yml +++ /dev/null @@ -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 diff --git a/tasks/php55min.yml b/tasks/php55min.yml deleted file mode 100644 index 460dfc1..0000000 --- a/tasks/php55min.yml +++ /dev/null @@ -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 diff --git a/templates/etc/php5/fpm/pool.d/pool.conf.j2 b/templates/etc/__php__/fpm/pool.d/pool.conf.j2 similarity index 100% rename from templates/etc/php5/fpm/pool.d/pool.conf.j2 rename to templates/etc/__php__/fpm/pool.d/pool.conf.j2 diff --git a/templates/etc/php5/mods-available/apcu.ini.j2 b/templates/etc/__php__/mods-available/apcu.ini.j2 similarity index 100% rename from templates/etc/php5/mods-available/apcu.ini.j2 rename to templates/etc/__php__/mods-available/apcu.ini.j2 diff --git a/templates/etc/php5/mods-available/opcache.ini.j2 b/templates/etc/__php__/mods-available/opcache.ini.j2 similarity index 100% rename from templates/etc/php5/mods-available/opcache.ini.j2 rename to templates/etc/__php__/mods-available/opcache.ini.j2 diff --git a/templates/etc/php5/mods-available/xdebug.ini.j2 b/templates/etc/__php__/mods-available/xdebug.ini.j2 similarity index 100% rename from templates/etc/php5/mods-available/xdebug.ini.j2 rename to templates/etc/__php__/mods-available/xdebug.ini.j2 diff --git a/tests/group_vars/php-5.6 b/tests/group_vars/php-5.6 new file mode 100644 index 0000000..cf95f41 --- /dev/null +++ b/tests/group_vars/php-5.6 @@ -0,0 +1 @@ +php_version: '5.6' diff --git a/tests/group_vars/php-7.0 b/tests/group_vars/php-7.0 new file mode 100644 index 0000000..5a7a3f5 --- /dev/null +++ b/tests/group_vars/php-7.0 @@ -0,0 +1 @@ +php_version: '7.0' diff --git a/tests/test.yml b/tests/test.yml index 24f980f..299696f 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -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 vars: vhost: 'test.local' php_extra_packages: - - 'php5-memcached' + - '{{ php_apt_prefix }}recode' php_install_xdebug: true pre_tasks: - name: APT | Install nginx @@ -17,10 +23,11 @@ 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: - name: COPY | Vhost copy: > 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 handlers: - name: reload nginx @@ -31,10 +38,14 @@ - name: SHELL | Test php-cli shell: php -i | grep '^PHP Version' | head -n 1 changed_when: false + register: p + failed_when: p.stdout == '' - name: FILE | Create /var/www file: dest=/var/www state=directory - name: COPY | Add phpinfo copy: dest=/var/www/phpinfo.php content=' /dev/null | grep h1 | grep -o 'PHP Version 5.*<' | sed -r 's/ /dev/null | grep h1 | grep -o 'PHP Version [57].*<' | sed -r 's/ Date: Fri, 22 Jan 2016 16:04:26 +0100 Subject: [PATCH 03/19] Travis support many PHP version --- .travis.yml | 4 ++-- ...n-jessie.Dockerfile => debian-jessie-php-5.6.Dockerfile} | 0 tests/debian-jessie-php-7.0.Dockerfile | 6 ++++++ tests/debian-wheezy.Dockerfile | 5 ----- 4 files changed, 8 insertions(+), 7 deletions(-) rename tests/{debian-jessie.Dockerfile => debian-jessie-php-5.6.Dockerfile} (100%) create mode 100644 tests/debian-jessie-php-7.0.Dockerfile delete mode 100644 tests/debian-wheezy.Dockerfile diff --git a/.travis.yml b/.travis.yml index db05ff8..cb8eb3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ env: - - PLATFORM=debian-wheezy - - PLATFORM=debian-jessie + - PLATFORM=debian-jessie-php-5.6 + - PLATFORM=debian-jessie-php-7.0 sudo: required diff --git a/tests/debian-jessie.Dockerfile b/tests/debian-jessie-php-5.6.Dockerfile similarity index 100% rename from tests/debian-jessie.Dockerfile rename to tests/debian-jessie-php-5.6.Dockerfile diff --git a/tests/debian-jessie-php-7.0.Dockerfile b/tests/debian-jessie-php-7.0.Dockerfile new file mode 100644 index 0000000..a060f92 --- /dev/null +++ b/tests/debian-jessie-php-7.0.Dockerfile @@ -0,0 +1,6 @@ +FROM williamyeh/ansible:debian8-onbuild + +RUN apt-get update +RUN ansible-galaxy install HanXHX.dotdeb +CMD ["sh", "tests/test.sh"] + diff --git a/tests/debian-wheezy.Dockerfile b/tests/debian-wheezy.Dockerfile deleted file mode 100644 index 0138946..0000000 --- a/tests/debian-wheezy.Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM williamyeh/ansible:debian7-onbuild - -RUN apt-get update -CMD ["sh", "tests/test.sh"] - From 2fa6bc284678ddd90251415e881f7ac46430a7c9 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Fri, 22 Jan 2016 16:29:43 +0100 Subject: [PATCH 04/19] Travis maanges now PHP version --- tests/debian-jessie-php-5.6.Dockerfile | 2 +- tests/debian-jessie-php-7.0.Dockerfile | 5 ++--- tests/test.sh | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/debian-jessie-php-5.6.Dockerfile b/tests/debian-jessie-php-5.6.Dockerfile index fc71280..9a4908a 100644 --- a/tests/debian-jessie-php-5.6.Dockerfile +++ b/tests/debian-jessie-php-5.6.Dockerfile @@ -1,5 +1,5 @@ FROM williamyeh/ansible:debian8-onbuild RUN apt-get update -CMD ["sh", "tests/test.sh"] +CMD ["sh", "tests/test.sh", "5.6"] diff --git a/tests/debian-jessie-php-7.0.Dockerfile b/tests/debian-jessie-php-7.0.Dockerfile index a060f92..0d61e33 100644 --- a/tests/debian-jessie-php-7.0.Dockerfile +++ b/tests/debian-jessie-php-7.0.Dockerfile @@ -1,6 +1,5 @@ FROM williamyeh/ansible:debian8-onbuild -RUN apt-get update -RUN ansible-galaxy install HanXHX.dotdeb -CMD ["sh", "tests/test.sh"] +RUN apt-get update && ansible-galaxy install HanXHX.dotdeb +CMD ["sh", "tests/test.sh", "7.0"] diff --git a/tests/test.sh b/tests/test.sh index e14025a..00278cb 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -5,17 +5,27 @@ DIR=$( dirname $0 ) INVENTORY_FILE="$DIR/inventory" PLAYBOOK="$DIR/test.yml" +ANSIBLE_ARG="" set -ev +# Only for travis +if [ -n "$1" ] +then + ANSIBLE_ARG="--extra-vars 'php_version=$1'" +fi + + +ansible --version + # Check syntax ansible-playbook -i $INVENTORY_FILE -c local --syntax-check -vv $PLAYBOOK # Check role -ansible-playbook -i $INVENTORY_FILE -c local --sudo -vv $PLAYBOOK +ansible-playbook -i $INVENTORY_FILE -c local $ANSIBLE_ARG --become -vv $PLAYBOOK # Check indempotence -ansible-playbook -i $INVENTORY_FILE -c local --sudo -vv $PLAYBOOK \ +ansible-playbook -i $INVENTORY_FILE -c local $ANSIBLE_ARG --become -vv $PLAYBOOK \ | grep -q 'changed=0.*failed=0' \ && (echo 'Idempotence test: pass' && exit 0) \ || (echo 'Idempotence test: fail' && exit 1) From d79928e41a64f5531d2b207b1633b4709c075945 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Fri, 22 Jan 2016 16:38:02 +0100 Subject: [PATCH 05/19] Fix mysql package --- vars/php-5.6.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/php-5.6.yml b/vars/php-5.6.yml index 46a15ce..4d9b30e 100644 --- a/vars/php-5.6.yml +++ b/vars/php-5.6.yml @@ -5,4 +5,4 @@ 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' +php_mysql_package: 'php5-mysqlnd' From 9711cd5d15a0cb81b24530b7155c3a9d2528018a Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Fri, 22 Jan 2016 16:57:32 +0100 Subject: [PATCH 06/19] Fix travis with dotdeb (Jessie) --- tests/test.sh | 2 +- tests/test.yml | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test.sh b/tests/test.sh index 00278cb..3f65d0b 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -19,7 +19,7 @@ fi ansible --version # Check syntax -ansible-playbook -i $INVENTORY_FILE -c local --syntax-check -vv $PLAYBOOK +ansible-playbook -i $INVENTORY_FILE -c local $ANSIBLE_ARG --syntax-check -vv $PLAYBOOK # Check role ansible-playbook -i $INVENTORY_FILE -c local $ANSIBLE_ARG --become -vv $PLAYBOOK diff --git a/tests/test.yml b/tests/test.yml index 299696f..d02ee88 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,10 +1,13 @@ --- # On Debian Jessie, we need Dotdeb for PHP 7.0 -- hosts: php-7.0 +- hosts: all roles: - role: HanXHX.dotdeb - when: ansible_distribution_major_version | version_compare(8, 'eq') + when: > + ansible_distribution_major_version | version_compare(8, 'eq') and + php_version is defined and + php_version | version_compare('7.0', 'ge') - hosts: all vars: From 9b55e917111eb69c60621745693b17fe3c233780 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Fri, 22 Jan 2016 17:17:38 +0100 Subject: [PATCH 07/19] Travis should load php version with group --- tests/debian-jessie-php-5.6.Dockerfile | 2 +- tests/debian-jessie-php-7.0.Dockerfile | 2 +- tests/inventory | 6 ++++++ tests/test.sh | 4 ++-- tests/test.yml | 6 ++---- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/debian-jessie-php-5.6.Dockerfile b/tests/debian-jessie-php-5.6.Dockerfile index 9a4908a..bca4a55 100644 --- a/tests/debian-jessie-php-5.6.Dockerfile +++ b/tests/debian-jessie-php-5.6.Dockerfile @@ -1,5 +1,5 @@ FROM williamyeh/ansible:debian8-onbuild RUN apt-get update -CMD ["sh", "tests/test.sh", "5.6"] +CMD ["sh", "tests/test.sh", "php-5.6"] diff --git a/tests/debian-jessie-php-7.0.Dockerfile b/tests/debian-jessie-php-7.0.Dockerfile index 0d61e33..8bc0393 100644 --- a/tests/debian-jessie-php-7.0.Dockerfile +++ b/tests/debian-jessie-php-7.0.Dockerfile @@ -1,5 +1,5 @@ FROM williamyeh/ansible:debian8-onbuild RUN apt-get update && ansible-galaxy install HanXHX.dotdeb -CMD ["sh", "tests/test.sh", "7.0"] +CMD ["sh", "tests/test.sh", "php-7.0"] diff --git a/tests/inventory b/tests/inventory index 2fbb50c..f226ed6 100644 --- a/tests/inventory +++ b/tests/inventory @@ -1 +1,7 @@ localhost + +[php-5.6] +localhost + +[php-7.0] +localhost diff --git a/tests/test.sh b/tests/test.sh index 3f65d0b..b62475e 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -5,14 +5,14 @@ DIR=$( dirname $0 ) INVENTORY_FILE="$DIR/inventory" PLAYBOOK="$DIR/test.yml" -ANSIBLE_ARG="" +ANSIBLE_ARG="localhost" set -ev # Only for travis if [ -n "$1" ] then - ANSIBLE_ARG="--extra-vars 'php_version=$1'" + ANSIBLE_ARG="--limit $1" fi diff --git a/tests/test.yml b/tests/test.yml index d02ee88..6d7b98d 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,13 +1,11 @@ --- # On Debian Jessie, we need Dotdeb for PHP 7.0 -- hosts: all +- hosts: php-7.0 roles: - role: HanXHX.dotdeb when: > - ansible_distribution_major_version | version_compare(8, 'eq') and - php_version is defined and - php_version | version_compare('7.0', 'ge') + ansible_distribution_major_version | version_compare(8, 'eq') - hosts: all vars: From 53aae314b4de84d813a441ac7731a27244760515 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Fri, 22 Jan 2016 17:24:15 +0100 Subject: [PATCH 08/19] Dotdeb on php 5.6 --- tests/debian-jessie-php-5.6.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/debian-jessie-php-5.6.Dockerfile b/tests/debian-jessie-php-5.6.Dockerfile index bca4a55..e38fdca 100644 --- a/tests/debian-jessie-php-5.6.Dockerfile +++ b/tests/debian-jessie-php-5.6.Dockerfile @@ -1,5 +1,5 @@ FROM williamyeh/ansible:debian8-onbuild -RUN apt-get update +RUN apt-get update && ansible-galaxy install HanXHX.dotdeb CMD ["sh", "tests/test.sh", "php-5.6"] From 089fd3bbb4460ddf9b621454bf93b38ef4b6c1b5 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Sat, 27 Feb 2016 12:14:34 +0100 Subject: [PATCH 09/19] Use official debian jessie boxes --- Vagrantfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 42396bf..9c03c3d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -6,8 +6,8 @@ Vagrant.configure("2") do |config| vms = [ - [ "jessie-php-5.6", "deb/jessie-amd64", "192.168.33.88", "php-5.6" ], - [ "jessie-php-7.0", "deb/jessie-amd64", "192.168.33.89", "php-7.0" ], + [ "jessie-php-5.6", "debian/contrib-jessie64", "192.168.33.88", "php-5.6" ], + [ "jessie-php-7.0", "debian/contrib-jessie64", "192.168.33.89", "php-7.0" ], [ "stretch-php-5.6", "sharlak/debian_stretch_64", "192.168.33.90", "php-5.6" ], [ "stretch-php-7.0", "sharlak/debian_stretch_64", "192.168.33.91", "php-7.0" ] ] From dfa55e3cb65df652e77cb5973ab6b17505dbf52d Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Sat, 27 Feb 2016 12:38:34 +0100 Subject: [PATCH 10/19] PHP7 now suports Xdebug --- tasks/main.yml | 3 +-- tasks/xdebug.yml | 14 +++++++++++--- templates/etc/__php__/mods-available/xdebug.ini.j2 | 4 ++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 0e3ddf2..6768fdb 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -33,10 +33,9 @@ - php_ini - php_ini_cli -# Note: Xdebug is not packaged on PHP7.0 - name: INCLUDE | Xdebug include: xdebug.yml - when: php_install_xdebug and php_version == 5 + when: php_install_xdebug - name: APT | Install and configure opcache include: opcache.yml diff --git a/tasks/xdebug.yml b/tasks/xdebug.yml index c53d795..1e54b88 100644 --- a/tasks/xdebug.yml +++ b/tasks/xdebug.yml @@ -1,13 +1,21 @@ --- - name: APT | Install php-xdebug - apt: pkg=php5-xdebug state=latest update_cache=yes cache_valid_time=3600 + apt: > + pkg="{{ php_apt_prefix }}xdebug" + state=latest + update_cache=yes + cache_valid_time=3600 - name: SHELL | Get Xdebug version - shell: dpkg -l | awk '$2 ~ /^php5-xdebug$/ { print $3 }' + shell: dpkg -l | awk '$2 ~ /xdebug$/ { print $3 }' changed_when: false register: xdebug_version - name: TEMPLATE | Deploy module configurations - template: src=etc/php5/mods-available/xdebug.ini.j2 dest=/etc/php5/mods-available/xdebug.ini owner=root mode=0644 + template: > + src=etc/__php__/mods-available/xdebug.ini.j2 + dest={{ php_mods_dir }}/xdebug.ini + owner=root + mode=0644 notify: restart php-fpm diff --git a/templates/etc/__php__/mods-available/xdebug.ini.j2 b/templates/etc/__php__/mods-available/xdebug.ini.j2 index 72f716a..59a1a3b 100644 --- a/templates/etc/__php__/mods-available/xdebug.ini.j2 +++ b/templates/etc/__php__/mods-available/xdebug.ini.j2 @@ -4,7 +4,11 @@ ; configuration for php xdebug module ; priority=20 +{% if php_version | version_compare('7.0', 'ge') %} +zend_extension=xdebug.so +{% else %} zend_extension={{ php_extension_dir.stdout }}/xdebug.so +{% endif %} {% if xdebug_version.stdout|version_compare('2.3', 'gt') %} {% endif %} From 5162d00f82cd01a32e8916c31e90c448356aaabf Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Sat, 27 Feb 2016 12:39:05 +0100 Subject: [PATCH 11/19] Ignore fails tries --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fd8e52a..c7cdbe1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vagrant* *.swp +*.retry From c092025337d669c541988cc6bdbf21b1d1393bec Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Sat, 27 Feb 2016 12:51:30 +0100 Subject: [PATCH 12/19] PHP7 now supports APCu / Opcache --- tasks/opcache.yml | 10 +++++----- templates/etc/__php__/mods-available/apcu.ini.j2 | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tasks/opcache.yml b/tasks/opcache.yml index 1a26595..42f1f9a 100644 --- a/tasks/opcache.yml +++ b/tasks/opcache.yml @@ -1,19 +1,19 @@ --- -- name: APT | Install php-apcu - apt: pkg=php5-apcu state=latest - when: php_version == 5 +- name: APT | Install APCu / Opcache + apt: pkg={{ item }} state=latest + with_items: + - "{{ php_apt_prefix }}apcu" + - "{{ php_apt_prefix }}opcache" - 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 diff --git a/templates/etc/__php__/mods-available/apcu.ini.j2 b/templates/etc/__php__/mods-available/apcu.ini.j2 index 2f946de..59afd0c 100644 --- a/templates/etc/__php__/mods-available/apcu.ini.j2 +++ b/templates/etc/__php__/mods-available/apcu.ini.j2 @@ -2,7 +2,7 @@ ; {{ ansible_managed }} ; -extension={{ php_apc_package }}.so +extension=apcu.so ; apc.enabled can be set to 0 to disable APC apc.enable={{ php_apc_enable }} From 9ec6fbf952e4c9a1d71f3efd9e9487474d6264fc Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Sat, 27 Feb 2016 13:05:02 +0100 Subject: [PATCH 13/19] Install Opcache only on PHP >= 7.0 --- tasks/opcache.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tasks/opcache.yml b/tasks/opcache.yml index 42f1f9a..ef5e657 100644 --- a/tasks/opcache.yml +++ b/tasks/opcache.yml @@ -1,10 +1,11 @@ --- -- name: APT | Install APCu / Opcache - apt: pkg={{ item }} state=latest - with_items: - - "{{ php_apt_prefix }}apcu" - - "{{ php_apt_prefix }}opcache" +- name: APT | Install APCu + apt: pkg="{{ php_apt_prefix }}apcu" state=present + +- name: APT | Install Opcache + apt: pkg="{{ php_apt_prefix }}opcache" state=present + when: php_version | version_compare('7.0', 'ge') - name: TEMPLATE | Configure APCu template: > From 675ef60b6de9c591f5b2791232d6589b95a4bb13 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Sat, 27 Feb 2016 13:08:45 +0100 Subject: [PATCH 14/19] Galaxy 1.1 compat --- meta/main.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/meta/main.yml b/meta/main.yml index 831c92d..bb34eb1 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -4,14 +4,16 @@ galaxy_info: description: Install and configure PHP 5.6/7.0 (+ FPM is wanted) company: license: GPLv2 - min_ansible_version: 2.0 + min_ansible_version: 1.9 platforms: - name: Debian versions: - wheezy - jessie - categories: + galaxy_tags: - development - web + - php + - debian dependencies: [] From fd3d404c3127421ac1dc8f921ff605a1b49098ce Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Sat, 27 Feb 2016 13:17:48 +0100 Subject: [PATCH 15/19] README : remove wheezy support, add PHP7 support --- README.md | 23 ++++++++++++----------- meta/main.yml | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 02b08f5..4e92340 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,15 @@ Ansible PHP (+FPM) role for Debian [![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.php-blue.svg)](https://galaxy.ansible.com/list#/roles/4472) [![Build Status](https://travis-ci.org/HanXHX/ansible-php.svg)](https://travis-ci.org/HanXHX/ansible-php) -Install PHP (php-fpm optional) on Debian Wheezy/Jessie. Depending of your PHP version: manage APC(u) / Opcache. +Install PHP (php-fpm optional) on Debian Jessie/Stretch. Manage APCu, Opcache, Xdebug. + +Managed versions: 5.6 and 7.0 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). -On Debian Wheezy, you can use many PHP version: 5.4 from Debian repository and 5.5/5.6 from [Dotdeb](https://www.dotdeb.org). With my [dotdeb role](https://github.com/HanXHX/ansible-debian-dotdeb), you can choose which version you want. +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). Role Variables -------------- @@ -18,6 +20,7 @@ You should look at [default vars](defaults/main.yml). ### Writable vars +- `php_version`: 5.6 (default) or 7.0 - `php_install_fpm`: boolean, install and manage php-fpm (default is true) - `php_install_xdebug`: boolean, install [Xdebug](http://xdebug.org) - `php_extra_packages`: additional php packages to install (default is an empty list). @@ -35,7 +38,7 @@ Note: - You can override with `php_ini_fpm`/`php_ini_cli`, but it breaks idempotence. -#### OpCache settings (PHP >= 5.5) +#### OpCache settings See [Opcache doc](https://secure.php.net/manual/en/opcache.configuration.php) @@ -119,7 +122,6 @@ See [Xdebug doc](http://xdebug.org/docs/all_settings) - `php_xdebug_var_display_max_data` - `php_xdebug_var_display_max_depth` - ### Read only vars - `php_packages`: minimal package list to install @@ -140,12 +142,12 @@ Example Playbook roles: - { role: HanXHX.php } -### Debian Wheezy with PHP 5.5 CLI (no FPM) +### Debian Jessie with PHP 7.0 CLI (no FPM) - - hosts: wheezy-servers + - hosts: jessie-servers roles: - - { role: HanXHX.dotdeb, dotdeb_php_version: "5.5" } - - { role: HanXHX.php, php_install_fpm: false } + - { role: HanXHX.dotdeb } + - { role: HanXHX.php, php_version: '7.0', php_install_fpm: false } License ------- @@ -155,6 +157,5 @@ GPLv2 Author Information ------------------ -- You can find many other roles in my GitHub "lab": https://github.com/HanXHX/my-ansible-playbooks -- All issues, pull-request are welcome :) - +- Twitter: [@hanxhx_](https://twitter.com/hanxhx_) +- All issues, pull-requests are welcome :) diff --git a/meta/main.yml b/meta/main.yml index bb34eb1..af79f48 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -8,12 +8,12 @@ galaxy_info: platforms: - name: Debian versions: - - wheezy - jessie galaxy_tags: - development - web - php + - php7 - debian dependencies: [] From e257e8bde776cd31fa5e89ba7733775411431c64 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Fri, 4 Mar 2016 07:12:41 +0100 Subject: [PATCH 16/19] Simplify tests (don't need dotdeb role + force php_version) --- Vagrantfile | 14 ++++++++------ tests/debian-jessie-php-5.6.Dockerfile | 4 ++-- tests/debian-jessie-php-7.0.Dockerfile | 4 ++-- tests/test.sh | 2 +- tests/test.yml | 12 +++++------- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 9c03c3d..db498a0 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -6,10 +6,10 @@ Vagrant.configure("2") do |config| vms = [ - [ "jessie-php-5.6", "debian/contrib-jessie64", "192.168.33.88", "php-5.6" ], - [ "jessie-php-7.0", "debian/contrib-jessie64", "192.168.33.89", "php-7.0" ], - [ "stretch-php-5.6", "sharlak/debian_stretch_64", "192.168.33.90", "php-5.6" ], - [ "stretch-php-7.0", "sharlak/debian_stretch_64", "192.168.33.91", "php-7.0" ] + [ "jessie-php-5.6", "debian/contrib-jessie64", "192.168.33.88", "5.6" ], + [ "jessie-php-7.0", "debian/contrib-jessie64", "192.168.33.89", "7.0" ], + [ "stretch-php-5.6", "sharlak/debian_stretch_64", "192.168.33.90", "5.6" ], + [ "stretch-php-7.0", "sharlak/debian_stretch_64", "192.168.33.91", "7.0" ] ] config.vm.provider "virtualbox" do |v| @@ -24,9 +24,11 @@ Vagrant.configure("2") do |config| m.vm.provision "ansible" do |ansible| ansible.playbook = "tests/test.yml" - ansible.groups = { vm[3] => [ vm[0] ] } ansible.verbose = 'vv' - ansible.sudo = true + ansible.sudo = true + ansible.extra_vars = { + php_version: vm[3] + } end end end diff --git a/tests/debian-jessie-php-5.6.Dockerfile b/tests/debian-jessie-php-5.6.Dockerfile index e38fdca..9a4908a 100644 --- a/tests/debian-jessie-php-5.6.Dockerfile +++ b/tests/debian-jessie-php-5.6.Dockerfile @@ -1,5 +1,5 @@ FROM williamyeh/ansible:debian8-onbuild -RUN apt-get update && ansible-galaxy install HanXHX.dotdeb -CMD ["sh", "tests/test.sh", "php-5.6"] +RUN apt-get update +CMD ["sh", "tests/test.sh", "5.6"] diff --git a/tests/debian-jessie-php-7.0.Dockerfile b/tests/debian-jessie-php-7.0.Dockerfile index 8bc0393..d4813e1 100644 --- a/tests/debian-jessie-php-7.0.Dockerfile +++ b/tests/debian-jessie-php-7.0.Dockerfile @@ -1,5 +1,5 @@ FROM williamyeh/ansible:debian8-onbuild -RUN apt-get update && ansible-galaxy install HanXHX.dotdeb -CMD ["sh", "tests/test.sh", "php-7.0"] +RUN apt-get update +CMD ["sh", "tests/test.sh", "7.0"] diff --git a/tests/test.sh b/tests/test.sh index b62475e..ac8719b 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -12,7 +12,7 @@ set -ev # Only for travis if [ -n "$1" ] then - ANSIBLE_ARG="--limit $1" + ANSIBLE_ARG="-e 'php_version: $1'" fi diff --git a/tests/test.yml b/tests/test.yml index 6d7b98d..58276ff 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,12 +1,5 @@ --- -# 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 vars: vhost: 'test.local' @@ -14,6 +7,11 @@ - '{{ php_apt_prefix }}recode' php_install_xdebug: true pre_tasks: + - 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 From 7829d09f4c57bbe9cf42c190b9c2fa6e89aa187c Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Fri, 4 Mar 2016 07:48:52 +0100 Subject: [PATCH 17/19] Fix script called by docker/travis --- tests/test.sh | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/tests/test.sh b/tests/test.sh index ac8719b..01cbcbf 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -9,23 +9,16 @@ ANSIBLE_ARG="localhost" set -ev -# Only for travis -if [ -n "$1" ] -then - ANSIBLE_ARG="-e 'php_version: $1'" -fi - - ansible --version # Check syntax -ansible-playbook -i $INVENTORY_FILE -c local $ANSIBLE_ARG --syntax-check -vv $PLAYBOOK +ansible-playbook -i $INVENTORY_FILE -c local --syntax-check -vv $PLAYBOOK # Check role -ansible-playbook -i $INVENTORY_FILE -c local $ANSIBLE_ARG --become -vv $PLAYBOOK +ansible-playbook -i $INVENTORY_FILE -c local -e "php_version: $1" --become -vv $PLAYBOOK # Check indempotence -ansible-playbook -i $INVENTORY_FILE -c local $ANSIBLE_ARG --become -vv $PLAYBOOK \ +ansible-playbook -i $INVENTORY_FILE -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) From 70e2bf3b505051c3dc363baec21ef1bb61d3ab20 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Fri, 4 Mar 2016 07:58:22 +0100 Subject: [PATCH 18/19] Add dotdeb gpg key in tests --- tests/test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test.yml b/tests/test.yml index 58276ff..bb29df3 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -7,6 +7,11 @@ - '{{ php_apt_prefix }}recode' php_install_xdebug: true pre_tasks: + - name: APT | Install DotDeb key + apt_key: url='http://www.dotdeb.org/dotdeb.gpg' state=present + when: > + 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: > From 87e7497b7f859df339eed46f769952fb9efb7c64 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Fri, 4 Mar 2016 08:07:57 +0100 Subject: [PATCH 19/19] Force php variable --- tests/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test.sh b/tests/test.sh index 01cbcbf..95b2489 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -15,10 +15,10 @@ ansible --version ansible-playbook -i $INVENTORY_FILE -c local --syntax-check -vv $PLAYBOOK # Check role -ansible-playbook -i $INVENTORY_FILE -c local -e "php_version: $1" --become -vv $PLAYBOOK +ansible-playbook -i $INVENTORY_FILE -c local -e "php_version=$1" --become -vv $PLAYBOOK # Check indempotence -ansible-playbook -i $INVENTORY_FILE -c local -e "php_version: $1" --become -vv $PLAYBOOK \ +ansible-playbook -i $INVENTORY_FILE -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)