Support FreeBSD 11/12

freebsd
Emilien Mantel 2018-03-18 21:29:47 +01:00
parent e87d158424
commit 9aa0f76c03
17 changed files with 205 additions and 57 deletions

View File

@ -1,5 +1,5 @@
Ansible PHP (+FPM) role for Debian / Ubuntu Ansible PHP (+FPM) role for Debian / Ubuntu / FreeBSD
=========================================== =====================================================
[![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.php-blue.svg)](https://galaxy.ansible.com/HanXHX/php) [![Build Status](https://travis-ci.org/HanXHX/ansible-php.svg?branch=master)](https://travis-ci.org/HanXHX/ansible-php) [![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-HanXHX.php-blue.svg)](https://galaxy.ansible.com/HanXHX/php) [![Build Status](https://travis-ci.org/HanXHX/ansible-php.svg?branch=master)](https://travis-ci.org/HanXHX/ansible-php)
@ -13,6 +13,8 @@ Managed OS / Versions
| Debian Strech (9) | Yes | Yes (Sury) | Yes (Sury) | | Debian Strech (9) | Yes | Yes (Sury) | Yes (Sury) |
| Ubuntu Xenial (16.04) | Yes | No | No | | Ubuntu Xenial (16.04) | Yes | No | No |
| Ubuntu Bionic (18.04) | No | No | Yes | | Ubuntu Bionic (18.04) | No | No | Yes |
| FreeBSD 11 | Yes | Yes | Yes |
| FreeBSD 12 | Yes | Yes | Yes |
Links: Links:
- [Dotdeb](https://www.dotdeb.org) - [Dotdeb](https://www.dotdeb.org)
@ -23,6 +25,14 @@ 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). 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).
FreeBSD limitations
-------------------
- It doesn't split ini file for FPM/CLI. It's hardcoded as `/usr/local/etc/php.ini`.
- It can't manage multiple PHP versions at the time (like old Debian versions)
- You must explicitely set xdebug package name (use `pkg search xdebug` to find the good one)
Role Variables Role Variables
-------------- --------------

25
Vagrantfile vendored
View File

