-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install and configure PHP automatically
Fixes #3
- Loading branch information
Showing
10 changed files
with
150 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
- name: Install PHP | ||
package: | ||
name: php-fpm | ||
state: latest | ||
|
||
# Ubuntu applies versioning to their PHP-FPM service names, because brain damage | ||
- name: Determine PHP-FPM unit name | ||
shell: | ||
cmd: "update-alternatives --query php | grep '^Best' | awk '{print $2}' | xargs basename | sed 's/php//'" | ||
changed_when: false | ||
register: noobient_nginx_php_check | ||
when: ansible_pkg_mgr == 'apt' | ||
|
||
- set_fact: | ||
noobient_nginx_php_ver: "{{ noobient_nginx_php_check.stdout_lines[0] }}" | ||
when: ansible_pkg_mgr == 'apt' | ||
|
||
- set_fact: | ||
noobient_nginx_php_unit: "php{% if ansible_pkg_mgr == 'apt' %}{{ noobient_nginx_php_ver }}{% endif %}-fpm.service" | ||
noobient_nginx_php_ini: "{% if ansible_pkg_mgr == 'dnf' %}/etc/php.ini{% else %}/etc/php/{{ noobient_nginx_php_ver }}/fpm/php.ini{% endif %}" | ||
noobient_nginx_fpm_conf: "{% if ansible_pkg_mgr == 'dnf' %}/etc/php-fpm.d/{% else %}/etc/php/{{ noobient_nginx_php_ver }}/fpm/pool.d/{% endif %}www.conf" | ||
noobient_nginx_fpm_sock: "{% if ansible_pkg_mgr == 'dnf' %}/run/php-fpm/www.sock{% else %}/run/php/php{{ noobient_nginx_php_ver }}-fpm.sock{% endif %}" | ||
|
||
- name: Set PHP options | ||
ini_file: | ||
path: "{{ noobient_nginx_php_ini }}" | ||
section: PHP | ||
option: "{{ item.option }}" | ||
value: "{{ item.value }}" | ||
mode: '0644' | ||
backup: true | ||
loop: | ||
- { option: 'post_max_size', value: '32M' } | ||
- { option: 'upload_max_filesize', value: '32M' } | ||
notify: Reload PHP | ||
|
||
- name: Set PHP-FPM options | ||
ini_file: | ||
path: "{{ noobient_nginx_fpm_conf }}" | ||
section: www | ||
option: "{{ item.option }}" | ||
value: "{{ item.value }}" | ||
mode: '0644' | ||
backup: true | ||
loop: | ||
- { option: 'user', value: "{{ nginx_account }}" } | ||
- { option: 'group', value: "{{ nginx_account }}" } | ||
- { option: 'pm', value: 'ondemand' } | ||
- { option: 'pm.process_idle_timeout', value: '10s' } | ||
#- { option: 'pm.max_requests', value: '' } | ||
#- { option: 'pm.max_children', value: '' } | ||
notify: Reload PHP | ||
|
||
- name: Enable PHP service | ||
systemd_service: | ||
name: "{{ noobient_nginx_php_unit }}" | ||
enabled: true | ||
state: started | ||
register: noobient_nginx_php_installed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
- name: Install PHP packages for WordPress | ||
package: | ||
name: "{{ packages }}" | ||
state: latest | ||
vars: | ||
packages: | ||
- php-pdo | ||
- php-gd | ||
- php-opcache | ||
- php-mysqlnd | ||
- php-json | ||
- php-mbstring | ||
- "php{% if ansible_pkg_mgr == 'apt' %}{{ noobient_nginx_php_ver }}{% endif %}-intl" | ||
- "php{% if ansible_pkg_mgr == 'dnf' %}-pecl{% else %}{{ noobient_nginx_php_ver }}{% endif %}-imagick" | ||
- "php{% if ansible_pkg_mgr == 'dnf' %}-pecl{% else %}{{ noobient_nginx_php_ver }}{% endif %}-zip" | ||
register: noobient_nginx_wp_installed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
- include_role: | ||
name: "{{ playbook_dir.split('/')[:-1] | last }}" | ||
vars: | ||
domain: foo0.com | ||
ssl_disabled: true | ||
mode: php | ||
|
||
# lineinfile fails for whatever reason | ||
- name: Redirect foo0.com requests to localhost # noqa no-changed-when | ||
shell: | ||
cmd: echo '127.0.0.1 foo0.com' >> /etc/hosts | ||
|
||
# for nginx_account | ||
- include_vars: | ||
file: ../vars/main.yml | ||
|
||
- name: Create document root | ||
file: | ||
path: /var/www/html/foo0.com | ||
state: directory | ||
recurse: true | ||
owner: "{{ nginx_account }}" | ||
group: "{{ nginx_account }}" | ||
mode: '0755' | ||
|
||
- name: Set up index with phpinfo() # noqa risky-file-permissions | ||
copy: | ||
dest: /var/www/html/foo0.com/index.php | ||
content: | | ||
<?php | ||
phpinfo(); | ||
?> | ||
# TODO On EL, cURL is installed by default. On top of that, on AlmaLinux 9, curl | ||
# is broken, and on Fedora, curl-minimal is broken. So just skip it altogether. | ||
# https://bugs.launchpad.net/tripleo/+bug/1953156 | ||
- name: Install cURL | ||
package: | ||
name: curl | ||
state: latest | ||
register: installed_curl | ||
when: installed_curl is not defined and ansible_os_family != 'RedHat' | ||
|
||
# gotta trigger manually, since nginx is only started via reload handler | ||
- meta: flush_handlers | ||
|
||
- name: Check phpinfo # noqa command-instead-of-module | ||
shell: | ||
cmd: curl --silent http://foo0.com | grep -A7 '>System <' | sed 's@ </td><td class="v">@{{ ":" }} @' | sed -e 's/<[^>]*>//g' | ||
changed_when: false | ||
register: curl_phpinfo_content | ||
|
||
- debug: | ||
msg: "{{ curl_phpinfo_content.stdout_lines }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters