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
echo "env CRONTABS_PATH: setting up crontabs [ $PHP_CRONTABS_PATH ]:";
for f in ${PHP_CRONTABS_PATH}; do
echo " - $f";
rm -f /etc/cron.d/${f##*/}
cp $f /etc/cron.d/
chmod 0644 /etc/cron.d/${f##*/}
done
touch /var/log/cron.log
printenv | grep -v "no_proxy" >> /etc/default/locale
/etc/init.d/cron start > /dev/null
fi
+86
View File
@@ -0,0 +1,86 @@
#!/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
echo "env PHP_INI_PATH: copy from [ $PHP_INI_PATH ] into [ /usr/local/etc/php/conf.d/ ] folder"
for f in ${PHP_INI_PATH}; do
echo " - $f";
rm -f /usr/local/etc/php/conf.d/${f##*/}
cp $f /usr/local/etc/php/conf.d/
done
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
echo "env PHP_POOL_PATH: copy from [ $PHP_POOL_PATH ] into [ /usr/local/etc/php-fpm.d/ ] folder"
for f in ${PHP_POOL_PATH}; do
echo " - $f";
rm -f /usr/local/etc/php-fpm.d/${f##*/}
cp $f /usr/local/etc/php-fpm.d/
done
fi
### scan for config files in folders from PHP_INI_SCAN_DIR
if [ ! -z ${PHP_INI_SCAN_DIR+x} ] && [ "$PHP_INI_SCAN_DIR" != "" ] ; then
echo "env PHP_INI_SCAN_DIR: copy from [ $PHP_INI_SCAN_DIR ] into [ /usr/local/etc/php-fpm.d/ ] folder"
### 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
echo " - $DIR/*.conf";
cp -f $DIR/*.conf /usr/local/etc/php-fpm.d/
fi
done
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
echo "env PHP_BOOT_SCRIPTS: executing scripts in [ $PHP_BOOT_SCRIPTS ]"
for f in ${PHP_BOOT_SCRIPTS}; do
echo " - $f";
rm -f /usr/local/bin/${f##*/}
cp $f /usr/local/bin/
chmod +x /usr/local/bin/${f##*/}
done
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 "$@"
+10
View File
@@ -0,0 +1,10 @@
<?php
if (isset($_SERVER['TEST_EMAIL']) && trim($_SERVER['TEST_EMAIL']) != "") {
$email = $_SERVER['TEST_EMAIL'];
$subject = "PHP email test script";
$message = "This is a test email to confirm that the PHP mail function works!";
$headers = "From: " . $email;
mail($email, $subject, $message, $headers);
}
+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
+38
View File
@@ -0,0 +1,38 @@
#!/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
error_log("Email sent: " . $logline);
// Execute the command
return shell_exec($command);
+38
View File
@@ -0,0 +1,38 @@
#!/bin/bash
if [ ! -z ${SENDGRID_API_KEY+x} ] && [ "$SENDGRID_API_KEY" != "" ]; then
echo "env SMTP_LOGIN: sendgrid credentials for email routing";
echo "[smtp.sendgrid.net]:2525 apikey:${SENDGRID_API_KEY}" > /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
### send test email if TEST_EMAIL env variable is set
if [ ! -z ${TEST_EMAIL+x} ] && [ "$TEST_EMAIL" != "" ]; then
echo " - sending test email to: [ $TEST_EMAIL ]";
php /usr/local/bin/emailtest.php
fi
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