Ansible Role php
This role installs and configures PHP (and PHP-FPM) on the system, optionally with additional modules.
Note that this role does NOT let you specify a particular PHP version. It simply installs the latest available PHP version from the repos configured in the system. If you want or need to install a specific or the latest PHP version available, use the linuxfabrik.lfops.repo_remi beforehand.
This role is compatible with the following PHP versions:
7.2
7.3
7.4
8.0
8.1
8.2
Rules of thumb:
Specify memory values in MB (M).
memory_limit
should be larger thanpost_max_size
.post_max_size
can stay at16M
, even if you haveupload_max_filesize
>10000M
for example.If disabling
opcache.validate_timestamps
,opcache.revalidate_freq
is ignored.
This role never exposes to the world that PHP is installed on the server, no matter what.
Optional Requirements
Enable the Remi’s RPM repository to get newer versions of PHP. This can be done using the linuxfabrik.lfops.repo_remi role.
Optional Role Variables
Variable |
Description |
Default Value |
---|---|---|
|
Enables or disables the php-fpm service, analogous to |
|
|
List of dictionaries containing PHP-FPM pools. Subkeys: |
|
|
List of dictionaries containing additional PHP modules that should be installed via the standard package manager. Subkeys: |
* |
Example:
# optional
php__fpm_service_enabled: true
php__fpm_pools__host_var:
- name: 'librenms'
user: 'librenms'
group: 'librenms'
raw: |-
env[PATH] = /usr/local/bin:/usr/bin:/bin
php__modules__host_var:
- name: 'php-mysqlnd'
state: 'present'
php__ini_*
Config Directives
Variables for php.ini
directives and their default values, defined and supported by this role.
Role Variable |
Documentation |
Default Value |
---|---|---|
|
The default timezone used by all date/time functions. php.net |
|
|
|
|
|
This determines whether errors should be printed to the screen as part of the output or if they should be hidden from the user. This is a feature to support your development and should never be used on production systems (e.g. systems connected to the internet). php.net |
|
|
Even when display_errors is on, errors that occur during PHP’s startup sequence are not displayed. It’s strongly recommended to keep php.net |
|
|
Set the error reporting level. php.net |
|
|
This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30. When running PHP from the command line the default setting is 0. php.net |
|
|
The maximum number of files allowed to be uploaded simultaneously. php.net |
|
|
This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET. Timing begins at the moment PHP is invoked at the server and ends when execution begins. The default setting is -1, which means that max_execution_time is used instead. Set to 0 to allow unlimited time. php.net |
|
|
How many input variables may be accepted (limit is applied to |
|
|
This sets the maximum amount of memory in bytes that ONE RUNNING SCRIPT is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1. Again: PHP memory_limit is per-script, just as a highway’s speed limit is per-vehicle. php.net |
|
|
A blacklist file is a text file containing the names of files that should not be accelerated, one per line. Wildcards are allowed, and prefixes can also be provided. Lines starting with a semi-colon are ignored as comments. php.net |
|
|
Enables the opcode cache. When disabled, code is not optimised or cached.php.net |
|
|
Enables the opcode cache for the CLI version of PHP. php.net |
|
|
|
|
|
The amount of memory used to store interned strings, in megabytes. php.net |
|
|
The maximum number of keys (and therefore scripts) in the OPcache hash table. The actual value ;used will be the first number in the set of prime numbers { 223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987, 262237, 524521, 1048793 } that is greater than or equal to the configured value. php.net |
|
|
The size of the shared memory storage used by OPcache, in megabytes. The minimum permissible value is „8“, which is enforced if a smaller value is set. php.net |
|
|
How often to check script timestamps for updates, in seconds. 0 will result in OPcache checking for updates on every request. php.net |
|
|
If disabled, all documentation comments will be discarded from the opcode cache to reduce the size of the optimised code. Disabling this configuration directive may break applications and frameworks that rely on comment parsing for annotations. php.net |
|
|
If enabled, OPcache will check for updated scripts every opcache.revalidate_freq seconds. When this directive is disabled, you must reset OPcache manually via opcache_reset(), opcache_invalidate() or by restarting the Web server for changes to the filesystem to take effect. php.net |
|
|
Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize. php.net |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The maximum size of an uploaded file. php.net |
|
Note that setting php__ini_opcache_huge_code_pages__group_var
or php__ini_opcache_huge_code_pages__host_var
to 1
might require enabling the SELinux boolean httpd_execmem
on RHEL systems.
Example:
# optional
php__ini_max_execution_time__host_var: 3600
php__ini_max_file_uploads__host_var: 100
php__ini_memory_limit__host_var: '1024M'
php__ini_upload_max_filesize__host_var: '10000M'
PHP-FPM Pool Config Directives
Variables for php.ini
directives and their default values, defined and supported by this role.
Role Variable |
Documentation |
Default Value |
---|---|---|
|
List defining pool configuration. Possible options:
|
|
|
Choose how the process manager will control the number of child processes. |
|
|
The number of child processes to be created when pm is set to ‚static‘ and the maximum number of child processes when pm is set to ‚dynamic‘ or ‚ondemand‘. |
|
|
The desired maximum number of idle server processes. |
|
|
The desired minimum number of idle server processes. |
|
|
The number of child processes created on startup. |
|
Example:
# optional
php__fpm_pools__host_var:
- name: 'librenms'
user: 'librenms'
group: 'librenms'
raw: |-
env[PATH] = /usr/local/bin:/usr/bin:/bin
php__fpm_pool_conf_pm__host_var: 'dynamic'
php__fpm_pool_conf_pm_max_children__host_var: 50
php__fpm_pool_conf_pm_max_spare_servers__host_var: 35
php__fpm_pool_conf_pm_min_spare_servers__host_var: 5
php__fpm_pool_conf_pm_start_servers__host_var: 5