Docker base images for PHP-FPM

This commit is contained in:
ChiefSoft works
2022-07-31 14:54:16 +00:00
parent 7865c34b7d
commit 5959d57ac3
144 changed files with 19767 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
#!/bin/bash
if [ ! "$PHP_CRONTABS_PATH" == "" ]; then
printf "env CRONTABS_PATH: setting up crontabs: ";
for f in ${PHP_CRONTABS_PATH}; do
printf "$f, ";
rm -f /etc/cron.d/${f##*/}
cp $f /etc/cron.d/
chmod 0644 /etc/cron.d/${f##*/}
done
echo
touch /var/log/cron.log
printenv | grep -v "no_proxy" >> /etc/environment
/etc/init.d/cron start > /dev/null
fi
+68
View File
@@ -0,0 +1,68 @@
#!/bin/bash
echo "[`date +"%d-%b-%Y %T"`] PHP-FPM Docker container boot"
### create system user for php pool
if [ ! "$PHP_USER" == "" ] && [ ! "$PHP_UID" == "" ] && [ ! "$PHP_GID" == "" ] && [ ! "$PHP_HOME" == "" ]; then
echo "env PHP_USER: creating new system user: ${PHP_USER} ${PHP_UID}:${PHP_GID} ${PHP_HOME}"
mkdir -p $PHP_HOME && \
groupadd -f $PHP_USER -g $PHP_GID && \
useradd -d $PHP_HOME -u $PHP_UID -g $PHP_GID -s /usr/sbin/nologin $PHP_USER
fi
### load PHP ini configurations
if [ ! "$PHP_INI_PATH" == "" ]; then
printf "env PHP_INI_PATH: "
for f in ${PHP_INI_PATH}; do
printf "$f, ";
rm -f /usr/local/etc/php/conf.d/${f##*/}
cp $f /usr/local/etc/php/conf.d/
done
echo "into [ /usr/local/etc/php/conf.d/ ] folder..."
fi
### make sure to create clean php-fpm.conf
### to avoid adding multiple times the same lines next
### in case container is restarting
echo "[global]" > /usr/local/etc/php-fpm.conf
echo "include=etc/php-fpm.d/*.conf" >> /usr/local/etc/php-fpm.conf
### load PHP-FPM pool configurations
if [ ! "$PHP_POOL_PATH" == "" ]; then
printf "env PHP_POOL_PATH: "
for f in ${PHP_POOL_PATH}; do
printf "$f, ";
rm -f /usr/local/etc/php-fpm.d/${f##*/}
cp $f /usr/local/etc/php-fpm.d/
done
echo "into [ /usr/local/etc/php-fpm.d/ ] folder..."
fi
### load boot bash scripts
for f in /usr/local/bin/*.sh; do
/bin/bash -c $f
done
### load additional on-demand scripts
if [ ! -z ${PHP_BOOT_SCRIPTS+x} ] && [ "$PHP_BOOT_SCRIPTS" != "" ]; then
printf "env PHP_BOOT_SCRIPTS: "
for f in ${PHP_BOOT_SCRIPTS}; do
printf "$f, ";
rm -f /usr/local/bin/${f##*/}
cp $f /usr/local/bin/
chmod +x /usr/local/bin/${f##*/}
done
echo
for f in ${PHP_BOOT_SCRIPTS}; do
/bin/bash -c /usr/local/bin/${f##*/}
done
fi
### expose php version
echo
/usr/local/bin/php -v
@@ -0,0 +1,11 @@
#!/bin/sh
set -e
/usr/local/bin/docker-boot
# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- php-fpm "$@"
fi
exec "$@"
+13
View File
@@ -0,0 +1,13 @@
#!/bin/bash
if [ ! -z ${NEWRELIC_LICENSE+x} ] && [ "$NEWRELIC_LICENSE" != "" ] ; then
echo "env NEWRELIC_LICENSE: setting up newrelic license"
sed -i "s/REPLACE_WITH_REAL_KEY/$NEWRELIC_LICENSE/g" /usr/local/etc/php/conf.d/newrelic.ini
nrsysmond-config --set license_key=$NEWRELIC_LICENSE
service newrelic-sysmond start > /dev/null
chmod u+rw,g+rw,o+rw /var/log/newrelic/newrelic-daemon.log
else
rm -f /usr/local/etc/php/conf.d/newrelic.ini
fi
+39
View File
@@ -0,0 +1,39 @@
#!/usr/local/bin/php
<?php
/**
* This script is a sendmail wrapper for php to log calls of the php mail() function.
* Author: Till Brehm, www.ispconfig.org
* (Hopefully) secured by David Goodwin <david @ _palepurple_.co.uk>
* https://www.howtoforge.com/how-to-log-emails-sent-with-phps-mail-function-to-detect-form-spam
*/
$sendmail_bin = '/usr/sbin/sendmail';
// Get the email content
$mail = '';
$logline = '';
$pointer = fopen('php://stdin', 'r');
while ($line = fgets($pointer)) {
if (preg_match('/^to:/i', $line) || preg_match('/^from:/i', $line)) {
$logline .= trim($line) . ' ';
}
$mail .= $line;
}
// Compose the sendmail command
$command = 'echo ' . escapeshellarg($mail) . ' | ' . $sendmail_bin . ' -t -i';
if (isset($_SERVER['argc'])) {
for ($i = 1; $i < $_SERVER['argc']; $i++) {
$command .= escapeshellarg($_SERVER['argv'][$i]) . ' ';
}
}
// Write the log
$stdout = fopen('php://stdout', 'w');
fwrite($stdout, (isset($_ENV['USER']) ? $_ENV['USER'] . ' ' : '') . $logline . ' - ' . $command . "\n");
// Execute the command
return shell_exec($command);
+32
View File
@@ -0,0 +1,32 @@
#!/bin/bash
if [ ! -z ${SMTP_LOGIN+x} ] && [ ! -z ${SMTP_PASSWORD+x} ] && [ "$SMTP_LOGIN" != "" ] && [ "$SMTP_PASSWORD" != "" ]; then
echo "env SMTP_LOGIN: sendgrid credentials for email routing";
echo "[smtp.sendgrid.net]:2525 ${SMTP_LOGIN}:${SMTP_PASSWORD}" > /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd.db
rm /etc/postfix/sasl_passwd
### update email relay configuration for SendGrid
sed -i 's/default_transport = error//g' /etc/postfix/main.cf
sed -i 's/relay_transport = error//g' /etc/postfix/main.cf
### delete following lines if already exist before adding
sed -i '/relayhost/d' /etc/postfix/main.cf
sed -i '/smtp_tls_security_level/d' /etc/postfix/main.cf
sed -i '/smtp_sasl_auth_enable/d' /etc/postfix/main.cf
sed -i '/smtp_sasl_password_maps/d' /etc/postfix/main.cf
sed -i '/header_size_limit/d' /etc/postfix/main.cf
sed -i '/smtp_sasl_security_options/d' /etc/postfix/main.cf
### add following lines
echo "relayhost = [smtp.sendgrid.net]:2525" >> /etc/postfix/main.cf
echo "smtp_tls_security_level = encrypt" >> /etc/postfix/main.cf
echo "smtp_sasl_auth_enable = yes" >> /etc/postfix/main.cf
echo "smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd" >> /etc/postfix/main.cf
echo "header_size_limit = 4096000" >> /etc/postfix/main.cf
echo "smtp_sasl_security_options = noanonymous" >> /etc/postfix/main.cf
/etc/init.d/postfix start > /dev/null
fi
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
### update PHP session handler
if [ ! "$PHP_SESSION_HANDLER" == "" ] && [ ! "$PHP_SESSION_PATH" == "" ]; then
echo "env PHP_SESSION_HANDLER: updating php session handler [ $PHP_SESSION_PATH ]"
echo "session.save_handler = $PHP_SESSION_HANDLER" > /usr/local/etc/php/conf.d/zz-session.ini
echo "session.save_path = \"$PHP_SESSION_PATH\"" >> /usr/local/etc/php/conf.d/zz-session.ini
fi
+17
View File
@@ -0,0 +1,17 @@
#!/bin/bash
if [ ! -z ${PHP_INI_SCAN_DIR+x} ] && [ "$PHP_INI_SCAN_DIR" != "" ] ; then
echo "env PHP_INI_SCAN_DIR: $PHP_INI_SCAN_DIR"
### break down path by : separator
IFS=':' read -ra DIRECTORIES <<< "$PHP_INI_SCAN_DIR"
for DIR in "${DIRECTORIES[@]}"; do
### check if there are any php pool configuration files to copy
COUNT=`ls -1 $DIR/*.conf 2>/dev/null | wc -l`
if [ $COUNT != "0" ] ; then
cp -f $DIR/*.conf /usr/local/etc/php-fpm.d/
fi
done
fi