geerlingguy.php
Ansible Role: PHP
This Ansible role installs PHP on RedHat/CentOS and Debian/Ubuntu servers.
Requirements
If you're using an older version of Ubuntu or RHEL with an outdated PHP, you need a repository or PPA that has an updated PHP version, as this role only supports currently maintained PHP versions.
Role Variables
Here's a list of available variables and their default values (see defaults/main.yml
):
php_packages: []
A list of PHP packages to install (default is OS-specific). You may want to include common packages like
php
,php-cli
,php-devel
, andphp-pdo
, and add any other packages you need (likephp-gd
for image processing, orphp-ldap
for LDAP server authentication).Note: If using Debian/Ubuntu, install
libapache2-mod-fastcgi
(for cgi/PHP-FPM) orlibapache2-mod-php7.0
(or a version-specific package) if you want to usemod_php
with Apache.php_packages_extra: []
List of extra PHP packages to install without replacing the default list.
php_enable_webserver: true
Set to
true
if you're using PHP with a web server (like Apache or Nginx). If using PHP server-side or for a small application, change tofalse
to avoid web server interactions.php_webserver_daemon: "httpd"
Default for HTTP server daemon is
httpd
(for Apache) on RedHat/CentOS andapache2
for Debian/Ubuntu. Change this if you're using a different web server (likenginx
).php_enablerepo: ""
(RedHat/CentOS only) List any additional repositories you have enabled here (e.g.,
remi-php70,epel
). Helpful for installing newer PHP versions from repositories like Remi.php_default_version_debian: ""
(Debian/Ubuntu only) Default PHP version in system repositories for your OS version. Override it by providing a version like
"7.4"
.
To easily switch PHP versions or use a version not in system packages, consider using the geerlingguy.php-versions
role.
php_packages_state: "present"
To allow easy PHP version swapping if you've enabled additional repositories. Set to
"latest"
to upgrade to the latest version.php_install_recommends: true
(Debian/Ubuntu only) Decides if recommended packages are installed with
php_packages
. Set tono
if you don't want any recommendations.php_executable: "php"
The command to run PHP from the command line. Change this only if necessary.
PHP-FPM
PHP-FPM is a management tool for PHP processes that helps in scaling PHP apps, especially when using web servers like Nginx.
If using this role with PHP-FPM, set the following variable to true
:
- php_enable_php_fpm: false
If using Apache, the geerlingguy.apache-php-fpm
role simplifies PHP-FPM configuration.
- php_fpm_state: started
- php_fpm_enabled_on_boot: true
Control the PHP-FPM daemon's state; change these to stopped
and false
to keep FPM installed but not running.
- php_fpm_handler_state: restarted
This restarts PHP-FPM by default. Set to reloaded
to just reload the service.
- php_fpm_pools:
A default "www" pool is created. To set up a new pool, add items to the list.
php.ini settings
php_use_managed_ini: true
Default settings applied through php.ini. Set to
false
to manage your own php.ini file.
Various default settings for PHP, only effective if php_use_managed_ini
is true
.
OpCache-related Variables
If you have PHP 5.5 or greater, you can customize these OpCache settings for performance:
- php_opcache and other related settings to manage memory and file handling in OpCache.
APCu-related Variables
APCu settings, including enabling APCu and managing shared memory settings.
Installing from Source
If specific PHP versions are needed, you can install from source, but it's more time-consuming:
- php_install_from_source: false
Set to true
to install from source.
Dependencies
None.
Example Playbook
- hosts: webservers
vars_files:
- vars/main.yml
roles:
- { role: geerlingguy.php }
In 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.
PHP for RedHat/CentOS/Fedora/Debian/Ubuntu.
ansible-galaxy install geerlingguy.php