aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-06-13 15:26:25 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2023-06-13 15:26:31 +0200
commit3014df137e2c49d85e7296bf0ac777b83f4e255f (patch)
tree9ee8c7def7146fd99687a07f403c9e1a97f7f28c
downloadphp_fpm-3014df137e2c49d85e7296bf0ac777b83f4e255f.tar.gz
php_fpm-3014df137e2c49d85e7296bf0ac777b83f4e255f.tar.xz
Initial commit.HEADmaster
-rw-r--r--README.md6
-rw-r--r--files/fastcgi-php.conf51
-rw-r--r--manifests/init.pp23
-rw-r--r--manifests/nginx.pp35
-rw-r--r--manifests/nginx/setup.pp28
-rw-r--r--metadata.json37
-rw-r--r--pdk.yaml2
7 files changed, 182 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..0a6bdc1
--- /dev/null
+++ b/README.md
@@ -0,0 +1,6 @@
+PHP FPM
+=======
+
+Optional Dependencies
+---------------------
+- puppet-nginx
diff --git a/files/fastcgi-php.conf b/files/fastcgi-php.conf
new file mode 100644
index 0000000..10ef975
--- /dev/null
+++ b/files/fastcgi-php.conf
@@ -0,0 +1,51 @@
+# File borrowed from Debian nginx package
+#
+# Copyright: 2007-2009, Fabio Tranchitella <kobold@debian.org>
+# 2008, Jose Parrella <joseparrella@cantv.net>
+# 2009-2014, Kartik Mistry <kartik@debian.org>
+# 2010-2014, Michael Lustfield <michael@lustfield.net>
+# 2011 Dmitry E. Oboukhov <unera@debian.org>
+# 2011-2013, Cyril Lavier <cyril.lavier@davromaniak.eu>
+# 2013-2016, Christos Trochalakis <ctrochalakis@debian.org>
+# 2019-2020, Thomas Ward <teward@ubuntu.com>
+# 2020, Ondřej Nový <onovy@debian.org>
+#
+# Licensed under BSD-2-clause
+#
+# All rights reserved.
+# .
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+# .
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# .
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# regex to split $uri to $fastcgi_script_name and $fastcgi_path
+fastcgi_split_path_info ^(.+?\.php)(/.*)$;
+
+# Check that the PHP script exists before passing it
+try_files $fastcgi_script_name =404;
+
+# Bypass the fact that try_files resets $fastcgi_path_info
+# see: http://trac.nginx.org/nginx/ticket/321
+set $path_info $fastcgi_path_info;
+fastcgi_param PATH_INFO $path_info;
+
+fastcgi_index index.php;
+include fastcgi.conf;
diff --git a/manifests/init.pp b/manifests/init.pp
new file mode 100644
index 0000000..781458a
--- /dev/null
+++ b/manifests/init.pp
@@ -0,0 +1,23 @@
+# @summary Installs and starts php-fpm
+#
+# TODO manage configuration file, /etc/php/php-fpm.conf
+#
+# @param package_name
+# Name of the system package to install
+# @param service_name
+# Name of the system service
+# @param socket_path
+# Socket on which to listen. Currently doesn't set it itself, but
+# must instead be set to match what the system expects.
+class php_fpm (
+ String $package_name = 'php-fpm',
+ String $service_name = 'php-fpm',
+ String $socket_path = '/run/php/php-fpm.sock',
+) {
+ ensure_packages([$package_name])
+
+ service { $service_name:
+ ensure => 'running',
+ enable => 'true',
+ }
+}
diff --git a/manifests/nginx.pp b/manifests/nginx.pp
new file mode 100644
index 0000000..f2f75b2
--- /dev/null
+++ b/manifests/nginx.pp
@@ -0,0 +1,35 @@
+# @summary Configures an nginx location for php-fpm
+#
+# Sets up an nginx::resource::location resource forwarding .php files
+# to php-fpm.
+#
+# @param server
+# Nginx server the resource should be attached to.
+# @param location_title
+# String used as the name of the location resoruce. Will be
+# prefixed with "php-fpm - nginx - ". Allows multiple php locations
+# on the same server.
+# @param location
+# Maps to nginx's location attribute.
+# @param ensure
+# @param conf
+# Extra configuration passed along to `nginx::resource::location`.
+define php_fpm::nginx (
+ String $server,
+ String $location_title = $name,
+ String $location = '~ \.php',
+ Enum['absent', 'present'] $ensure = 'present',
+ Hash[String, Any] $conf = {},
+) {
+ include php_fpm::nginx::setup
+
+ nginx::resource::location { "php-fpm - nginx - ${location_title}":
+ ensure => $ensure,
+ server => $server,
+ location => $location,
+ index_files => [],
+ fastcgi => "unix:${php_fpm::socket_path}",
+ fastcgi_params => "${nginx::conf_dir}/snippets/fastcgi-php.conf",
+ * => $conf,
+ }
+}
diff --git a/manifests/nginx/setup.pp b/manifests/nginx/setup.pp
new file mode 100644
index 0000000..d3c9434
--- /dev/null
+++ b/manifests/nginx/setup.pp
@@ -0,0 +1,28 @@
+# @summary Prepares nginx resources
+#
+# Creates all nessesary files for php_fpm::nginx to work.
+#
+# @param filename
+# Local filename to use for extra fastcgi php params.
+# @param snippets_dir
+# Directory in which nginx snippets are stored in.
+# @param manage_snippets_dir
+# Should we manage the snippets directory.
+# @api private
+class php_fpm::nginx::setup (
+ String $filename = 'fastcgi-php.conf',
+ String $snippets_dir = "${nginx::conf_dir}/snippets",
+ Boolean $manage_snippets_dir = false,
+) {
+ include nginx
+
+ if $manage_snippets_dir {
+ file { $snippets_dir:
+ ensure => directory,
+ }
+ }
+
+ file { "${snippets_dir}/${filename}":
+ source => "puppet:///modules/${module_name}/fastcgi-php.conf",
+ }
+}
diff --git a/metadata.json b/metadata.json
new file mode 100644
index 0000000..d4c9462
--- /dev/null
+++ b/metadata.json
@@ -0,0 +1,37 @@
+{
+ "name": "HugoNikanor-php_fpm",
+ "version": "0.1.0",
+ "author": "HugonNikanor",
+ "summary": "Configures PHP-FPM",
+ "license": "Apache-2.0",
+ "source": "https://git.hornquist.se/puppet/hugonikanor-letsencrypt",
+ "operatingsystem_support": [
+ {
+ "operatingsystem": "Archlinux"
+ },
+ {
+ "operatingsystem": "Ubuntu",
+ "operatingsystemrelease": [
+ "22"
+ ]
+ }
+ ],
+ "requirements": [
+ {
+ "name": "puppet",
+ "version_requirement": ">= 6.21.0 < 8.0.0"
+ }
+ ],
+ "dependencies": [
+ ],
+ "tags": [
+ "php",
+ "fastcgi",
+ "fcgi",
+ "fpm",
+ "php-fpm"
+ ],
+ "pdk-version": "2.5.0",
+ "template-url": "pdk-default#2.5.0",
+ "template-ref": "tags/2.5.0-0-g369d483"
+}
diff --git a/pdk.yaml b/pdk.yaml
new file mode 100644
index 0000000..4bef4bd
--- /dev/null
+++ b/pdk.yaml
@@ -0,0 +1,2 @@
+---
+ignore: []