apham0001.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 version, you will need to have a repository or PPA that provides a maintained PHP version. This role only works with PHP versions that are supported by the PHP community.
Role Variables
Here are the available variables and their default values (check defaults/main.yml):
- php_packages:
[]A list of PHP packages to install (OS-specific by default). Common packages includephp,php-cli,php-devel, andphp-pdo. Add any other packages you want, likephp-gdfor image manipulation orphp-ldapfor LDAP authentication.
Note: On Debian/Ubuntu, you also need to install libapache2-mod-fastcgi for cgi/PHP-FPM, or libapache2-mod-php7.0 (depending on your PHP version) to use mod_php with Apache.
php_packages_extra:
[]A list of additional PHP packages to install without replacing the default list.php_enable_webserver:
trueSet totrueif PHP is used with a web server (e.g., Apache or Nginx). If you're using PHP server-side or for a small app, set this tofalse.php_webserver_daemon:
"httpd"The default HTTP server daemon:httpdfor RedHat/CentOS, andapache2for Debian/Ubuntu. Change this if you're using another web server, likenginx.php_enablerepo:
""For RedHat/CentOS systems, list any additional repositories here (likeremi-php70,epel) to easily install newer PHP versions from them.php_default_version_debian:
"7.0"The default PHP version for Debian/Ubuntu. Set this to"7.2"for Ubuntu 18.04 as it doesn't have PHP 7.0 in default packages.
If you want to easily switch PHP versions or use a version not available in system packages, consider using the geerlingguy.php-versions role.
php_packages_state:
"present"This variable is set to"present"by default. You can change it to"latest"to upgrade to the latest version without needing to uninstall existing PHP packages first.php_install_recommends:
trueFor Debian/Ubuntu only. Indicates whether to install recommended packages. Set tonoif you don’t want certain recommended packages from a PPA.php_executable:
"php"The command to run PHP from the command line. Change this only if you need a different PHP executable.
PHP-FPM
PHP-FPM (FastCGI Process Manager) is a tool for scaling PHP applications. If using PHP-FPM instead of Apache’s mod_php, set the following:
- php_enable_php_fpm:
falseSet totrueif using PHP-FPM.
You can configure Apache to work with PHP-FPM using the geerlingguy.apache-php-fpm role.
- php_fpm_pools: Configuration for PHP-FPM pools, such as user, group, listening socket, and process management settings.
php.ini settings
- php_use_managed_ini:
trueManagephp.iniautomatically. Set tofalseif you want to manage your ownphp.inifile.
OpCache-related Variables
OpCache optimizes PHP performance. Set the following variables for versions 5.5 or greater:
- php_opcache_zend_extension:
"opcache.so" - php_opcache_enable:
"1" - php_opcache_memory_consumption:
"96" - php_opcache_max_accelerated_files:
"4096"
Make sure you have enough memory allocated in OpCache to optimize performance.
APCu-related Variables
- php_enable_apc:
trueEnable APCu for caching. If set to false, related settings won't have an effect.
Installing from Source
If you need a specific or latest version of PHP, you can install it from source:
php_install_from_source:
falseSet totrueto install PHP from source.php_source_version:
"master"Set various parameters for cloning and compiling the 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 by Jeff Geerling in 2014.
PHP for RedHat/CentOS/Fedora/Debian/Ubuntu.
ansible-galaxy install apham0001.php