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| Vagrant.configure("2") do |config|
vms_debian = [ vms_debian = [
[ "debian-wheezy", "debian/wheezy64" ],
[ "debian-jessie", "debian/jessie64" ], [ "debian-jessie", "debian/jessie64" ],
[ "debian-stretch", "sharlak/debian_stretch_64" ], [ "debian-stretch", "sharlak/debian_stretch_64" ]
] ]
vms_freebsd = [ vms_freebsd = [

View File

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

View File

@ -1,7 +1,7 @@
PHP 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) - `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). 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` - `max_fails`
- `fail_timeout` - `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. - `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_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". - `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 (O): Optional
(M): Mandatory (M): Mandatory

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,24 @@
{% extends "_base.j2" %} {% 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 %} {% block template_index %}
index {{ item.index | default('index.html index.htm index.php') }}; index {{ item.index | default('index.html index.htm index.php') }};
{% endblock %} {% endblock %}
@ -9,7 +29,7 @@
{% block template_upstream_location %} {% block template_upstream_location %}
location ~ \.php$ { location ~ \.php$ {
fastcgi_pass php; fastcgi_pass {{ php_upstream }};
fastcgi_index index.php; fastcgi_index index.php;
{% if item.upstream_params is defined and item.upstream_params is iterable %} {% if item.upstream_params is defined and item.upstream_params is iterable %}
{% for param in item.upstream_params %} {% for param in item.upstream_params %}

View File

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

View File

@ -2,8 +2,9 @@
# {{ ansible_managed }} # {{ ansible_managed }}
# #
upstream php { {% if nginx_php5 %}
{% for item in nginx_php_sockets %} upstream {{ nginx_upstream_php5 }} {
{% for item in nginx_php5_sockets %}
{% if item.unix_socket is defined %} {% if item.unix_socket is defined %}
server unix:{{ item.unix_socket }} weight={{ item.weight | default('1') }}; server unix:{{ item.unix_socket }} weight={{ item.weight | default('1') }};
{% else %} {% else %}
@ -12,4 +13,18 @@ upstream php {
{% endfor %} {% 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 # vim:filetype=nginx

View File

@ -3,10 +3,18 @@
- name: APT_REPOSITORY | Install backports - name: APT_REPOSITORY | Install backports
apt_repository: repo='deb http://httpredir.debian.org/debian {{ ansible_distribution_release }}-backports main' state=present 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 - name: APT | Install needed packages
apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 state=present
with_items: with_items:
- php5-fpm - php5-fpm
- php7.0-fpm
- curl - curl
- fcgiwrap - fcgiwrap
@ -19,4 +27,5 @@
register: sf register: sf
with_items: with_items:
- php5-fpm - php5-fpm
- php7.0-fpm
- fcgiwrap - fcgiwrap

View File

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

View File

@ -16,7 +16,8 @@
# Role vars # Role vars
nginx_worker_processes: 1 # Ansible+FreeBSD can't detect CPU number nginx_worker_processes: 1 # Ansible+FreeBSD can't detect CPU number
nginx_backports: true nginx_backports: true
nginx_php: true nginx_php5: true
nginx_php7: true
nginx_upstreams: nginx_upstreams:
- name: 'test' - name: 'test'
servers: servers:
@ -145,6 +146,7 @@
'/': '/':
- 'alias /var/tmp;' - 'alias /var/tmp;'
- name: 'test-php.local' - name: 'test-php.local'
php_version: 7
upstream_params: upstream_params:
- 'fastcgi_param FOO bar;' - 'fastcgi_param FOO bar;'
redirect_from: redirect_from:
@ -240,6 +242,20 @@
failed_when: p.stdout.find('PHP Version') == -1 failed_when: p.stdout.find('PHP Version') == -1
with_items: ['test-php.local', 'test-php-index.local'] 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 # Basic Auth
# -------------------------------- # --------------------------------

View File

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