DEV Community

nabbisen
nabbisen

Posted on • Updated on • Originally published at obsd.solutions

PHP-FPM 7.2 on OpenBSD 6.4

Summary

PHP-FPM, PHP FastCGI Process Manager, is a part of PHP 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
✿ ✿ ✿

Installation

The first step is to install the PHP package:

# 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: 
Enter fullscreen mode Exit fullscreen mode

I chose "4" because of each support term of the PHP versions.

Then these directories/files were made:

$ 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
Enter fullscreen mode Exit fullscreen mode

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:

# ln -sf /etc/php-7.2.sample/%target-ini-files% /etc/php-7.2/
Enter fullscreen mode Exit fullscreen mode

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

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
;upload_max_filesize = 2M
upload_max_filesize = 5M
Enter fullscreen mode Exit fullscreen mode

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:

# rcctl enable php72_fpm
# rcctl start php72_fpm
Enter fullscreen mode Exit fullscreen mode

* Troubleshooting: If you fail to start php72_fpm (or php71_fpm), it might be the known bug.

Usage

Next, we have to prepare a web server.
So let's edit /etc/httpd.conf to add fastcgi socket in SERVERS sections like this:

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"
    }
}
Enter fullscreen mode Exit fullscreen mode

Note that 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:

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

Then browsing your host will show you the whole phpinfo!

✿ ✿ ✿

Happy serving 💃

Top comments (9)

Collapse
 
denkoss profile image
denkoss

Hello!
I configured httpd server, index.html is ok. Then I installed php with your manual and i have 500 internal error, when trying index.php to show in browser. What can be wrong?

Collapse
 
nabbisen profile image
nabbisen

Hello, denkoss. Hmmm... 500 internal error implies several possibility.

httpd -v -v -v -d after stopping the service will show the detail in the console:

# rcctl stop httpd
# httpd -v -v -v -d

Then try index.php with your browser. What is the output?

Collapse
 
denkoss profile image
denkoss

thx for answer.
default 192.168.0.105 - - [28/Mar/2020:17:37:58 +0300] "GET / HTTP/1.1" 500 0
server default, client 5 (1 active), 192.168.0.105:28051 -> 192.168.0.105, No such file or directory (500 Internal Server Error)

Thread Thread
 
nabbisen profile image
nabbisen

Thank you for your testing.
"No such file or directory" seems the answer.
I think it's possibly because of 1. wrong path, 2. permission (missing?) or 3. the effect of chroot.
chroot defaults to under /var/www. For example, fastcgi socket "/run/php-fpm.sock" in httpd.conf means it must be actually in /var/www/run/php-fpm.sock. It's the same to index.php.
Would you have any idea or clue?

Thread Thread
 
denkoss profile image
denkoss • Edited
  1. Wrong path - which one?
  2. I gave 777 to /var/www/htdocs/ for testing.
  3. yeah, /var/www/htdocs/index.php and /var/www/run/php-fpm.sock

httpd.conf:
ext_ip= ""
server "default" {
listen on $ext_ip port 80
root "/htdocs"
location "
.php" {
fastcgi socket "/run/php-fpm-sock"
}
directory index index.php
}
types {
include "/usr/share/misc/mime.types"
}

I think mistake is stuped, but cannt find it.(

Thread Thread
 
nabbisen profile image
nabbisen

Thanks for the detail.

fastcgi socket "/run/php-fpm-sock"

fastcgi socket "/run/php-fpm.sock" ?

I mean "-sock" should have been ".sock".


Well, empty string, aka your ext_ip, can be listened on. I didn't know it. Interesting.

Thread Thread
 
denkoss profile image
denkoss

I mean "-sock" should have been ".sock". - this is my stupid mistake.))now its work.
ext_ip not empty, its *, I dont know why it not showing here.
Thank you so much!

Thread Thread
 
nabbisen profile image
nabbisen • Edited

Great. You're welcome.

ext_ip not empty, its *, I dont know why it not showing here.

I've found the reason.
it is recognized with * of location "*.php" { as markdown Italic.

Collapse
 
leslieeeee profile image
Leslie

If you are a macOS user, ServBay.dev is worth to try. You don't need to spend some time or couple of days to setup anything. Just download it and you can use it immediately. You can run multiple PHP versions simultaneously and switch between them effortlessly.
Honestly, this tool has greatly simplified my PHP development and is definitely worth trying!

Some comments may only be visible to logged-in visitors. Sign in to view all comments.