HanXHX.php

Ansible PHP (+FPM) Role for Debian / Ubuntu / FreeBSD

Ansible Galaxy GitHub Workflow Status (master)

This role installs PHP on Debian, Ubuntu, and FreeBSD systems. It also manages PHP-FPM, APCu, Opcache, and Xdebug.

Supported Operating Systems and PHP Versions

For all Debian versions, you can install different PHP versions using Sury's APT repository.

For other systems:

OS PHP 7.0 PHP 7.1 PHP 7.2 PHP 7.3 PHP >= 7.4
Ubuntu Bionic (18.04) No No Yes No No
FreeBSD 11 Yes Yes Yes Yes Needs testing...
FreeBSD 12 Yes Yes Yes Yes Needs testing...

Links:

Requirements

  • Ansible version 2.11 or higher
  • Collections: community.general
  • If you need PHP-FPM, you must have a web server that supports FastCGI. You can use my nginx role.

Limitations for FreeBSD

  • It does not separate ini files for FPM and CLI. It uses a single file located at /usr/local/etc/php.ini.
  • It cannot handle multiple PHP versions simultaneously (unlike older Debian versions).
  • You must manually specify the xdebug package name (use pkg search xdebug to find it).

Role Variables

Check the default variables.

Writable variables

  • php_version: The version of PHP to install (e.g., 7.3, 7.4).
  • php_install_fpm: Boolean that defines if PHP-FPM should be installed and managed (default is true).
  • php_install_xdebug: Boolean to install Xdebug.
  • php_extra_packages: Any additional PHP packages to install (default is an empty list).

php.ini Settings

  • php_ini: Global configuration used for both FPM and CLI.
  • php_ini_fpm: Configuration specifically for FPM (php-fpm).
  • php_ini_cli: Configuration specifically for CLI (php-fpm).

Note:

  • If you want the same configuration for both CLI and FPM, use php_ini.
  • Keep specific settings in php_ini_fpm and php_ini_cli.
  • You can override settings with php_ini_fpm and php_ini_cli, but that may cause issues with idempotence.

OpCache Settings

See the Opcache documentation for details:

  • php_opcache_enable
  • php_opcache_enable_cli
  • php_opcache_memory_consumption
  • ...and more.

APC/APCu Settings

See the APC documentation for details:

  • php_apc_enable
  • php_apc_shm_size
  • ...and more.

Xdebug Settings

See the Xdebug documentation for the complete list:

  • php_xdebug_auto_trace
  • php_xdebug_default_enable
  • ...and more.

Read-only variables

  • php_packages: Minimal package list to install.
  • php_extension_dir.stdout: Directory where PHP extensions are located (from a task).
  • php_version.stdout: Retrieved PHP version (from a task).

Dependencies

None required.

Example Playbook

Simple Playbook

- hosts: servers
  roles:
     - { role: hanxhx.php }

Debian Bullseye with PHP 8.0 CLI (no FPM)

- hosts: servers
  roles:
     - { role: HanXHX.sury }
     - { role: hanxhx.php, php_version: '8.0', php_install_fpm: false }

License

GPLv2

Donation

If this code has helped you, or if you’ve used it in your projects, feel free to buy me a drink! :beers:

  • Bitcoin: 1BQwhBeszzWbUTyK4aUyq3SRg7rBSHcEQn
  • Ethereum: 0x63abe6b2648fd892816d87a31e3d9d4365a737b5
  • Litecoin: LeNDw34zQLX84VvhCGADNvHMEgb5QyFXyD
  • Monero: 45wbf7VdQAZS5EWUrPhen7Wo4hy7Pa7c7ZBdaWQSRowtd3CZ5vpVw5nTPphTuqVQrnYZC72FXDYyfP31uJmfSQ6qRXFy3bQ

No crypto? A simple star on the project is a great way to say thank you! :sunglasses:

Author Information

Informazioni sul progetto

Install and configure PHP 7.x/8.x

Installa
ansible-galaxy install HanXHX.php
Licenza
gpl-2.0
Download
3.8k
Proprietario
CEO/CTO/SRE triplestack.fr / daemonit.com