| _ | | | | _ \ | | _ | / | ( _ ) | /

| |) | || | |) || | | |) | |/| | / _ \ | \

| /| _ | /_| | | __/| | | | | () | ___) |

|| || ||| || || || || ___()___/


/ _ \ _ __ ___ _ __ | __ ) || _ \ | | ___|

| | | | '_ \ / _ \ '_ | _ ___ | | | | / /|___ \

| || | |) | / | | | |_) |) | || | / / ___) |

_/| ./ ___|| ||//|/ //()__/

  |_|                                              

Install PHP-FPM on OpenBSD 7.5 with HTTPD server

Add PHPMailer to the chroot of HTTPD

Add QRencode and ZBARIMG to the choort of HTTPD

				Written by Wim Stockman

				On 18 Nov 2024

Installlation of PHP-FPM

doas pkg_add php

choose version 8.3

Installation of PHPMailer

=> https://github.com/PHPMailer/PHPMailer/archive/master.zip

cd /var/www
mkdir -p usr/local/share/php-8.3
doas rsync -avr PHPMailer-master/ /var/www/usr/local/share/php-8.3/PHPMailer

This install it to the chroot only if you want it systemwide for use with CLI PHP

also copy it to:

doas rsync -avr PHPMailer-master/ /usr/local/share/php-8.3/PHPMailer

Installation of qrencode

The Qrencode library is a CLI tool to create QR-Codes.

doas pkg_add libqrencode

Installation of zbarimg

The Zbarimg is a CLI tool to read QR-Code out of images.

doas pkg_add zbar

Configure PHP-FPM

enable our php-fpm server

rcctl enable php83_fpm
rcctl start php83_fpm

Edit your /etc/http.conf to add fastcgi socket definitions in some SERVER section

	server "default" {
	    listen on * port 80
	    #listen on * port 443

	    root "/htdocs"
	    directory index index.php

	    location "/*.php" { 
		fastcgi socket "/run/php-fpm.sock"
	    }
	    location "/*.php[/?]*" { 
		fastcgi socket "/run/php-fpm.sock"
	    } 
	}

restart our httpd server

rcctl restart httpd

Configure PHPMailer

To be able to sent imap mails with our PHPMailer class we should

also we need to install this extension :

doas pgk_add php-imap-8.3.11

So now start your PHPMailer scripts with these includes:

	

Last Part to be able to sent a mail with our PHPMailer is copy some important files to our chroot.

mkdir /var/www/etc
cp /etc/resolv.conf /var/www/etc/
cp -r /etc/ssl /var/www/etc/

So now you can sent mails with the PHPMailer class.

When sending mails with PHPMailer it doesn't copy the sent mails to the sent mails folder.

Here is a sample function to save your sent mails to your sent mail folder:

	getSentMIMEMessage());
		imap_close($imap_stream);
		return $result;
	}
	?>

Setup our QRENCODE & ZBARIMG

To be able to use our QRENCODE and ZBARIMG CLI tools inside our chroot we need to copy the necessary dependencies.

you can find the dependencies with the "ldd" command

First see what executable is actually called when running qrencode

which qrencode
/usr/local/bin/qrencode

Now we can run our ldd to find the dynamic linked libraries it uses.

ldd /usr/local/bin/qrencode

This returns :

	/usr/local/bin/qrencode:
		Start            End              Type  Open Ref GrpRef Name
		000000cba4a9e000 000000cba4aad000 exe   2    0   0      /usr/local/bin/qrencode
		000000cdc4ea6000 000000cdc4ebb000 rlib  0    1   0      /usr/local/lib/libqrencode.so.2.1
		000000ce60c7e000 000000ce60cbf000 rlib  0    1   0      /usr/local/lib/libpng.so.18.0
		000000ce594b5000 000000ce594e7000 rlib  0    2   0      /usr/lib/libm.so.10.1
		000000ce50e33000 000000ce50e51000 rlib  0    2   0      /usr/lib/libz.so.7.0
		000000ce1b1fc000 000000ce1b209000 rlib  0    2   0      /usr/lib/libpthread.so.27.1
		000000ce1f4cb000 000000ce1f5c2000 rlib  0    1   0      /usr/lib/libc.so.99.0
		000000ce36ec0000 000000ce36ec0000 ld.so 0    1   0      /usr/libexec/ld.so

Now we have to copy all these files to there relative directory in our chroot /var/www/

we could do this manually but i wrote a small scripts to do this automaticly:

Here is my chroottool.sh script

	#!/usr/local/bin/bash
	# Written by Wim Stockman on 18 Nov 2024
	# uses bash and rsync on OpenBSD7.5

	CHROOT='/var/www/'

	for i in $( ldd $* | awk 'NR > 2{print $7;}' | sort | uniq )
	  do
	    echo $i
	    rsync -a --relative $i $CHROOT
	  done

	echo "Chroot files are copied is ready."

You can also Download it from here:

=> "My Chroottool Bash Script"

so just run:

doas chroottool.sh /usr/local/bin/qrencode

do the same for zbarimg

doas chroottool.sh /usr/local/bin/zbarimg

Finalizing our chroot.

we need to copy some necessary files to /var/www/bin

doas mkdir /var/www/bin/
doas cp /usr/local/bin/bash /var/www/bin/
doas cp /bin/sh /var/www/bin/
doas cp /bin/ksh /var/www/bin/ksh

So enjoy your Chrooted OpenBsd Httpd PHP-FPM Server !!!

Proxy Information
Original URL
gemini://yasendfile.org/TipTricks/php-fpm_OpenBSD.gmi
Status Code
Success (20)
Meta
text/gemini; lang=en
Capsule Response Time
428.94709 milliseconds
Gemini-to-HTML Time
1.957059 milliseconds

This content has been proxied by September (3851b).