bodsch.php

Ansible 角色: php

用于在各种系统上安装 fpm-php 的 Ansible 角色。

仅受 geerlingguy 的启发。

根据 php_version 变量检测可用的 PHP 版本。

支持 PHP 7 和 8 版本,只要相应的版本可用。

ArchLinux 已经从其仓库中删除了 PHP 7 包!

GitHub Workflow Status GitHub issues GitHub release (latest by date) Ansible Downloads

需求与依赖

Ansible 集合

ansible-galaxy collection install bodsch.core

ansible-galaxy collection install --requirements-file collections.yml

操作系统

已测试

  • ArchLinux (仅支持 PHP 8!)
  • 基于 Debian 的系统
    • Debian 12
    • Ubuntu 22.04

基于 RedHat 的系统不再正式支持!可能可以工作,但不一定。

使用方法

# 选择您的版本!
php_version: "8"

php_packages_state: present

php_fpm_log_directory: /var/log/php-fpm
php_fpm_tmp_upload_directory: /tmp/php-fpm
php_fpm_socket_directory: /run/php

php_fpm_log_level: notice

php_enable_php_fpm: true

php_fpm_listen: "127.0.0.1:9000"
php_fpm_listen_allowed_clients: "127.0.0.1"
php_fpm_pm:
  max_children: 50
  start_servers: 5
  spare_servers:
    min: 5
    max: 5

php_use_managed_ini: true

php_expose_php: "On"
php_memory_limit: "256M"
php_max_execution_time: "60"
php_max_input_time: "60"
php_max_input_vars: "1000"
php_realpath_cache_size: "32K"

php_file_uploads: "On"
php_upload_max_filesize: "64M"
php_max_file_uploads: "20"

php_post_max_size: "32M"
php_date_timezone: "Europe/Berlin"
php_allow_url_fopen: "On"

php_sendmail_path: "/usr/sbin/sendmail -t -i"
php_output_buffering: "4096"
php_short_open_tag: "Off"
php_disable_functions: []

php_session_cookie_lifetime: 0
php_session_gc_probability: 1
php_session_gc_divisor: 1000
php_session_gc_maxlifetime: 1440
php_session_save_handler: files
php_session_save_path: ''
php_session_cache_expire: 180

php_error_reporting: "E_ALL & ~E_DEPRECATED & ~E_STRICT"
php_display_errors: "Off"
php_display_startup_errors: "Off"

php_packages: []

php_fpm_default_pool:
  delete: false
  name: www.conf

php_fpm_pools: []

# php 模块
php_modules: []

自定义包

要安装更多 PHP 包,可以在 php_packages 中列出。

例如:

php_packages:
  - php-ldap

这些包不需要版本信息,因为对于 RedHat 和 Remis 包来说是必要的。 该角色会确保包名称有效。

例如,php-ldap 在某些情况下可能变为 php73-php-ldap

php 池

php_fpm_pools:
  - name: worker-01
    user: "{{ php_fpm_pool_user }}"
    group: "{{ php_fpm_pool_group }}"
    listen.owner: "{{ php_fpm_pool_user }}"
    listen.group: "{{ php_fpm_pool_group }}"
    listen: "{{ php_fpm_socket_directory }}/$pool.sock"
    # 静态、动态或按需
    pm: ondemand
    pm.max_children: 10
    pm.start_servers: 4
    pm.min_spare_servers: 2
    pm.max_spare_servers: 6
    pm.status_path: /status

  - name: worker-02
    user: "{{ php_fpm_pool_user }}"
    group: "{{ php_fpm_pool_group }}"
    listen.owner: "{{ php_fpm_pool_user }}"
    listen.group: "{{ php_fpm_pool_group }}"
    listen: "{{ php_fpm_socket_directory }}/$pool.sock"
    pm: dynamic
    pm.max_children: 10
    pm.start_servers: 4
    pm.min_spare_servers: 2
    pm.max_spare_servers: 6
    pm.status_path: /status
    ping.path: /ping
    ping.response: pong
    access.log: "{{ php_fpm_log_directory }}/$pool_access.log"
    access.format: "%R - %n - %{HTTP_HOST}e - %u %t \"%m %r [%Q%q]\" %s %f %{mili}d %{kilo}M %C%%"
    chdir: /
    env:
      PATH: "/usr/local/bin:/usr/bin:/bin"
      TMPDIR: "{{ php_fpm_tmp_upload_diectory }}"
    php_admin_value:
      date.timezone: "Europe/Berlin"
      log_errors: 'on'
      max_execution_time: 300
      memory_limit: 512M
      upload_max_filesize: 32M

php 模块

php_modules:
  # gd
  - name: gd
    enabled: true
    priority: 20
    content: |
      extension=gd
  # OpCache 设置
  - name: opcache
    enabled: true
    priority: 10
    content: |
      zend_extension=opcache
      opcache.enable=1
      opcache.enable_cli=1
      opcache.memory_consumption=128
      opcache.interned_strings_buffer=16
      opcache.max_accelerated_files=10000
      opcache.max_wasted_percentage=5
      opcache.validate_timestamps=1
      opcache.revalidate_path=0
      opcache.revalidate_freq=1
      opcache.max_file_size=0
  # PDO mysql
  - name: pdo_mysql
    enabled: true
    priority: 20
    content: |
      extension=pdo_mysql

documentation 中可以找到一些从 php.ini 复制的模块配置。


贡献

请阅读 Contribution

开发,分支(Git 标签)

master 分支是我的工作马,包含“最新、热乎”的内容,可能会存在问题!

如果您想使用稳定的版本,请使用 标记版本


作者

  • Bodo Schulz

许可证

Apache

自由软件,太棒了!

关于项目

ansible role to install and configure php-fpm

安装
ansible-galaxy install bodsch.php
许可证
apache-2.0
下载
2.2k
拥有者
ex-developer (c, c++, php), ex-system administrator / engineer, keep-it-simple, monitoring, automation, system architect