net2grid.php
Ansible Role: PHP
This role installs PHP on servers running RedHat/CentOS or Debian/Ubuntu.
Requirements
If you have an older version of Ubuntu or RHEL with outdated PHP, you will need to use a repository or PPA that has a newer PHP version since this role only works with versions of PHP that are currently supported.
Role Variables
Here are the available variables and their default values (see defaults/main.yml
):
php_packages:
[]
- List of PHP packages to install (defaults are OS-specific). You might want to install common packages like
php
,php-cli
,php-devel
, andphp-pdo
, and you can add others likephp-gd
for image handling.
- List of PHP packages to install (defaults are OS-specific). You might want to install common packages like
php_packages_extra:
[]
- Additional PHP packages to install without changing the default list.
php_enable_webserver:
true
- Leave this as is if using PHP with a web server (like Apache or Nginx). Set to
false
if you’re using PHP for server-side tasks or apps that don't need a web server.
- Leave this as is if using PHP with a web server (like Apache or Nginx). Set to
php_webserver_daemon:
"httpd"
- Default HTTP server daemon (for Apache). Change this if using a different server (like
nginx
).
- Default HTTP server daemon (for Apache). Change this if using a different server (like
php_enablerepo:
""
- For RedHat/CentOS only. List any extra repositories here to use their PHP versions (e.g.
remi-php70,epel
).
- For RedHat/CentOS only. List any extra repositories here to use their PHP versions (e.g.
php_packages_state:
"present"
- Set to
"latest"
if you want to upgrade to the latest PHP version when using additional repositories.
- Set to
php_install_recommends:
true
- For Debian/Ubuntu only. Set to
false
if you do not want to install recommended packages.
- For Debian/Ubuntu only. Set to
php_executable:
"php"
- The command used to run PHP from the command line. Change it only if necessary.
PHP-FPM
PHP-FPM (FastCGI Process Manager) helps manage PHP applications effectively. To use PHP-FPM, set:
- php_enable_php_fpm:
false
(change totrue
if using PHP-FPM).
You can configure useful settings for FPM, like:
- php_fpm_listen:
"127.0.0.1:9000"
- php_fpm_pm_max_children:
50
- php_fpm_pm_start_servers:
5
- php_fpm_pm_min_spare_servers:
5
- php_fpm_pm_max_spare_servers:
5
php.ini Settings
- php_use_managed_ini:
true
- By default, this role manages the
php.ini
settings. Set it tofalse
if you want to manage your own.
- By default, this role manages the
Various default settings include:
- php_memory_limit:
"256M"
- php_max_execution_time:
"60"
- php_post_max_size:
"32M"
- php_display_errors:
"Off"
OpCache Variables
OpCache improves PHP performance. Settings take effect if PHP version is 5.5 or above:
- php_opcache_enable:
"1"
- php_opcache_memory_consumption:
"96"
- php_opcache_max_accelerated_files:
"4096"
APCu Variables
APCu caching can be enabled with:
- php_enable_apc:
true
- php_apc_shm_size:
"96M"
Source Installation
If you want a specific PHP version, you can compile it from source:
- php_install_from_source:
false
(set totrue
to compile). - php_source_version:
"master"
(the version you want).
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 net2grid.php