• Stars
    star
    468
  • Rank 93,767 (Top 2 %)
  • Language Jinja
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ansible Role - PHP

Ansible Role: PHP

CI

Installs PHP on RedHat/CentOS and Debian/Ubuntu servers.

Requirements

If you're using an older LTS release of Ubuntu or RHEL, with an old/outdated version of PHP, you need to use a repo or PPA with a maintained PHP version, as this role only works with PHP versions that are currently supported by the PHP community.

Role Variables

Available variables are listed below, along with default values (see defaults/main.yml):

php_packages: []

A list of the PHP packages to install (OS-specific by default). You'll likely want to install common packages like php, php-cli, php-devel and php-pdo, and you can add in whatever other packages you'd like (for example, php-gd for image manipulation, or php-ldap if you need to connect to an LDAP server for authentication).

Note: If you're using Debian/Ubuntu, you also need to install libapache2-mod-fastcgi (for cgi/PHP-FPM) or libapache2-mod-php7.0 (or a similar package depending on PHP version) if you want to use mod_php with Apache.

php_packages_extra: []

A list of extra PHP packages to install without overriding the default list.

php_enable_webserver: true

If your usage of PHP is tied to a web server (e.g. Apache or Nginx), leave this default value. If you are using PHP server-side or to run some small application, set this value to false so this role doesn't attempt to interact with a web server.

php_webserver_daemon: "httpd"

The default values for the HTTP server deamon are httpd (used by Apache) for RedHat/CentOS, or apache2 (also used by Apache) for Debian/Ubuntu. If you are running another webserver (for example, nginx), change this value to the name of the daemon under which the webserver runs.

php_enablerepo: ""

(RedHat/CentOS only) If you have enabled any additional repositories (might I suggest geerlingguy.repo-epel or geerlingguy.repo-remi), those repositories can be listed under this variable (e.g. remi-php70,epel). This can be handy, as an example, if you want to install the latest version of PHP 7.0, which is in the Remi repository.

php_default_version_debian: ""

(Debian/Ubuntu only) The default version of PHP in the given OS version repositories. The specific version is set per distro and per version, but you can override it by providing a value here, like "7.4".

If you'd like to be able to switch PHP versions easily, or use a version that's not available in system packages: You can use the geerlingguy.php-versions role to more easily switch between major PHP versions (e.g. 5.6, 7.1, 7.2).

php_packages_state: "present"

If you have enabled any additional repositories such as geerlingguy.repo-epel or geerlingguy.repo-remi, you may want an easy way to swap PHP versions on the fly. By default, this is set to "present". You can override this variable to "latest" to upgrade to the latest available version. Combined with php_enablerepo, a user now doesn't need to manually uninstall the existing PHP packages before installing them from a different repository.

php_install_recommends: true

