PHP-FPM 7.2 on OpenBSD 6.4
Tags: php, phpfpm, httpd, openbsd
Published: 2018-12-13 15:43:31

---
title: PHP-FPM 7.2 on OpenBSD 6.4
published: true
description: PHP-FPM, PHP FastCGI Process Manager, is a part of PHP 7 package in OpenBSD packages nowadays. So installing PHP (php-7.? due to the version) comes with php7?_fpm automatically. I'll show you how to set it up in this post.
tags: php, phpfpm, httpd, openbsd
series: OpenBSD PHP-FPM
canonical_url: https://obsd.solutions/en/blog/2018/12/14/php-fpm-72-on-openbsd-64/index.html
---

### Summary

[PHP-FPM](https://php-fpm.org/), PHP FastCGI Process Manager, is a part of [PHP](https://www.php.net/) package in OpenBSD packages nowadays.
So installing PHP (`php-7.?` due to the version) comes with `php7?_fpm` automatically 💃
I'll show you how to set it up in this post 😃

##### Environment

- OS: OpenBSD 6.4 amd64
- PHP: 7.2

<center>✿ ✿ ✿</center>

### Installation

The first step is to install the PHP package:

```console
# pkg_add php
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: 
```

I chose "4" because of [each support term of the PHP versions](https://www.php.net/supported-versions.php).

Then these directories/files were made:

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

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

Well, the `.ini` files in `/etc/php-7.2.sample` are PHP extensions.
According to necessity, copy each of them to `/etc/php-7.2/` to activate the extensions:

```console
# ln -sf /etc/php-7.2.sample/%target-ini-files% /etc/php-7.2/
```

Also edit `/etc/php-7.2.ini` as needed.
For example:

```ini
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
;upload_max_filesize = 2M
upload_max_filesize = 5M
```

Besides, the manual is also installed as `/usr/local/share/doc/pkg-readmes/php-7.2` which declares:

> The main OpenBSD php packages include php-fpm, FastCGI Process Manager.
> This manages pools of FastCGI processes: starts/restarts them and maintains a minimum and maximum number of spare processes as configured. You can use rcctl(8) to enable php-fpm at boot, and start it at runtime:2
> 
>   rcctl enable php72_fpm
>   rcctl start php72_fpm

OK. We're ready.
Let's start daemon:

```console
# rcctl enable php72_fpm
# rcctl start php72_fpm
```

_\* Troubleshooting: If you fail to start `php72_fpm` (or `php71_fpm`), [it might be the known bug](https://obsd.solutions/en/blog/2018/11/24/fixing-php72_fpm-on-openbsd-64-doesnt-work-by-default/index.html)._

### Usage

Next, we have to prepare a web server.
So let's edit [`/etc/httpd.conf`](https://man.openbsd.org/httpd.conf.5) to add `fastcgi socket` in [SERVERS](https://man.openbsd.org/httpd.conf.5#SERVERS) sections like this:

```apache
types {
    include "/usr/share/misc/mime.types"
}

ext_addr="egress"

server "default" {
    listen on $ext_addr port 80

    root "/htdocs"
    directory index index.php

    location "*.php*" {
        fastcgi socket "/run/php-fpm.sock"
    }
}
```

Note that [`chroot`](https://man.openbsd.org/httpd.conf.5#chroot) works in this context.
Therefore, `fastcgi socket "/run/php-fpm.sock"` in `/etc/httpd.conf` actually means `fastcgi socket "/var/www/run/php-fpm.sock"`.
This is the same to that `root "/htdocs"` means `"/var/www/htdocs"`.

### Testing

Let's make `/var/www/htdocs/index.php` for testing like this:

```console
# echo "<?php phpinfo(); ?>" > /var/www/htdocs/index.php
# # delete the file above afterwards as needed
```

Then browsing your host will show you the whole phpinfo!

<center>✿ ✿ ✿</center>

Happy serving 💃