php72_fpm on OpenBSD 6.4 doesn't work by default: How to fix

( modified )


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.

Besides, it is fixed in the -current version.

* Note: The above links are to GitHub commits, but The version control system OpenBSD actually uses is CVS.


  • OS: OpenBSD 6.4 amd64
  • PHP version: 7.2
✿ ✿ ✿


A Problem

OpenBSD 6.4 has 4 versions of PHP:

# 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, PHP 5.6 is almost no longer safe. So I choose PHP 7.*, especially 7.2:

Your choice: 4
php-7.2.10: ok

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

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



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

# 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
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

The Reason

It is because of the lack of “Pool Definintions”.

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

; 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

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

The Solution

Make the directory and the file manually:

# 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:

; Pool Definitions ;

user = www
group = www
listen = /var/www/run/php-fpm.sock
listen.owner = www = 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 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:

# rcctl start php72_fpm

OK 😆

✿ ✿ ✿

Happy serving 🕊

Comments or feedbacks are welcomed and appreciated.