An Ansible Role that installs PHP and PHP-FPM from the packages.sury.org repository on Ubuntu and Debian, created with Phansible in mind.
- Ubuntu 22.04, 24.04, 26.04 or Debian 12, 13 (x86_64)
- Ansible >= 2.15
- Root access or
becomeon the target. The configuration and PECL tasks do not setbecomethemselves, so run the play withbecome: yesor as root. - PHP 8.2, 8.3, 8.4 and 8.5 are tested in CI
Defaults from defaults/main.yml:
| Variable | Default | Description |
|---|---|---|
php_version |
"8.4" |
PHP version to install; packages are named php<version>-* |
php_config_prefix |
"/etc/php/{{ php_version }}" |
Directory holding the cli, fpm and apache2 configuration |
php.packages |
["cli", "intl"] |
Extension packages to install, without the php<version>- prefix |
server.timezone |
"Europe/London" |
Written to date.timezone in every php.ini the role finds |
Optional, not set by default:
| Variable | Description |
|---|---|
php.peclpackages |
List of PECL extensions to build with pecl install (pulls in php<version>-dev), then enabled with phpenmod |
php<version> and php<version>-fpm are always installed. On the FPM php.ini the role also enables OPcache and turns off expose_php, and sets the www pool socket to www-data:www-data with mode 0660. The CLI php.ini gets opcache.enable_cli=1. If libapache2-mod-php is already installed, its php.ini gets the timezone and OPcache settings too.
php and server are dictionaries, so an override replaces the whole default. server is shared with role-server, which uses the same name.
None.
- hosts: all
become: yes
vars:
php_version: "8.3"
php:
packages: [cli, intl, mbstring, xml, curl]
roles:
- role-phpThis role is released under the terms of the license specified in the repository or if not specified, under the MIT license.
This role was created in 2015 by The Phansible Team & Contributors, credits go also to Jeff Geerling, author of Ansible for DevOps and source of inspiration.