php72_fpm on OpenBSD 6.4 doesn't work by default: How to fix
Tags: openbsd, php, phpfpm, troubleshooting
Published: 2018-11-24 13:54:46

---
title: php72_fpm on OpenBSD 6.4 doesn't work by default: How to fix
published: true
description: In OpenBSD, installing PHP by pkg_add (of ports) is followed by installing php-fpm automatically. (It's nice.) However, it doesn't work as daemon out of the box now in case of PHP 7.2 (and 7.1). The problem can be fixed by adding its pool definition manually. This post will show how to do it.
tags: openbsd, php, phpfpm, troubleshooting
cover_image: https://thepracticaldev.s3.amazonaws.com/i/7wg0yxqc8d4vxr6i3alz.jpg
canonical_url: https://obsd.solutions/en/blog/2018/11/24/php72_fpm-on-openbsd-64-doesnt-work-by-default-how-to-fix/index.html
---

*\* The cover image is originally by [pixel2013](https://pixabay.com/en/users/pixel2013-2364555) and edited with great appreciation.*

## Summary 

In OpenBSD, installing PHP by `pkg_add` (of `ports`) is [followed by installing php-fpm automatically](https://github.com/openbsd/ports/commit/5b4e47f8261f71072cc15e7f1e23cb6fafb81f9e). (It's nice 😃)

However, it doesn't work as daemon out of the box now in case of PHP 7.2 (and 7.1).
The problem can be fixed by **adding its pool definition manually**.
This post will show how to do it.

Besides, it is [fixed in the `-current` version](https://github.com/openbsd/ports/commit/8c40c6d028d47ad4d1ecbb2e88c1a50d654230f0).

*\* Note: The above links are to GitHub commits, but [The version control system OpenBSD actually uses is CVS](https://www.openbsd.org/faq/faq5.html#Flavors).*

### Environment

- OS: OpenBSD 6.4 amd64
- PHP version: 7.2 

<center>✿ ✿ ✿</center>

## A Problem

OpenBSD 6.4 has 4 versions of PHP:

```shell-session
# pkg_add php
quirks-3.16 signed on 2018-10-12T15:26:25Z
Ambiguous: choose package for php
a       0: <None>
        1: php-5.6.38p0
        2: php-7.0.32p1
        3: php-7.1.22
        4: php-7.2.10
Your choice:
```

[According to their support terms](http://php.net/supported-versions.php), PHP 5.6 is almost no longer safe.
So I choose PHP 7.*, especially 7.2:

```shell-session
Your choice: 4
php-7.2.10: ok
```

As a result, these files are created in `/etc`:

```shell-session
$ ls /etc/php*
/etc/php-7.2.ini    /etc/php-fpm.conf

/etc/php-7.2:

/etc/php-7.2.sample:
opcache.ini
```

Sadly, `php72_fpm` in `php-7.2.10` doesn't work by default:

```shell-session
# rcctl -d start php72_fpm
doing _rc_parse_conf
...
php72_fpm_flags empty, using default ><
doing _rc_parse_conf /var/run/rc.d/php72_fpm
doing _rc_quirks
doing rc_check
php72_fpm
doing rc_start
doing _rc_wait start
doing rc_check
[10-Nov-2018 23:32:18] WARNING: Nothing matches the include pattern '/etc/php-fpm.d/*.conf' from /etc/php-fpm.conf at line 125.
[10-Nov-2018 23:32:18] ERROR: No pool defined. at least one pool section must be specified in config file
[10-Nov-2018 23:32:18] ERROR: failed to post process the configuration
[10-Nov-2018 23:32:18] ERROR: FPM initialization failed
doing _rc_rm_runfile
(failed)
```

### The Reason

It is because of the lack of "Pool Definintions".

The description is at the bottom of `/etc/php-fpm.ini`:

```config
;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;

; Multiple pools of child processes may be started with different listening
; ports and different management options.  The name of the pool will be
; used in logs and stats. There is no limitation on the number of pools which
; FPM can handle. Your system will tell you anyway :)

; Include one or more files. If glob(3) exists, it is used to include a bunch of
; files from a glob(3) pattern. This directive can be used everywhere in the
; file.
; Relative path can also be used. They will be prefixed by:
;  - the global prefix if it's been set (-p argument)
;  - /usr/local otherwise
include=/etc/php-fpm.d/*.conf
```

But there is no `/etc/php-fpm.d/*.conf`.

### The Solution

Make the directory and the file manually:

```shell-session
# mkdir /etc/php-fpm.d
# touch /etc/php-fpm.d/default.conf
```

What should be written in `/etc/php-fpm.d/default.conf`?
We can get it by installing (and uninstalling 😜) PHP 7.0 (`php-7.0.32p1`) package.
Its `/etc/php-fpm.conf` includes the desired pool definition.

The essence of the definition is like this:

```config
;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;

[www]
user = www
group = www
listen = /var/www/run/php-fpm.sock
listen.owner = www
listen.group = www
listen.mode = 0660
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
chroot = /var/www
```

Also [here](https://gist.github.com/nabbisen/4f55fa3889010d1121ac2e3b0376fe6a) is the full version as Gist (423 lines with comments).

Writing in `/etc/php-fpm.d/default.conf`, the preparation is finished.
The result is:

```shell-session
# rcctl start php72_fpm
(ok)
```

OK 😆

<center>✿ ✿ ✿</center>

Happy serving 🕊