Manages PHP 7.1

freebsd
Emilien Mantel 2017-03-16 18:22:32 +01:00
parent 7727e19da9
commit 2987051153
8 changed files with 63 additions and 10 deletions

View File

@ -1,6 +1,7 @@
env: env:
- PLATFORM=debian-jessie-php-5.6 - PLATFORM=debian-jessie-php-5.6
- PLATFORM=debian-jessie-php-7.0 - PLATFORM=debian-jessie-php-7.0
- PLATFORM=debian-jessie-php-7.1
sudo: required sudo: required

View File

@ -5,7 +5,7 @@ Ansible PHP (+FPM) role for Debian
Install PHP (php-fpm optional) on Debian Jessie/Stretch. Manage APCu, Opcache, Xdebug. Install PHP (php-fpm optional) on Debian Jessie/Stretch. Manage APCu, Opcache, Xdebug.
Managed versions: 5.6 and 7.0 Managed versions: 5.6, 7.0, 7.1
Requirements Requirements
------------ ------------
@ -20,7 +20,7 @@ You should look at [default vars](defaults/main.yml).
### Writable vars ### Writable vars
- `php_version`: 5.6 (default) or 7.0 - `php_version`: 5.6 (default), 7.0, 7.1
- `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).

1
Vagrantfile vendored
View File

@ -8,6 +8,7 @@ Vagrant.configure("2") do |config|
vms = [ vms = [
[ "jessie-php-5.6", "debian/contrib-jessie64", "192.168.33.88", "5.6" ], [ "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" ], [ "jessie-php-7.0", "debian/contrib-jessie64", "192.168.33.89", "7.0" ],
[ "jessie-php-7.1", "debian/contrib-jessie64", "192.168.33.89", "7.1" ],
[ "stretch-php-5.6", "sharlak/debian_stretch_64", "192.168.33.90", "5.6" ], [ "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" ] [ "stretch-php-7.0", "sharlak/debian_stretch_64", "192.168.33.91", "7.0" ]
] ]

View File

@ -1,10 +1,10 @@
--- ---
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 5.6/7.0/7.1 (+ 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:
@ -13,7 +13,11 @@ galaxy_info:
- development - development
- web - web
- php - php
- php5.6
- php5
- php7 - php7
- php7.0
- php7.1
- debian - debian
dependencies: [] dependencies: []

View File

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

View File

@ -6,48 +6,81 @@
php_extra_packages: php_extra_packages:
- '{{ php_apt_prefix }}recode' - '{{ php_apt_prefix }}recode'
php_install_xdebug: true php_install_xdebug: true
pre_tasks: pre_tasks:
- name: APT | Install packages
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600
with_items: ['apt-transport-https', 'curl', 'lsb-release', 'ca-certificates']
- block:
- name: APT | Install DotDeb key - name: APT | Install DotDeb key
apt_key: url='http://www.dotdeb.org/dotdeb.gpg' state=present 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 - name: APT | Add Dotdeb repository for Jessie + PHP7
apt_repository: repo='deb http://packages.dotdeb.org jessie all' state=present apt_repository: repo='deb http://packages.dotdeb.org jessie all' state=present
when: > when: >
ansible_distribution_major_version | version_compare(8, 'eq') and ansible_distribution_major_version | version_compare(8, 'eq') and
php_version | version_compare('7.0', 'ge') php_version | version_compare('7.0', 'eq')
- block:
- name: APT | Install Sury key
apt_key: url='https://packages.sury.org/php/apt.gpg' state=present
- name: APT | Add Dotdeb repository for Jessie + PHP7
apt_repository: repo='deb https://packages.sury.org/php/ jessie main' state=present
when: >
ansible_distribution_major_version | version_compare(8, 'eq') and
php_version | version_compare('7.1', 'eq')
- name: APT | Install nginx - name: APT | Install nginx
apt: pkg=nginx state=present update_cache=yes cache_valid_time=3600 apt: pkg=nginx state=present update_cache=yes cache_valid_time=3600
- name: SHELL | Get nginx version - name: SHELL | Get nginx version
shell: nginx -V 2>&1 | awk -F '/' '/nginx version/ { print $2 }' shell: nginx -V 2>&1 | awk -F '/' '/nginx version/ { print $2 }'
register: nginx_version register: nginx_version
changed_when: false changed_when: false
- set_fact: nginx_include="fastcgi_params" - set_fact: nginx_include="fastcgi_params"
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: 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:{{ php_default_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
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' | 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 [57].*<' | sed -r 's/<//g'"
changed_when: false changed_when: false

View File

@ -11,3 +11,4 @@ php_packages:
php_managed_versions: php_managed_versions:
- '5.6' - '5.6'
- '7.0' - '7.0'
- '7.1'

8
vars/php-7.1.yml 100644
View File

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