#!/bin/sh -e

# Replace ENV vars in configuration files
tmpfile=$(mktemp)
cat /etc/php81/conf.d/custom.ini | envsubst "$(env | cut -d= -f1 | sed -e 's/^/$/')" | tee "$tmpfile" > /dev/null
mv "$tmpfile" /etc/php81/conf.d/custom.ini

tmpfile=$(mktemp)
cat /etc/php81/php-fpm.d/www.conf | envsubst "$(env | cut -d= -f1 | sed -e 's/^/$/')" | tee "$tmpfile" > /dev/null
mv "$tmpfile" /etc/php81/php-fpm.d/www.conf

# pipe stderr to stdout and run php-fpm
exec 2>&1
exec php-fpm -F
