commit
b294234dec
|
@ -1,2 +1,3 @@
|
|||
.vagrant*
|
||||
*.swp
|
||||
*.retry
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
23
README.md
23
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?branch=master)](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 :)
|
||||
|
|
|
@ -6,8 +6,10 @@
|
|||
Vagrant.configure("2") do |config|
|
||||
|
||||
vms = [
|
||||
[ "debian-wheezy", "deb/wheezy-amd64" , "192.168.33.87" ],
|
||||
[ "debian-jessie", "deb/jessie-amd64", "192.168.33.88" ]
|
||||
[ "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|
|
||||
|
@ -22,9 +24,11 @@ Vagrant.configure("2") do |config|
|
|||
|
||||
m.vm.provision "ansible" do |ansible|
|
||||
ansible.playbook = "tests/test.yml"
|
||||
ansible.groups = { "test" => [ vm[0] ] }
|
||||
ansible.verbose = 'vv'
|
||||
ansible.sudo = true
|
||||
ansible.sudo = true
|
||||
ansible.extra_vars = {
|
||||
php_version: vm[3]
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
---
|
||||
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: 1.9
|
||||
platforms:
|
||||
- name: Debian
|
||||
versions:
|
||||
- wheezy
|
||||
- jessie
|
||||
categories:
|
||||
galaxy_tags:
|
||||
- development
|
||||
- web
|
||||
- php
|
||||
- php7
|
||||
- debian
|
||||
dependencies: []
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,22 +1,34 @@
|
|||
---
|
||||
|
||||
- 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
|
||||
|
@ -25,16 +37,6 @@
|
|||
include: xdebug.yml
|
||||
when: php_install_xdebug
|
||||
|
||||
- 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
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
|
||||
- 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: >
|
||||
src=etc/__php__/mods-available/opcache.ini.j2
|
||||
dest="{{ php_mods_dir }}/opcache.ini"
|
||||
notify: restart php-fpm
|
||||
|
||||
- name: TEMPLATE | Configure APCu
|
||||
template: >
|
||||
src=etc/__php__/mods-available/apcu.ini.j2
|
||||
dest={{ php_mods_dir }}/apcu.ini
|
||||
notify: restart php-fpm
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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 }}
|
|
@ -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 %}
|
|
@ -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"]
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
FROM williamyeh/ansible:debian8-onbuild
|
||||
|
||||
RUN apt-get update
|
||||
CMD ["sh", "tests/test.sh", "7.0"]
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
FROM williamyeh/ansible:debian7-onbuild
|
||||
|
||||
RUN apt-get update
|
||||
CMD ["sh", "tests/test.sh"]
|
||||
|
|
@ -0,0 +1 @@
|
|||
php_version: '5.6'
|
|
@ -0,0 +1 @@
|
|||
php_version: '7.0'
|
|
@ -0,0 +1,7 @@
|
|||
localhost
|
||||
|
||||
[php-5.6]
|
||||
localhost
|
||||
|
||||
[php-7.0]
|
||||
localhost
|
|
@ -4,17 +4,20 @@
|
|||
|
||||
DIR=$( dirname $0 )
|
||||
PLAYBOOK="$DIR/test.yml"
|
||||
ANSIBLE_ARG="localhost"
|
||||
|
||||
set -ev
|
||||
|
||||
ansible --version
|
||||
|
||||
# Check syntax
|
||||
ansible-playbook -i localhost, -c local --syntax-check -vv $PLAYBOOK
|
||||
|
||||
# Check role
|
||||
ansible-playbook -i localhost, -c local --sudo -vv $PLAYBOOK
|
||||
ansible-playbook -i localhost, -c local -e "php_version=$1" --become -vv $PLAYBOOK
|
||||
|
||||
# Check indempotence
|
||||
ansible-playbook -i localhost, -c local --sudo -vv $PLAYBOOK \
|
||||
ansible-playbook -i localhost, -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)
|
||||
|
|
|
@ -4,9 +4,19 @@
|
|||
vars:
|
||||
vhost: 'test.local'
|
||||
php_extra_packages:
|
||||
- 'php5-memcached'
|
||||
- '{{ 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: >
|
||||
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
|
||||
|
@ -17,10 +27,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 +42,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='<?php phpinfo();'
|
||||
- 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
|
||||
register: c
|
||||
failed_when: c.stdout == ''
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
---
|
||||
|
||||
php_packages:
|
||||
- php5-cli
|
||||
- php5-curl
|
||||
- php5-gd
|
||||
- php5-mcrypt
|
||||
- php5-mysqlnd
|
||||
- php5-intl
|
||||
- php5-dev
|
||||
- '{{ php_apt_prefix }}cli'
|
||||
- '{{ php_apt_prefix }}curl'
|
||||
- '{{ php_apt_prefix }}gd'
|
||||
- '{{ php_apt_prefix }}mcrypt'
|
||||
- '{{ php_mysql_package }}'
|
||||
- '{{ php_apt_prefix }}intl'
|
||||
- '{{ php_apt_prefix }}dev'
|
||||
|
||||
php_managed_versions:
|
||||
- '5.6'
|
||||
- '7.0'
|
||||
|
|
|
@ -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: 'php5-mysqlnd'
|
|
@ -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'
|
Loading…
Reference in New Issue