(Debian/Ubuntu only) Whether to install recommended packages when installing php_packages; you might want to set this to no explicitly if you're installing a PPA that recommends certain packages you don't want (e.g. Ondrej's php PPA will install php7.0-cli if you install php-pear alongside php5.6-cli... which is often not desired!).

php_executable: "php"

The executable to run when calling PHP from the command line. You should only change this if running php on your server doesn't target the correct executable, or if you're using software collections on RHEL/CentOS and need to target a different version of PHP.

PHP-FPM

PHP-FPM is a simple and robust FastCGI Process Manager for PHP. It can dramatically ease scaling of PHP apps and is the normal way of running PHP-based sites and apps when using a webserver like Nginx (though it can be used with other webservers just as easily).

When using this role with PHP running as php-fpm instead of as a process inside a webserver (e.g. Apache's mod_php), you need to set the following variable to true:

php_enable_php_fpm: false

If you're using Apache, you can easily get it configured to work with PHP-FPM using the geerlingguy.apache-php-fpm role.

php_fpm_state: started
php_fpm_enabled_on_boot: true

Control over the fpm daemon's state; set these to stopped and false if you want FPM to be installed and configured, but not running (e.g. when installing in a container).

php_fpm_handler_state: restarted

The handler restarts PHP-FPM by default. Setting the value to reloaded will reload the service, intead of restarting it.

php_fpm_pools:
  - pool_name: www
    pool_template: www.conf.j2
    pool_listen: "127.0.0.1:9000"
    pool_listen_allowed_clients: "127.0.0.1"
    pool_pm: dynamic
    pool_pm_max_children: 5
    pool_pm_start_servers: 2
    pool_pm_min_spare_servers: 1
    pool_pm_max_spare_servers: 3
    pool_pm_max_requests: 500
    pool_pm_status_path: /status

List of PHP-FPM pool to create. By default, www pool is created. To setup a new pool, add an item to php_fpm_pools list.

Specific settings inside the default www.conf.j2 PHP-FPM pool. If you'd like to manage additional settings, you can do so either by replacing the file with your own template using pool_template.

php.ini settings

php_use_managed_ini: true

By default, all the extra defaults below are applied through the php.ini included with this role. You can self-manage your php.ini file (if you need more flexility in its configuration) by setting this to false (in which case all the below variables will be ignored).

php_fpm_pool_user: "[apache|nginx|other]" # default varies by OS
php_fpm_pool_group: "[apache|nginx|other]" # default varies by OS
php_memory_limit: "256M"
php_max_execution_time: "60"
php_max_input_time: "60"
php_max_input_vars: "1000"
php_realpath_cache_size: "32K"
php_file_uploads: "On"
php_upload_max_filesize: "64M"
php_max_file_uploads: "20"
php_post_max_size: "32M"
php_date_timezone: "America/Chicago"
php_allow_url_fopen: "On"
php_sendmail_path: "/usr/sbin/sendmail -t -i"
php_output_buffering: "4096"
php_short_open_tag: false
php_error_reporting: "E_ALL & ~E_DEPRECATED & ~E_STRICT"
php_display_errors: "Off"
php_display_startup_errors: "On"
php_expose_php: "On"
php_session_cookie_lifetime: 0
php_session_gc_probability: 1
php_session_gc_divisor: 1000
php_session_gc_maxlifetime: 1440
php_session_save_handler: files
php_session_save_path: ''
php_disable_functions: []
php_precision: 14
php_serialize_precision: "-1"

Various defaults for PHP. Only used if php_use_managed_ini is set to true.

OpCache-related Variables

The OpCache is included in PHP starting in version 5.5, and the following variables will only take effect if the version of PHP you have installed is 5.5 or greater.

php_opcache_zend_extension: "opcache.so"
php_opcache_enable: "1"
php_opcache_enable_cli: "0"
php_opcache_memory_consumption: "96"
php_opcache_interned_strings_buffer: "16"
php_opcache_max_accelerated_files: "4096"
php_opcache_max_wasted_percentage: "5"
php_opcache_validate_timestamps: "1"
php_opcache_revalidate_path: "0"
php_opcache_revalidate_freq: "2"
php_opcache_max_file_size: "0"

OpCache ini directives that are often customized on a system. Make sure you have enough memory and file slots allocated in the OpCache (php_opcache_memory_consumption, in MB, and php_opcache_max_accelerated_files) to contain all the PHP code you are running. If not, you may get less-than-optimal performance!

For custom opcache.so location provide full path with php_opcache_zend_extension.

php_opcache_conf_filename: [platform-specific]

The platform-specific opcache configuration filename. Generally the default should work, but in some cases, you may need to override the filename.

APCu-related Variables

php_enable_apc: true

Whether to enable APCu. Other APCu variables will be ineffective if this is set to false.

php_apc_shm_size: "96M"
php_apc_enable_cli: "0"

APCu ini directives that are often customized on a system. Set the php_apc_shm_size so it will hold all cache entries in memory with a little overhead (fragmentation or APC running out of memory will slow down PHP dramatically).

php_apc_conf_filename: [platform-specific]

The platform-specific APC configuration filename. Generally the default should work, but in some cases, you may need to override the filename.

Ensuring APC is installed

If you use APC, you will need to make sure APC is installed (it is installed by default, but if you customize the php_packages list, you need to include APC in the list):

  • On RHEL/CentOS systems: Make sure php-pecl-apcu is in the list of php_packages.
  • On Debian/Ubuntu systems: Make sure php-apcu is in the list of php_packages.

Installing from Source

If you need a specific version of PHP, or would like to test the latest (e.g. master) version of PHP, there's a good chance there's no suitable package already available in your platform's package manager. In these cases, you may choose to install PHP from source by compiling it directly.

Note that source compilation takes much longer than installing from packages (PHP HEAD takes 5+ minutes to compile on a modern quad-core computer, just as a point of reference).

php_install_from_source: false

Set this to true to install PHP from source instead of installing from packages.

php_source_version: "master"

The version of PHP to install from source (a git branch, tag, or commit hash).

php_source_clone_dir: "~/php-src"
php_source_clone_depth: 1
php_source_install_path: "/opt/php"
php_source_install_gmp_path: "/usr/include/x86_64-linux-gnu/gmp.h"
php_source_mysql_config: "/usr/bin/mysql_config"

Location where source will be cloned and installed, and the location of the GMP header file (which can be platform/distribution specific), and mysql_config binary (this may be mariadb_config in newer operating system versions).

php_source_make_command: "make"

Set the make command to make --jobs=X where X is the number of cores present on the server where PHP is being compiled. Will speed up compilation times dramatically if you have multiple cores.

php_source_configure_command: >
  [...]

The ./configure command that will build the Makefile to be used for PHP compilation. Add in all the options you need for your particular environment. Using a folded scalar (>) allows you to define the variable over multiple lines, which is extremely helpful for legibility and source control!

A few other notes/caveats for specific configurations:

  • Apache with mpm_prefork: If you're using Apache with prefork as a webserver for PHP, you will need to make sure apxs2 is available on your system (e.g. by installing apache2-prefork-dev in Ubuntu), and you will need to make sure the option --with-apxs2 is defined in php_source_configure_command. Finally, you will need to make sure the mpm_prefork module is loaded instead of mpm_worker or mpm_event, and likely add a phpX.conf (where X is the major version of PHP) configuration file to the Apache module config folder with contents like php7.conf.
  • Apache with mpm_event or mpm_worker: If you're using Apache with event or worker as a webserver for PHP, you will need to compile PHP with FPM. Make sure the option --enable-fpm is defined in php_source_configure_command. You'll also need to make sure Apache's support for CGI and event is installed (e.g. by installing apache2-mpm-event and libapache2-mod-fastcgi) and the mpm_event module is loaded.
  • Nginx: If you're using Nginx as a webserver for PHP, you will need to compile PHP with FPM. Make sure the option --enable-fpm is defined in php_source_configure_command.

Dependencies

None.

Example Playbook

- hosts: webservers
  vars_files:
    - vars/main.yml
  roles:
    - { role: geerlingguy.php }

Inside vars/main.yml:

php_memory_limit: "128M"
php_max_execution_time: "90"
php_upload_max_filesize: "256M"
php_packages:
  - php
  - php-cli
  - php-common
  - php-devel
  - php-gd
  - php-mbstring
  - php-pdo
  - php-pecl-apcu
  - php-xml
  ...

License

MIT / BSD

Author Information

This role was created in 2014 by Jeff Geerling, author of Ansible for DevOps.

More Repositories

1

ansible-for-devops

Ansible for DevOps examples.
Python
7,475
star
2

mac-dev-playbook

Mac setup and configuration via Ansible.
Shell
5,906
star
3

internet-pi

Raspberry Pi config for all things Internet.
Jinja
3,690
star
4

macos-virtualbox-vm

Instructions and script to help you create a VirtualBox VM running macOS.
Shell
2,519
star
5

ansible-vagrant-examples

Ansible examples using Vagrant to deploy to local VMs.
2,034
star
6

raspberry-pi-dramble

DEPRECATED - Raspberry Pi Kubernetes cluster that runs HA/HP Drupal 8
Shell
1,656
star
7

ansible-role-docker

Ansible Role - Docker
1,515
star
8

drupal-vm

A VM for Drupal development
Jinja
1,370
star
9

pi-webcam

Automation to configure a Raspberry Pi as a USB OTG webcam
1,322
star
10

internet-monitoring

Monitor your network and internet speed with Docker & Prometheus
1,237
star
11

raspberry-pi-pcie-devices

Raspberry Pi PCI Express device compatibility database
HTML
1,230
star
12

ansible-role-mysql

Ansible Role - MySQL
Jinja
988
star
13

ansible-role-jenkins

Ansible Role - Jenkins CI
Groovy
802
star
14

ansible-role-nginx

Ansible Role - Nginx
Jinja
774
star
15

ansible-role-security

Ansible Role - Security
Jinja
706
star
16

ansible-role-certbot

Ansible Role - Certbot (for Let's Encrypt)
Shell
698
star
17

ansible-role-gitlab

Ansible Role - GitLab
Jinja
653
star
18

packer-boxes

Jeff Geerling's Packer build configurations for Vagrant boxes.
Shell
635
star
19

ansible-for-kubernetes

Ansible and Kubernetes examples from Ansible for Kubernetes Book
Shell
612
star
20

my-backup-plan

How I back up all my data.
Shell
576
star
21

dotfiles

My configuration. Minimalist, but helps save a few thousand keystrokes a day.
Shell
540
star
22

ansible-role-firewall

Ansible Role - iptables Firewall configuration.
Shell
481
star
23

ansible-role-postgresql

Ansible Role - PostgreSQL
Jinja
478
star
24

kubernetes-101

Kubernetes 101 - by Jeff Geerling
HTML
477
star
25

ansible-role-kubernetes

Ansible Role - Kubernetes
Jinja
425
star
26

Ping

A PHP class to ping hosts.
PHP
415
star
27

ansible-role-apache

Ansible Role - Apache 2.x.
Jinja
392
star
28

ansible-role-nodejs

Ansible Role - Node.js
Jinja
386
star
29

turing-pi-cluster

DEPRECATED - Turing Pi cluster configuration for Raspberry Pi Compute Modules
Jinja
347
star
30

awx-container

Ansible Container project that manages the lifecycle of AWX on Docker.
297
star
31

ansible-role-java

Ansible Role - Java
Jinja
293
star
32

ansible-role-ntp

Ansible Role - NTP
Jinja
290
star
33

pi-timelapse

Time-lapse app for Raspberry Pi computers.
Python
278
star
34

temperature-monitor

Raspberry Pi-based home temperature monitoring network.
JavaScript
256
star
35

pi-cluster

Raspberry Pi Cluster automation
Shell
231
star
36

ansible-role-awx

DEPRECATED Ansible Role - AWX
230
star
37

ansible-role-homebrew

Ansible Role - Homebrew (MOVED to geerlingguy.mac collection)
Shell
229
star
38

ansible-role-redis

Ansible Role - Redis
Jinja
228
star
39

packer-centos-7

This build has been moved - see README.md
223
star
40

ansible-collection-mac

Collection of macOS automation tools for Ansible.
Shell
220
star
41

ansible-role-dotfiles

Ansible Role - Easy and flexible dotfile installation.
214
star
42

ansible-role-nfs

Ansible Role - NFS
Jinja
207
star
43

ansible-role-haproxy

Ansible Role - HAProxy
Jinja
194
star
44

ansible-role-git

Ansible Role - Git
188
star
45

ansible-role-repo-epel

Ansible Role - EPEL Repository for RHEL/CentOS
175
star
46

ansible-role-composer

Ansible Role - Composer PHP Dependency Manager
Jinja
175
star
47

ansible-role-pip

Ansible Role - Pip (for Python)
174
star
48

turing-pi-2-cluster

DEPRECATED - Turing Pi 2 Cluster
Jinja
174
star
49

ansible-role-logstash

Ansible Role - Logstash
Jinja
168
star
50

ansible-role-elasticsearch

Ansible Role - Elasticsearch
Jinja
167
star
51

pico-w-garage-door-sensor

Wireless garage door sensor for Home Assistant powered by Raspberry Pi Pico W
Python
166
star
52

drupal-for-kubernetes

Drupal Example Site for Kubernetes
PHP
149
star
53

ansible-role-filebeat

Ansible Role - Filebeat for ELK stack
Jinja
137
star
54

ansible-role-backup

Ansible Role - Backup for simple servers
Shell
135
star
55

ansible-role-ansible

Ansible Role - Ansible
130
star
56

airgradient-prometheus

AirGradient Prometheus exporter.
C++
116
star
57

ansible-role-kibana

Ansible Role - Kibana
Jinja
115
star
58

ansible-role-swap

Ansible Role - Swap
107
star
59

obs-task-list-overlay

An HTML and Node.js-based task list overlay for OBS.
JavaScript
105
star
60

drupal-pi

Drupal on Docker on a Raspberry Pi. Pi Dramble's little brother.
Jinja
105
star
61

ansible-role-glusterfs

Ansible Role - GlusterFS
104
star
62

ansible-role-raspberry-pi

Configures a Raspberry Pi (running Raspbian).
102
star
63

docker-centos7-ansible

CentOS 7 Docker container for Ansible playbook and role testing.
Dockerfile
101
star
64

packer-ubuntu-1804

This build has been moved - see README.md
101
star
65

ansible-role-solr

Ansible Role - Apache Solr
Shell
97
star
66

ansible-mastodon

Mastodon installation on a single server using Ansible.
Jinja
95
star
67

sbc-reviews

Jeff Geerling's SBC review data - Raspberry Pi, Radxa, Orange Pi, etc.
93
star
68

ansible-role-supervisor

Ansible Role - Supervisor
Shell
92
star
69

ansible-role-docker_arm

Ansible Role - Docker for ARM and Pi
91
star
70

ansible-requirements-updater

Update your requirements.yml with this grisly Ansible playbook.
90
star
71

ansible-role-php-versions

Ansible Role - PHP Versions
88
star
72

ansible-role-ruby

Ansible Role - Ruby
Shell
86
star
73

ansible-role-mas

Ansible Role - Mac App Store CLI (MOVED to geerlingguy.mac collection)
85
star
74

JJG-Ansible-Windows

[DEPRECATED] Windows shell provisioning script to bootstrap Ansible from within a Vagrant VM.
Shell
85
star
75

ansible-role-drupal

Ansible Role - Drupal
84
star
76

pi4gpu

Raspberry Pi GPU Carrier Board
OpenSCAD
83
star
77

ansible-role-postfix

Ansible Role - Postfix
82
star
78

tower-operator

DEPRECATED: This project was moved and renamed to: https://github.com/ansible/awx-operator
Dockerfile
82
star
79

ansible-role-varnish

Ansible Role - Varnish HTTP accelerator
Jinja
82
star
80

packer-ubuntu-1404

DEPRECATED - Packer Example - Ubuntu 14.04 Vagrant Box using Ansible provisioner
Shell
82
star
81

pi-camera

A Raspberry Pi Camera
Python
79
star
82

packer-centos-6

This build has been moved - see README.md
79
star
83

pi-router

Raspberry Pi-based OpenWRT router config for 4G/5G Waveshare Dual Ethernet board.
Dockerfile
79
star
84

docker-ubuntu1804-ansible

Ubuntu 18.04 LTS (Bionic) Docker container for Ansible playbook and role testing.
Dockerfile
78
star
85

top500-benchmark

Automated Top500 benchmark for clusters or single nodes.
Jinja
76
star
86

deskpi-super6c-cluster

DEPRECATED - DeskPi Super6c 6-node Raspberry Pi CM4 Cluster
76
star
87

docker-examples

There are many like it, but this one is mine.
Python
75
star
88

youtube-10k-pods

10,000 Kubernetes Pods for 10,000 Subscribers
74
star
89

docker-ubuntu2004-ansible

Ubuntu 20.04 LTS (Focal Fossa) Docker container for Ansible playbook and role testing.
Dockerfile
74
star
90

pi-bell-slapper

The King of Ding. Internet-connected Raspberry Pi-based notification bell.
OpenSCAD
74
star
91

baby-safe-temp

Safe temperature monitor for baby's room. Made for Raspberry Pi Pico.
Python
74
star
92

ansible-role-memcached

Ansible Role - Memcached
Jinja
68
star
93

ansible-role-node_exporter

Ansible role - Node exporter
Jinja
66
star
94

ansible-role-mailhog

Ansible Role - MailHog for catching and viewing emails
Shell
62
star
95

molecule-playbook-testing

This is an example from the Ansible 101 livestream
62
star
96

ansible-role-ssh-chroot-jail

Ansible Role - SSH chroot jail config
Shell
60
star
97

pi-nvr

Raspberry Pi NVR for home CCTV recording.
Dockerfile
58
star
98

Imap

Simple wrapper class for PHP's IMAP-related email functions.
PHP
57
star
99

Request

A simple PHP HTTP request class.
PHP
56
star
100

ansible-role-samba

Ansible Role - Samba
55
star