Fixes #55 and Fixes #43: Extra basic configuration for PHP-FPM.

This commit is contained in:
Jeff Geerling 2016-01-14 20:47:25 -06:00
parent bb0c7e7bbc
commit f35d2a2b53
7 changed files with 55 additions and 15 deletions

View File

@ -16,7 +16,7 @@ Available variables are listed below, along with default values (see `defaults/m
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 may also need to install `libapache2-mod-php5` (or a similar package depending on PHP version) if you want to use `mod_php` with Apache._
_Note: If you're using Debian/Ubuntu, you may also need to install `libapache2-mod-fastcgi` (for cgi/PHP-FPM) or `libapache2-mod-php5` (or a similar package depending on PHP version) if you want to use `mod_php` with Apache._
php_enable_webserver: true
@ -44,7 +44,14 @@ When using this role with PHP running as `php-fpm` instead of as a process insid
You will also need to override the default `php_packages` list and add `php-fpm` (RedHat/CentOS) or `php5-fpm` (Debian/Ubuntu) to the list.
This role does not manage fpm-specific www pool configuration (found in `/etc/php-fpm.d/www.conf` on RedHat/CentOS and `/etc/php5/fpm/pool.d/www.conf` on Debian/Ubuntu), but rather allows you to manage those files on your own. If you change that file, remember to notify the `restart php-fpm` handler so PHP picks up the new settings once in place. Settings like `pm.max_children` and other `pm.*` settings can have a dramatic impact on server performance, and should be tuned specifically for each application and server configuration.
php_fpm_listen: "127.0.0.1:9000"
php_fpm_listen_allowed_clients: "127.0.0.1"
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
Specific settings inside the default `www.conf` PHP-FPM pool. If you'd like to manage additional settings, you can do so either by replacing the file with your own template or using `lineinfile` like this role does inside `tasks/configure.yml`.
### php.ini settings

View File

@ -5,8 +5,14 @@ php_enablerepo: ""
# Set this to false if you're not using PHP with Apache/Nginx/etc.
php_enable_webserver: true
# Start and enable the PHP fpm service.
# PHP-FPM configuration.
php_enable_php_fpm: false
php_fpm_listen: "127.0.0.1:9000"
php_fpm_listen_allowed_clients: "127.0.0.1"
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
# The executable to run when calling PHP from the command line.
php_executable: "php"

34
tasks/configure-fpm.yml Normal file
View File

@ -0,0 +1,34 @@
---
- name: Define php_fpm_daemon.
set_fact:
php_fpm_daemon: "{{ __php_fpm_daemon }}"
when: php_fpm_daemon is not defined
- name: Configure php-fpm pool (if enabled).
lineinfile:
dest: "{{ php_fpm_pool_conf_path }}"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
state: present
with_items:
- regexp: "^listen.?=.+$"
line: "listen = 127.0.0.1:9000"
- regexp: '^listen\.allowed_clients.?=.+$'
line: "listen.allowed_clients = {{ php_fpm_listen_allowed_clients }}"
- regexp: '^pm\.max_children.?=.+$'
line: "pm.max_children = {{ php_fpm_pm_max_children }}"
- regexp: '^pm\.start_servers.?=.+$'
line: "pm.start_servers = {{ php_fpm_pm_start_servers }}"
- regexp: '^pm\.min_spare_servers.?=.+$'
line: "pm.min_spare_servers = {{ php_fpm_pm_min_spare_servers }}"
- regexp: '^pm\.max_spare_servers.?=.+$'
line: "pm.max_spare_servers = {{ php_fpm_pm_max_spare_servers }}"
when: php_enable_php_fpm
notify: restart php-fpm
- name: Ensure php-fpm is started and enabled at boot (if configured).
service:
name: "{{ php_fpm_daemon }}"
state: started
enabled: yes
when: php_enable_php_fpm

View File

@ -39,15 +39,3 @@
mode: 0644
when: php_opcache_enable
notify: restart webserver
- name: Define php_fpm_daemon.
set_fact:
php_fpm_daemon: "{{ __php_fpm_daemon }}"
when: php_fpm_daemon is not defined
- name: Ensure php-fpm is started and enabled at boot (if configured).
service:
name: "{{ php_fpm_daemon }}"
state: started
enabled: yes
when: php_enable_php_fpm

View File

@ -57,3 +57,6 @@
# Configure PHP.
- include: configure.yml
# Configure PHP-FPM.
- include: configure-fpm.yml

View File

@ -20,3 +20,4 @@ __php_extension_conf_path: "{{ __php_conf_path }}/conf.d"
__php_apc_conf_filename: 20-apcu.ini
__php_opcache_conf_filename: 05-opcache.ini
__php_fpm_daemon: php5-fpm
php_fpm_pool_conf_path: "/etc/php5/fpm/pool.d/www.conf"

View File

@ -23,3 +23,4 @@ php_extension_conf_path: /etc/php.d
__php_apc_conf_filename: 50-apc.ini
__php_opcache_conf_filename: 10-opcache.ini
__php_fpm_daemon: php-fpm
php_fpm_pool_conf_path: "/etc/php-fpm.d/www.conf"