@ -13,6 +13,11 @@ Vagrant.configure("2") do |config|
{ :name => "ubuntu-bionic-php72", :box => "ubuntu/bionic64", :vars => { }}, { :name => "ubuntu-bionic-php72", :box => "ubuntu/bionic64", :vars => { }},
] ]
vms_freebsd = [
{ :name => "freebsd-11", :box => "freebsd/FreeBSD-11.1-STABLE", :vars => {} },
{ :name => "freebsd-12", :box => "freebsd/FreeBSD-12.0-CURRENT", :vars => {} }
]
conts = [ conts = [
{ :name => "docker-debian-stretch-php70", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { }}, { :name => "docker-debian-stretch-php70", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { }},
{ :name => "docker-debian-stretch-php71", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "php_version": '7.1' }}, { :name => "docker-debian-stretch-php71", :docker => "hanxhx/vagrant-ansible:debian9", :vars => { "php_version": '7.1' }},
@ -55,4 +60,24 @@ Vagrant.configure("2") do |config|
end end
end end
end end
vms_freebsd.each do |opts|
config.vm.base_mac = "080027D14C66"
config.vm.define opts[:name] do |m|
m.vm.box = opts[:box]
m.vm.provider "virtualbox" do |v, override|
override.ssh.shell = "csh"
v.cpus = 2
v.memory = 512
end
m.vm.provision "shell", inline: "pkg install -y python bash"
m.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/test.yml"
ansible.verbose = 'vv'
ansible.become = true
ansible.extra_vars = opts[:vars].merge({ "ansible_python_interpreter": '/usr/local/bin/python' })
end
end
end
end end

View File

@ -4,6 +4,7 @@ php_version: '{{ php_default_version }}'
php_install_fpm: true php_install_fpm: true
php_install_xdebug: false php_install_xdebug: false
php_extra_packages: [] php_extra_packages: []
php_xdebug_package: null
# php.ini config # php.ini config
php_ini: php_ini:

View File

@ -13,6 +13,11 @@ galaxy_info:
versions: versions:
- xenial - xenial
- bionic - bionic
- name: FreeBSD
versions:
- 11.0
- 11.1
- 12.0
galaxy_tags: galaxy_tags:
- development - development
- web - web
@ -21,5 +26,6 @@ galaxy_info:
- php7 - php7
- debian - debian
- ubuntu - ubuntu
- freebsd
dependencies: [] dependencies: []

View File

@ -1,14 +1,23 @@
--- ---
- name: APT | Install PHP-FPM - name: APT | Install PHP-FPM for Debian based systems
apt: apt:
pkg: "{{ php_fpm_service }}" pkg: "{{ php_fpm_service }}"
state: "{{ 'present' if php_install_fpm else 'absent' }}"
when: ansible_os_family == 'Debian'
- name: SERVICE | Enable service on FreeBSD
service:
name: "{{ php_fpm_service }}"
enabled: "{{ 'yes' if php_install_fpm else 'no' }}"
when: ansible_os_family == 'FreeBSD'
- name: LINEINFILE | PHP configuration - name: LINEINFILE | PHP configuration
lineinfile: lineinfile:
dest: '{{ php_cli_ini }}' dest: '{{ php_cli_ini }}'
regexp: '^;?{{ item.key }}' regexp: '^;?{{ item.key }}'
line: '{{ item.key }} = {{ item.value }}' line: '{{ item.key }} = {{ item.value }}'
create: yes
with_dict: "{{ php_ini | combine(php_ini_fpm) }}" with_dict: "{{ php_ini | combine(php_ini_fpm) }}"
notify: restart php-fpm notify: restart php-fpm

View File

@ -16,17 +16,26 @@
- "{{ php_packages }}" - "{{ php_packages }}"
- "{{ php_extra_packages }}" - "{{ php_extra_packages }}"
notify: restart php-fpm notify: restart php-fpm
when: ansible_os_family == 'Debian'
- name: PKGNG | Install PHP packages
pkgng:
name: "{{ item }}"
with_flattened:
- "{{ php_packages }}"
- "{{ php_extra_packages }}"
notify: restart php-fpm
when: ansible_os_family == 'FreeBSD'
- name: INCLUDE | PHP-FPM - name: INCLUDE | PHP-FPM
include: fpm.yml include: fpm.yml
when: php_install_fpm
- name: LINEINFILE | PHP configuration - name: LINEINFILE | PHP CLI configuration
lineinfile: lineinfile:
dest: '{{ php_cli_ini }}' dest: '{{ php_cli_ini }}'
regexp: '^;?{{ item.key }}' regexp: '^;?{{ item.key }}'
line: '{{ item.key }} = {{ item.value }}' line: '{{ item.key }} = {{ item.value }}'
with_dict: "{{ php_ini_cli }}" with_dict: "{{ php_ini | combine(php_ini_cli) }}"
- name: INCLUDE | Xdebug - name: INCLUDE | Xdebug
include: xdebug.yml include: xdebug.yml

View File

@ -1,13 +1,29 @@
--- ---
- name: APT | Install APCu - block:
- name: APT | Install APCu
apt: apt:
pkg: "{{ php_package_prefix }}apcu" pkg: "{{ php_package_prefix }}apcu"
- name: APT | Install Opcache - name: APT | Install Opcache
apt: apt:
pkg: "{{ php_package_prefix }}opcache" pkg: "{{ php_package_prefix }}opcache"
when: ansible_os_family == 'Debian'
- block:
- name: PKGNG | Install APCu
pkgng:
name: "php{{ php_version | replace('.', '') }}-pecl-APCu"
- name: PKGNG | Install Opcache
pkgng:
name: "{{ php_package_prefix }}opcache"
when: ansible_os_family == 'FreeBSD'
- name: TEMPLATE | Configure Opcache - name: TEMPLATE | Configure Opcache
template: template:
src: "etc/__php__/mods-available/opcache.ini.j2" src: "etc/__php__/mods-available/opcache.ini.j2"

View File

@ -2,12 +2,18 @@
- block: - block:
- name: APT | Install php-xdebug - name: APT | Install xdebug
apt: apt:
pkg: "{{ php_package_prefix }}xdebug" pkg: "{{ php_xdebug_package }}"
state: present state: present
update_cache: yes update_cache: yes
cache_valid_time: 3600 cache_valid_time: 3600
when: ansible_os_family == 'Debian'
- name: PKGNG | Install xdebug
pkgng:
name: "{{ php_xdebug_package }}"
when: ansible_os_family == 'FreeBSD' and php_xdebug_package is defined
- name: TEMPLATE | Deploy module configurations - name: TEMPLATE | Deploy module configurations
template: template:
@ -19,8 +25,17 @@
when: php_install_xdebug when: php_install_xdebug
- name: APT | Uninstall php-xdebug - block:
- name: APT | Uninstall xdebug
apt: apt:
pkg: "{{ php_package_prefix }}xdebug" pkg: "{{ php_xdebug_package }}"
state: absent state: absent
when: ansible_os_family == 'Debian'
- name: PKGNG | Install xdebug
pkgng:
name: "{{ php_xdebug_package }}"
when: ansible_os_family == 'FreeBSD' and php_xdebug_package is defined
when: not php_install_xdebug when: not php_install_xdebug

View File

@ -20,8 +20,8 @@
; Unix user/group of processes ; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group ; Note: The user is mandatory. If the group is not set, the default user's group
; will be used. ; will be used.
user = {{ item.user | default('www-data') }} user = {{ item.user | default(php_default_user_group) }}
group = {{ item.group | default('www-data') }} group = {{ item.group | default(php_default_user_group) }}
; The address on which to accept FastCGI requests. ; The address on which to accept FastCGI requests.
; Valid syntaxes are: ; Valid syntaxes are:
@ -46,8 +46,8 @@ listen = {{ item.listen }}
; BSD-derived systems allow connections regardless of permissions. ; BSD-derived systems allow connections regardless of permissions.
; Default Values: user and group are set as the running user ; Default Values: user and group are set as the running user
; mode is set to 0660 ; mode is set to 0660
listen.owner = {{ item.listen_owner | default('www-data') }} listen.owner = {{ item.listen_owner | default(php_default_user_group) }}
listen.group = {{ item.listen_owner | default('www-data') }} listen.group = {{ item.listen_owner | default(php_default_user_group) }}
;listen.mode = 0660 ;listen.mode = 0660
; When POSIX Access Control Lists are supported you can set them using ; When POSIX Access Control Lists are supported you can set them using
; these options, value is a comma separated list of user/group names. ; these options, value is a comma separated list of user/group names.

View File

@ -2,7 +2,7 @@
- name: SET_FACT | Prepare test vars - name: SET_FACT | Prepare test vars
set_fact: set_fact:
__nginx_site_dir: /etc/nginx/sites-enabled __nginx_conf: /etc/nginx/nginx.conf
- name: APT | Install packages - name: APT | Install packages
apt: apt:

View File

@ -0,0 +1,13 @@
---
- name: SET_FACT | Prepare test vars
set_fact:
__nginx_conf: /usr/local/etc/nginx/nginx.conf
php_xdebug_package: 'php72-pecl-xdebug26'
- name: PKGNG | Install packages
pkgng:
name: "{{ item }}"
with_items:
- curl
- nginx

View File

@ -0,0 +1,36 @@
events {
worker_connections 1024;
}
user {{ php_default_user_group }};
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
server_name {{ vhost }};
root /var/www;
{% if php_fpm_poold.0.status_path is defined %}
location = {{ php_fpm_poold.0.status_path }} {
include fastcgi.conf;
fastcgi_pass unix:{{ php_default_fpm_sock }};
}
{% endif %}
{% if php_fpm_poold.0.ping_path is defined %}
location = {{ php_fpm_poold.0.ping_path }} {
include fastcgi.conf;
fastcgi_pass unix:{{ php_default_fpm_sock }};
}
{% endif %}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass unix:{{ php_default_fpm_sock }};
}
}
}

