Support many php versions (php7) + drop wheezy support

pull/22/head
Emilien Mantel 2016-08-09 16:02:09 +02:00
parent af3930a58a
commit e4b5bb2a32
15 changed files with 83 additions and 18 deletions

3
Vagrantfile vendored
View File

@ -6,9 +6,8 @@
Vagrant.configure("2") do |config|
vms_debian = [
[ "debian-wheezy", "debian/wheezy64" ],
[ "debian-jessie", "debian/jessie64" ],
[ "debian-stretch", "sharlak/debian_stretch_64" ],
[ "debian-stretch", "sharlak/debian_stretch_64" ]
]
vms_freebsd = [

View File

@ -31,9 +31,12 @@ nginx_helper_dir: '{{ nginx_etc_dir}}/helper'
#
# PHP
nginx_php: false
nginx_php_sockets:
- unix_socket: "/var/run/php5-fpm.sock"
nginx_php5: false
nginx_php7: false
nginx_php5_sockets:
- unix_socket: "/run/php5-fpm.sock"
nginx_php7_sockets:
- unix_socket: "/run/php/php7.0-fpm.sock"
nginx_upstreams: []
#

View File

@ -1,7 +1,7 @@
PHP
===
- `nginx_php`: boolean if you need to preconfigure PHP (default: false)
- `nginx_php5` and `nginx_php7`: boolean if you need to preconfigure PHP (default: false)
- `nginx_php_sockets`: list of sockets (see bellow)
You should see [Nginx upstream module doc](http://nginx.org/en/docs/http/ngx_http_upstream_module.html).
@ -15,4 +15,4 @@ Each socket have:
- `max_fails`
- `fail_timeout`
With default configuration, it works fine with PHP-FPM. But if you install PHP7 with Dotdeb, path changed between version, you must set well this list.
With default configuration, it works fine with PHP-FPM.

View File

@ -27,6 +27,7 @@ Common
- `proto`: (O) list of protocol used. Default is a list with "http". If you need http and https, you must set a list with "http" and "https". You can only set "https" without http support.
- `ssl_name`: (D) name of the key used when using TLS/SSL. Mandatory when `proto` contains "https"
- `ssl_template` (O) "strong" (default) or "legacy". You can disable SSL helpers and add your own directives by setting "false".
- `php_version` (O) Sepecify PHP version (5 or 7)
(O): Optional
(M): Mandatory

View File

@ -8,7 +8,6 @@ galaxy_info:
platforms:
- name: Debian
versions:
- wheezy
- jessie
- name: FreeBSD
versions:

View File

@ -1,6 +1,5 @@
---
- name: INCLUDE_VARS | Related to OS
include_vars: "{{ ansible_distribution }}.yml"

View File

@ -4,7 +4,7 @@
template: >
src=etc/nginx/upstream/php.conf.j2
dest="{{ nginx_etc_dir }}/conf.d/php.conf"
when: nginx_php
when: nginx_php5 or nginx_php7
notify: reload nginx
- name: TEMPLATE | Deploy other upstreams

View File

@ -1,4 +1,4 @@
{% extends "_base.j2" %}
{% extends "_php.j2" %}
{% block root %}
root {{ nginx_nagios_root }};
@ -56,7 +56,7 @@
fastcgi_param REMOTE_USER $remote_user;
}
location ~ \.php$ {
fastcgi_pass php;
fastcgi_pass {{ php_upstream }};
fastcgi_index index.php;
{% if nginx_version.stdout | version_compare('1.6.1', 'lt') %}
include fastcgi_params;

View File

@ -1,4 +1,24 @@
{% extends "_base.j2" %}
{% macro phpv(version) %}
{% if version == 5 %}
{{ nginx_upstream_php5 -}}
{% elif version == 7 %}
{{ nginx_upstream_php7 -}}
{% else %}
{# Hack... define another upstream #}
{{ version -}}
{% endif %}
{%- endmacro -%}
{% if item.php_version is defined %}
{% set php_upstream = phpv(item.php_version) %}
{% elif nginx_php5 %}
{% set php_upstream = phpv(5) %}
{% elif nginx_php7 %}
{% set php_upstream = phpv(7) %}
{% endif %}
{% block template_index %}
index {{ item.index | default('index.html index.htm index.php') }};
{% endblock %}
@ -9,7 +29,7 @@
{% block template_upstream_location %}
location ~ \.php$ {
fastcgi_pass php;
fastcgi_pass {{ php_upstream }};
fastcgi_index index.php;
{% if item.upstream_params is defined and item.upstream_params is iterable %}
{% for param in item.upstream_params %}

View File

@ -2,7 +2,7 @@
{% block template_upstream_location %}
location = /index.php {
fastcgi_pass php;
fastcgi_pass {{ php_upstream }};
fastcgi_index index.php;
{% if item.upstream_params is defined and item.upstream_params is iterable %}
{% for param in item.upstream_params %}

View File

@ -2,8 +2,9 @@
# {{ ansible_managed }}
#
upstream php {
{% for item in nginx_php_sockets %}
{% if nginx_php5 %}
upstream {{ nginx_upstream_php5 }} {
{% for item in nginx_php5_sockets %}
{% if item.unix_socket is defined %}
server unix:{{ item.unix_socket }} weight={{ item.weight | default('1') }};
{% else %}
@ -12,4 +13,18 @@ upstream php {
{% endfor %}
}
{% endif %}
{% if nginx_php7 %}
upstream {{ nginx_upstream_php7 }} {
{% for item in nginx_php7_sockets %}
{% if item.unix_socket is defined %}
server unix:{{ item.unix_socket }} weight={{ item.weight | default('1') }};
{% else %}
server {{ item.host }}:{{ item.port }} weight={{ item.weight | default('1') }} max_fails={{ item.max_fails | default('5') }} fail_timeout={{ item.fail_timeout | default('10s') }};
{% endif %}
{% endfor %}
}
{% endif %}
# vim:filetype=nginx

View File

@ -3,10 +3,18 @@
- name: APT_REPOSITORY | Install backports
apt_repository: repo='deb http://httpredir.debian.org/debian {{ ansible_distribution_release }}-backports main' state=present
- block:
- name: APT | Install DotDeb key
apt_key: url='http://www.dotdeb.org/dotdeb.gpg' state=present
- name: APT_REPOSITORY | Install dotdeb (PHP 7)
apt_repository: repo='deb http://packages.dotdeb.org {{ ansible_distribution_release }} all' state=present
when: ansible_distribution_release == 'jessie'
- name: APT | Install needed packages
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
with_items:
- php5-fpm
- php7.0-fpm
- curl
- fcgiwrap
@ -19,4 +27,5 @@
register: sf
with_items:
- php5-fpm
- php7.0-fpm
- fcgiwrap

View File

@ -4,7 +4,8 @@
set_fact:
nginx_pkgng_package: 'nginx-devel'
nginx_user: 'www'
nginx_php_sockets:
nginx_php7: false
nginx_php5_sockets:
- host: '127.0.0.1'
port: 9000

View File

@ -16,7 +16,8 @@
# Role vars
nginx_worker_processes: 1 # Ansible+FreeBSD can't detect CPU number
nginx_backports: true
nginx_php: true
nginx_php5: true
nginx_php7: true
nginx_upstreams:
- name: 'test'
servers:
@ -145,6 +146,7 @@
'/':
- 'alias /var/tmp;'
- name: 'test-php.local'
php_version: 7
upstream_params:
- 'fastcgi_param FOO bar;'
redirect_from:
@ -240,6 +242,20 @@
failed_when: p.stdout.find('PHP Version') == -1
with_items: ['test-php.local', 'test-php-index.local']
- name: -- VERIFY PHP5 VHOSTS (implicit default) --
command: "curl -H 'Host: {{ item }}' http://127.0.0.1/"
register: p
changed_when: false
failed_when: p.stdout.find('PHP Version 5') == -1
with_items: ['test-php-index.local']
- name: -- VERIFY PHP7 VHOSTS --
command: "curl -H 'Host: {{ item }}' http://127.0.0.1/"
register: p
changed_when: false
failed_when: p.stdout.find('PHP Version 7') == -1
with_items: ['test-php.local']
# --------------------------------
# Basic Auth
# --------------------------------

View File

@ -31,3 +31,6 @@ nginx_templates_no_dir:
- '_proxy'
- '_nagios3'
- '_backuppc'
nginx_upstream_php5: 'php5'
nginx_upstream_php7: 'php7'