From d18c93563d9fbbdf63936bb8f73fa73320427ecd Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Tue, 30 Jan 2018 14:56:35 +0100 Subject: [PATCH 01/10] php.ng.apache2: FreeBSD support --- php/ng/apache2/files/mod_php.conf.jinja | 14 ++++++++++++++ php/ng/apache2/ini.sls | 2 +- php/ng/apache2/init.sls | 7 +++---- php/ng/apache2/install.sls | 16 ++++++++++++++++ php/ng/map.jinja | 14 ++++++++++++-- pillar.example | 4 ++++ 6 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 php/ng/apache2/files/mod_php.conf.jinja diff --git a/php/ng/apache2/files/mod_php.conf.jinja b/php/ng/apache2/files/mod_php.conf.jinja new file mode 100644 index 0000000..9c70790 --- /dev/null +++ b/php/ng/apache2/files/mod_php.conf.jinja @@ -0,0 +1,14 @@ +{% from "php/ng/map.jinja" import php with context %} +{% from "php/ng/map.jinja" import phpng_version with context %} +{% set major = phpng_version.split('.')|first %} + +LoadModule php{{ major }}_module /usr/local/libexec/{{ php.lookup.apache2.name }}/libphp{{ major }}.so + +DirectoryIndex index.html index.php + + + SetHandler application/x-httpd-php + + + SetHandler application/x-httpd-php-source + diff --git a/php/ng/apache2/ini.sls b/php/ng/apache2/ini.sls index 00c5e22..8f01a8a 100644 --- a/php/ng/apache2/ini.sls +++ b/php/ng/apache2/ini.sls @@ -1,4 +1,4 @@ -# Manages the libapache2-mod-php5 main ini file +# Manages the main Apache2 ini file {% from "php/ng/map.jinja" import php with context %} {% from "php/ng/ini.jinja" import php_ini %} diff --git a/php/ng/apache2/init.sls b/php/ng/apache2/init.sls index 424da3d..2ebfb1e 100644 --- a/php/ng/apache2/init.sls +++ b/php/ng/apache2/init.sls @@ -1,8 +1,8 @@ -# Installs libapache2-mod-php5 package and manages the associated php.ini on os Debian -{% if grains['os_family'] == "Debian" %} - include: +{% if grains['os_family'] in ["Debian", "FreeBSD"] %} - php.ng.apache2.install +{% endif %} #END: os = Debian|FreeBSD +{% if grains['os_family'] == "Debian" %} - php.ng.apache2.ini extend: @@ -10,5 +10,4 @@ extend: file: - require: - sls: php.ng.apache2.install - {% endif %} #END: os = debian diff --git a/php/ng/apache2/install.sls b/php/ng/apache2/install.sls index 0f1ed17..46c7da4 100644 --- a/php/ng/apache2/install.sls +++ b/php/ng/apache2/install.sls @@ -1,2 +1,18 @@ +{% from "php/ng/map.jinja" import php with context %} + {% set state = 'apache2' %} {% include "php/ng/installed.jinja" %} + +{% if grains['os_family'] == "FreeBSD" %} +{{ php.lookup.apache2.module_config }}: + file.managed: + - source: salt://php/ng/apache2/files/mod_php.conf.jinja + - template: jinja +{% if salt['pillar.get']('php:ng:use_apache_formula', True) %} + - makedirs: true + - require_in: + - sls: apache + - watch_in: + - module: apache-restart +{% endif %} #END: use apache formula +{% endif %} #END: os = debian diff --git a/php/ng/map.jinja b/php/ng/map.jinja index da8b1b1..d4d768e 100644 --- a/php/ng/map.jinja +++ b/php/ng/map.jinja @@ -1,10 +1,12 @@ # -*- coding: utf-8 -*- # vim: ft=jinja +{%- set phpng_version = salt['pillar.get']('php:ng:version', '7.0')|string %} +{%- set freebsd_phpng_version = phpng_version.replace('.', '') %} + {%- if salt['grains.get']('os') == "Ubuntu" %} {%- set use_external_repo = salt['pillar.get']('php:use_external_repo', False) %} {%- if use_external_repo %} - {%- set phpng_version = salt['pillar.get']('php:ng:version', '7.0')|string %} {%- if salt['grains.get']('osrelease')|string >= '16.04' %} {%- set php = salt['pillar.get']('php:ng', { 'lookup': salt['grains.filter_by']({ @@ -1767,7 +1769,6 @@ {%- endif %} {%- endif %} {%- elif salt['grains.get']('os') == "Debian" %} - {%- set phpng_version = salt['pillar.get']('php:ng:version', '7.0')|string %} {%- if phpng_version|string == '5' %} {%- set confdir = '/etc/php5' %} {%- else %} @@ -2386,6 +2387,15 @@ 'ini': '/etc/php/conf.d/xcache.ini', }, }, + 'FreeBSD': { + 'apache2': { + 'module_config': '/usr/local/etc/apache24/modules.d/050_mod_php.conf', + 'name': 'apache24', + }, + 'pkgs': { + 'apache2': 'mod_php' + freebsd_phpng_version, + }, + }, }), 'fpm': { 'service': { diff --git a/pillar.example b/pillar.example index a2699e9..abea95d 100644 --- a/pillar.example +++ b/pillar.example @@ -171,3 +171,7 @@ php: - pcntl_wait 'CLI Server': cli_server_color: 'On' + + # When using php.ng.apache2 on FreeBSD: + # Set this to False if you're not using apache-formula + use_apache_formula: True From db45454657c412a2ec5049bca05a3bd6301dffc4 Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Thu, 15 Mar 2018 14:28:38 +0100 Subject: [PATCH 02/10] FreeBSD: set ini file paths --- php/ng/map.jinja | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/php/ng/map.jinja b/php/ng/map.jinja index d4d768e..f6c2343 100644 --- a/php/ng/map.jinja +++ b/php/ng/map.jinja @@ -2389,9 +2389,13 @@ }, 'FreeBSD': { 'apache2': { + 'ini': '/usr/local/etc/php.ini', 'module_config': '/usr/local/etc/apache24/modules.d/050_mod_php.conf', 'name': 'apache24', }, + 'cli': { + 'ini': '/usr/local/etc/php.ini' + }, 'pkgs': { 'apache2': 'mod_php' + freebsd_phpng_version, }, From 3a1e7ffa0ce623c3c983be97b0c47d12db64993e Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Thu, 15 Mar 2018 14:36:32 +0100 Subject: [PATCH 03/10] FreeBSD: local bin path --- php/ng/map.jinja | 1 + 1 file changed, 1 insertion(+) diff --git a/php/ng/map.jinja b/php/ng/map.jinja index f6c2343..1bd6ad6 100644 --- a/php/ng/map.jinja +++ b/php/ng/map.jinja @@ -2398,6 +2398,7 @@ }, 'pkgs': { 'apache2': 'mod_php' + freebsd_phpng_version, + 'local_bin': '/usr/local/bin', }, }, }), From 7ea03f350f1e429b6d463ce995450ea7ce603a94 Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Thu, 15 Mar 2018 14:43:35 +0100 Subject: [PATCH 04/10] FreeBSD: support for php.composer --- php/map.jinja | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/php/map.jinja b/php/map.jinja index 324e4ef..04c3bd1 100644 --- a/php/map.jinja +++ b/php/map.jinja @@ -417,5 +417,10 @@ 'xml_pkg': ['php5-xmlreader','php5-xmlwriter','php5-xmlrpc'], 'zip_pkg': 'php5-zip', }, + 'FreeBSD': { + 'local_bin': '/usr/local/bin', + 'composer_bin': 'composer', + 'temp_dir': '/tmp', + }, }, merge=salt['pillar.get']('php:lookup')) %} {%- endif %} From a12b0a1ba5fc8d90e50e558311ad94a10bcb2aa5 Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Thu, 15 Mar 2018 14:52:51 +0100 Subject: [PATCH 05/10] FreeBSD: PHP pkg (name + version) --- php/ng/map.jinja | 1 + 1 file changed, 1 insertion(+) diff --git a/php/ng/map.jinja b/php/ng/map.jinja index 1bd6ad6..0f932a5 100644 --- a/php/ng/map.jinja +++ b/php/ng/map.jinja @@ -2399,6 +2399,7 @@ 'pkgs': { 'apache2': 'mod_php' + freebsd_phpng_version, 'local_bin': '/usr/local/bin', + 'php': 'php' + freebsd_phpng_version, }, }, }), From 0e52813017b320b1ed57d5562ef7f14559482a96 Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Thu, 15 Mar 2018 15:00:02 +0100 Subject: [PATCH 06/10] README: added php.ng.composer --- README.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 9fbbdc8..f645db7 100644 --- a/README.rst +++ b/README.rst @@ -49,7 +49,7 @@ Disabled on opensuse not available, only fastcgi Installs the php-cli package. ``php.composer`` ------------ +---------------- Installs [composer](https://getcomposer.org) and keeps it updated. @@ -247,6 +247,11 @@ Manages the php-cli ini file. Installs the php-cli package. +``php.ng.composer`` +------------------- + +Installs [composer](https://getcomposer.org) and keeps it updated. + ``php.ng.curl`` --------------- From 9c5e04291846b7668aa5c6c70733d7ac0bc92d4f Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Thu, 15 Mar 2018 15:14:13 +0100 Subject: [PATCH 07/10] FreeBSD: support for php.ng.composer added - php.ng.filter - php.ng.hash - php.ng.openssl - php.ng.phar --- php/ng/composer.sls | 8 ++++++++ php/ng/filter.sls | 2 ++ php/ng/hash.sls | 2 ++ php/ng/map.jinja | 8 ++++++++ php/ng/openssl.sls | 2 ++ php/ng/phar.sls | 2 ++ 6 files changed, 24 insertions(+) create mode 100644 php/ng/filter.sls create mode 100644 php/ng/hash.sls create mode 100644 php/ng/openssl.sls create mode 100644 php/ng/phar.sls diff --git a/php/ng/composer.sls b/php/ng/composer.sls index 39e61e7..b20f7c4 100644 --- a/php/ng/composer.sls +++ b/php/ng/composer.sls @@ -12,6 +12,14 @@ include: - php.ng +{% if grains['os_family'] == 'FreeBSD' %} + - php.ng.filter + - php.ng.hash + - php.ng.json + - php.ng.mbstring + - php.ng.openssl + - php.ng.phar +{% endif %} get-composer: file.managed: diff --git a/php/ng/filter.sls b/php/ng/filter.sls new file mode 100644 index 0000000..46c155b --- /dev/null +++ b/php/ng/filter.sls @@ -0,0 +1,2 @@ +{% set state = 'filter' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/hash.sls b/php/ng/hash.sls new file mode 100644 index 0000000..aabf7a6 --- /dev/null +++ b/php/ng/hash.sls @@ -0,0 +1,2 @@ +{% set state = 'hash' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/map.jinja b/php/ng/map.jinja index 0f932a5..331e57a 100644 --- a/php/ng/map.jinja +++ b/php/ng/map.jinja @@ -2398,8 +2398,16 @@ }, 'pkgs': { 'apache2': 'mod_php' + freebsd_phpng_version, + 'composer_bin': 'composer', + 'filter': 'php' + freebsd_phpng_version + '-filter', + 'hash': 'php' + freebsd_phpng_version + '-hash', + 'json': 'php' + freebsd_phpng_version + '-json', 'local_bin': '/usr/local/bin', + 'mbstring': 'php' + freebsd_phpng_version + '-mbstring', + 'openssl': 'php' + freebsd_phpng_version + '-openssl', 'php': 'php' + freebsd_phpng_version, + 'phar': 'php' + freebsd_phpng_version + '-phar', + 'temp_dir': '/tmp', }, }, }), diff --git a/php/ng/openssl.sls b/php/ng/openssl.sls new file mode 100644 index 0000000..b37485b --- /dev/null +++ b/php/ng/openssl.sls @@ -0,0 +1,2 @@ +{% set state = 'openssl' %} +{% include "php/ng/installed.jinja" %} diff --git a/php/ng/phar.sls b/php/ng/phar.sls new file mode 100644 index 0000000..8a1b9ac --- /dev/null +++ b/php/ng/phar.sls @@ -0,0 +1,2 @@ +{% set state = 'phar' %} +{% include "php/ng/installed.jinja" %} From 4b6f0c689b3524487816cd088e35619e239056a6 Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Thu, 15 Mar 2018 17:41:07 +0100 Subject: [PATCH 08/10] Ubuntu: composer settings in map.jinja --- php/ng/map.jinja | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/php/ng/map.jinja b/php/ng/map.jinja index 331e57a..9558e6c 100644 --- a/php/ng/map.jinja +++ b/php/ng/map.jinja @@ -666,6 +666,7 @@ 'cgi': 'php-cgi', 'cli': 'php-cli', 'console-table': 'php-console-table', + 'composer_bin': 'composer', 'curl': 'php-curl', 'dev': 'php7.1-dev', 'fpm': 'php-fpm', @@ -679,6 +680,7 @@ 'intl': 'php-intl', 'json': 'php-json', 'ldap': 'php-ldap', + 'local_bin': '/usr/local/bin', 'mbstring': 'php-mbstring', 'mcrypt': 'php-mcrypt', 'memcache': 'php-memcache', @@ -704,6 +706,7 @@ 'suhosin': 'php', 'sybase': 'php-sybase', 'tcpdf': 'php-tcpdf', + 'temp_dir': '/tmp', 'tidy': 'php7.1-tidy', 'xcache': 'php', 'xdebug': 'php-xdebug', @@ -1030,6 +1033,7 @@ 'cgi': 'php-cgi', 'cli': 'php-cli', 'console-table': 'php-console-table', + 'composer_bin': 'composer', 'curl': 'php-curl', 'dev': 'php7.0-dev', 'fpm': 'php-fpm', @@ -1043,6 +1047,7 @@ 'intl': 'php-intl', 'json': 'php-json', 'ldap': 'php-ldap', + 'local_bin': '/usr/local/bin', 'mbstring': 'php-mbstring', 'mcrypt': 'php-mcrypt', 'memcache': 'php-memcache', @@ -1068,6 +1073,7 @@ 'suhosin': 'php', 'sybase': 'php-sybase', 'tcpdf': 'php-tcpdf', + 'temp_dir': '/tmp', 'tidy': 'php7.0-tidy', 'xcache': 'php', 'xdebug': 'php-xdebug', From fcb3d85f34c51637c630f885c2cf0d2d0f156521 Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Thu, 15 Mar 2018 20:54:19 +0100 Subject: [PATCH 09/10] composer update: fixed unless cmd by using -gt instead of > (Command was not working on Ubuntu 16.04.) Both Ubuntu's and RedHat's man pages of test list -gt, but not > as their 'greater than' operator. --- php/composer.sls | 2 +- php/ng/composer.sls | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/php/composer.sls b/php/composer.sls index bc9f999..b316f0d 100644 --- a/php/composer.sls +++ b/php/composer.sls @@ -41,7 +41,7 @@ install-composer: update-composer: cmd.run: - name: "{{ install_file }} selfupdate" - - unless: test $(date -d "60 days $({{ install_file }} --version | cut -d ' ' -f 4,5)" "+%s") \> $(date "+%s") + - unless: test $(date -d "60 days $({{ install_file }} --version | cut -d ' ' -f 4,5)" "+%s") -gt $(date "+%s") - cwd: {{ php.local_bin }} - env: - HOME: {{ salt_user_home }} diff --git a/php/ng/composer.sls b/php/ng/composer.sls index b20f7c4..a4b7442 100644 --- a/php/ng/composer.sls +++ b/php/ng/composer.sls @@ -49,7 +49,7 @@ install-composer: update-composer: cmd.run: - name: "{{ install_file }} selfupdate" - - unless: test $(date -d "60 days $({{ install_file }} --version | cut -d ' ' -f 4,5)" "+%s") \> $(date "+%s") + - unless: test $(date -d "60 days $({{ install_file }} --version | cut -d ' ' -f 4,5)" "+%s") -gt $(date "+%s") - cwd: {{ php.lookup.pkgs.local_bin }} - env: - HOME: {{ salt_user_home }} From 4cffd9c9e107f39b18c24934c4093dfea8876e20 Mon Sep 17 00:00:00 2001 From: Alexander Weidinger Date: Thu, 15 Mar 2018 22:12:48 +0100 Subject: [PATCH 10/10] composer update: date works differently on FreeBSD --- php/composer.sls | 4 ++++ php/ng/composer.sls | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/php/composer.sls b/php/composer.sls index b316f0d..935508e 100644 --- a/php/composer.sls +++ b/php/composer.sls @@ -41,7 +41,11 @@ install-composer: update-composer: cmd.run: - name: "{{ install_file }} selfupdate" +{% if grains['os_family'] == 'FreeBSD' %} + - unless: test $(date -v+60d -j -f "%Y-%m-%d %H:%M:%S" "$({{ install_file }} --version | cut -d ' ' -f 4,5)" "+%s") -gt $(date "+%s") +{% else %} - unless: test $(date -d "60 days $({{ install_file }} --version | cut -d ' ' -f 4,5)" "+%s") -gt $(date "+%s") +{% endif %} - cwd: {{ php.local_bin }} - env: - HOME: {{ salt_user_home }} diff --git a/php/ng/composer.sls b/php/ng/composer.sls index a4b7442..8f6221d 100644 --- a/php/ng/composer.sls +++ b/php/ng/composer.sls @@ -49,7 +49,11 @@ install-composer: update-composer: cmd.run: - name: "{{ install_file }} selfupdate" +{% if grains['os_family'] == 'FreeBSD' %} + - unless: test $(date -v+60d -j -f "%Y-%m-%d %H:%M:%S" "$({{ install_file }} --version | cut -d ' ' -f 4,5)" "+%s") -gt $(date "+%s") +{% else %} - unless: test $(date -d "60 days $({{ install_file }} --version | cut -d ' ' -f 4,5)" "+%s") -gt $(date "+%s") +{% endif %} - cwd: {{ php.lookup.pkgs.local_bin }} - env: - HOME: {{ salt_user_home }}