View File

@ -1,23 +0,0 @@
server {
server_name {{ vhost }};
root /var/www;
{% if php_fpm_poold.0.status_path is defined %}
location = {{ php_fpm_poold.0.status_path }} {
include fastcgi.conf;
fastcgi_pass unix:{{ php_default_fpm_sock }};
}
{% endif %}
{% if php_fpm_poold.0.ping_path is defined %}
location = {{ php_fpm_poold.0.ping_path }} {
include fastcgi.conf;
fastcgi_pass unix:{{ php_default_fpm_sock }};
}
{% endif %}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass unix:{{ php_default_fpm_sock }};
}
}

View File

@ -31,14 +31,21 @@
- name: TEMPLATE | Nginx site config - name: TEMPLATE | Nginx site config
template: template:
src: "templates/site.j2" src: "templates/nginx.conf.j2"
dest: "{{ __nginx_site_dir }}/{{ vhost }}" dest: "{{ __nginx_conf }}"
notify: reload nginx notify: reload nginx
- name: FILE | Delete default site - name: COMMAND | Fix nginx config
file: command: "cp {{ __nginx_conf | dirname }}/fastcgi_params {{ __nginx_conf | dirname }}/fastcgi.conf"
path: "{{ __nginx_site_dir }}/default" args:
state: absent creates: "{{ __nginx_conf | dirname }}/fastcgi.conf"
notify: reload nginx
- name: LINEINFILE | Fix nginx config (second step)
lineinfile:
regexp: '^fastcgi_param\s+SCRIPT_FILENAME'
line: "fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;"
dest: "{{ __nginx_conf | dirname }}/fastcgi.conf"
notify: reload nginx notify: reload nginx
handlers: handlers:

