From 3a460d9cadac6bdb4033b944e639ced5740d7da4 Mon Sep 17 00:00:00 2001 From: lhahn Date: Sun, 20 Aug 2023 11:14:00 +0200 Subject: [PATCH] Git initial commit --- LICENSE | 9 +++++++ README.md | 3 +++ defaults/main.yml | 46 +++++++++++++++++++++++++++++++++ handlers/main.yml | 5 ++++ meta/main.yml | 15 +++++++++++ tasks/main.yml | 66 +++++++++++++++++++++++++++++++++++++++++++++++ vars/main.yml | 53 +++++++++++++++++++++++++++++++++++++ 7 files changed, 197 insertions(+) create mode 100755 LICENSE create mode 100755 README.md create mode 100755 defaults/main.yml create mode 100755 handlers/main.yml create mode 100755 meta/main.yml create mode 100755 tasks/main.yml create mode 100755 vars/main.yml diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..2071b23 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100755 index 0000000..1d26b74 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# cloud-php + +Ansible role to provide php, e.g. used for nginx or wordpress. \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100755 index 0000000..912887c --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,46 @@ +--- +cloud_apps: /opt +cloud_storage: /opt/storage +cloud_stage: prod +cloud_update: false + + +php_version: 8.0 + +php_modules: [] + +php_memory_limit: 128M +php_upload_max_filesize: 2M +php_post_max_size: 8M + +php_opcache_interned_strings_buffer: 8 +php_opcache_save_comments: 1 +php_opcache_revalidate_freq: 2 +php_opcache_validate_timestamps: 1 + +# see: https://spot13.com/pmcalculator/ +php_pm_max_children: 102 +php_pm_start_servers: 25 +php_pm_min_spare_servers: 25 +php_pm_max_spare_servers: 76 + + +php_fpm_config: [] +# - key: upload_max_filesize +# value: 2M + +php_fpm_poolconf: [] +# - key: pm.max_children +# value: 102 + +php_fpm_poolconf_env: + - key: HOSTNAME + value: $HOSTNAME + - key: PATH + value: /usr/local/bin:/usr/bin:/bin + - key: TMP + value: /tmp + - key: TMPDIR + value: /tmp + - key: TEMP + value: /tmp \ No newline at end of file diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100755 index 0000000..d491444 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: restart php-fpm + service: + name: "php{{ php_version }}-fpm" + state: restarted \ No newline at end of file diff --git a/meta/main.yml b/meta/main.yml new file mode 100755 index 0000000..f6b376f --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,15 @@ +--- +galaxy_info: + role_name: php + namespace: hahn-cloud + author: Lars Hahn + company: OpenDevChain + license: MIT + description: Role to setup PHP; should be used in combination with an DB-, HTTP-Server. + platforms: + - name: Debian + versions: + - 11 + galaxy_tags: + - php +dependencies: [] diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100755 index 0000000..24b429b --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,66 @@ +--- +- name: install requirements for php repository + apt: + update_cache: yes + state: "{% if cloud_update | bool %}latest{% else %}present{% endif %}" + install_recommends: yes + pkg: + - apt-transport-https + - ca-certificates + - gnupg2 + - lsb-release + - libmagickcore-6.q16-6-extra # SVG for imagick php module + +- name: install PHP sury repository key + apt_key: + url: https://packages.sury.org/php/apt.gpg + state: present + +- name: install PHP sury repository + apt_repository: + repo: "deb https://packages.sury.org/php/ {{ ansible_distribution_release }} main" + state: present + +- name: install PHP and recommendations + apt: + update_cache: yes + state: "{% if cloud_update | bool %}latest{% else %}present{% endif %}" + install_recommends: yes + pkg: "{{ php_modules + php_modules_base }}" + +- name: configure PHP fpm + lineinfile: + path: "{{ php_path }}/fpm/php.ini" + regexp: '^(;|){{ item.key }} = ' + line: "{{ item.key }} = {{ item.value }}" + loop: "{{ php_fpm_config + php_fpm_config_default }}" + loop_control: + label: "{{ item.key }}" + notify: restart php-fpm + +- name: configure PHP fpm pool conf + lineinfile: + path: "{{ php_path }}/fpm/pool.d/www.conf" + regexp: '^(;|){{ item.key }} = ' + line: "{{ item.key }} = {{ item.value }}" + loop: "{{ php_fpm_poolconf + php_fpm_poolconf_default }}" + loop_control: + label: "{{ item.key }}" + notify: restart php-fpm + +- name: configure PHP fpm env pool conf + lineinfile: + path: "{{ php_path }}/fpm/pool.d/www.conf" + regexp: '^(;|)env\[{{ item.key }}\] = ' + line: "env[{{ item.key }}] = {{ item.value }}" + loop: "{{ php_fpm_poolconf_env }}" + loop_control: + label: "{{ item.key }}" + notify: restart php-fpm + +- name: configure PHP apcu availability + lineinfile: + path: "{{ php_path }}/mods-available/apcu.ini" + regexp: '^(;\s*|)apc.enable_cli=' + line: "apc.enable_cli=1" + notify: restart php-fpm \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml new file mode 100755 index 0000000..56a3ce6 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,53 @@ +--- +#a rather good selection for most apps +php_modules_base: + - "php{{ php_version }}-apcu" + - "php{{ php_version }}-bz2" + - "php{{ php_version }}-ctype" + - "php{{ php_version }}-curl" + - "php{{ php_version }}-dom" + - "php{{ php_version }}-fpm" + - "php{{ php_version }}-fileinfo" + - "php{{ php_version }}-gd" + - "php{{ php_version }}-gmp" + - "php{{ php_version }}-imagick" + - "php{{ php_version }}-intl" + - "php{{ php_version }}-mbstring" + - "php{{ php_version }}-memcached" + - "php{{ php_version }}-mysql" + - "php{{ php_version }}-pdo-pgsql" + - "php{{ php_version }}-posix" + - "php{{ php_version }}-redis" + - "php{{ php_version }}-simplexml" + - "php{{ php_version }}-xmlreader" + - "php{{ php_version }}-xmlwriter" + - "php{{ php_version }}-zip" + + +php_path: "/etc/php/{{ php_version }}" + +php_fpm_config_default: + - key: memory_limit + value: "{{ php_memory_limit }}" + - key: upload_max_filesize + value: "{{ php_upload_max_filesize }}" + - key: post_max_size + value: "{{ php_post_max_size }}" + - key: opcache.interned_strings_buffer + value: "{{ php_opcache_interned_strings_buffer }}" + - key: opcache.save_comments + value: "{{ php_opcache_save_comments }}" + - key: opcache.revalidate_freq + value: "{{ php_opcache_revalidate_freq }}" + - key: opcache.validate_timestamps + value: "{{ php_opcache_validate_timestamps }}" + +php_fpm_poolconf_default: + - key: pm.max_children + value: "{{ php_pm_max_children }}" + - key: pm.start_servers + value: "{{ php_pm_start_servers }}" + - key: pm.min_spare_servers + value: "{{ php_pm_min_spare_servers }}" + - key: pm.max_spare_servers + value: "{{ php_pm_max_spare_servers }}" \ No newline at end of file