View File

@ -0,0 +1 @@
php_default_version: '7.2'

View File

@ -7,14 +7,17 @@ php_packages:
- '{{ php_package_prefix }}mysql' - '{{ php_package_prefix }}mysql'
- '{{ php_package_prefix }}intl' - '{{ php_package_prefix }}intl'
php_xdebug_package: 'php-xdebug'
php_package_prefix: 'php{{ php_version }}-' php_package_prefix: 'php{{ php_version }}-'
php_etc_dir: '/etc/php/{{ php_version }}' php_mods_dir: '/etc/php/{{ php_version }}/mods-available'
php_mods_dir: '{{ php_etc_dir }}/mods-available' php_fpm_pool_dir: '/etc/php/{{ php_version }}/fpm/pool.d'
php_fpm_pool_dir: '{{ php_etc_dir }}/fpm/pool.d'
php_fpm_service: 'php{{ php_version }}-fpm' php_fpm_service: 'php{{ php_version }}-fpm'
php_default_fpm_sock: '/var/run/php/php{{ php_version }}-fpm.sock' php_default_fpm_sock: '/var/run/php/php{{ php_version }}-fpm.sock'
php_cli_ini: '{{ php_etc_dir }}/cli/php.ini' php_cli_ini: '/etc/php/{{ php_version }}/cli/php.ini'
php_fpm_ini: '{{ php_etc_dir }}/fpm/php.ini' php_fpm_ini: '/etc/php/{{ php_version }}/fpm/php.ini'
php_default_user_group: 'www-data'

View File

@ -0,0 +1,20 @@
---
php_packages:
- '{{ php_package_prefix }}curl'
- '{{ php_package_prefix }}gd'
- '{{ php_package_prefix }}mysqli'
- '{{ php_package_prefix }}intl'
php_package_prefix: 'php{{ php_version | replace(".", "") }}-'
php_mods_dir: '/usr/local/etc/php'
php_fpm_pool_dir: '/usr/local/etc/php-fpm.d'
php_fpm_service: 'php-fpm'
php_default_fpm_sock: '/var/run/php-fpm.sock'
php_cli_ini: '/usr/local/etc/php.ini'
php_fpm_ini: '/usr/local/etc/php.ini'
php_default_user_group: 'www'