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
+144
View File
@@ -0,0 +1,144 @@
#! /bin/bash
# Colors used for status updates
ESC_SEQ="\x1b["
COL_RESET=$ESC_SEQ"39;49;00m"
COL_RED=$ESC_SEQ"31;01m"
COL_GREEN=$ESC_SEQ"32;01m"
COL_YELLOW=$ESC_SEQ"33;01m"
COL_BLUE=$ESC_SEQ"34;01m"
COL_MAGENTA=$ESC_SEQ"35;01m"
COL_CYAN=$ESC_SEQ"36;01m"
# Detect which `ls` flavor is in use
if ls --color > /dev/null 2>&1; then # GNU `ls`
colorflag="--color"
export LS_COLORS='no=00:fi=00:di=01;31:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:'
else # macOS `ls`
colorflag="-G"
export LSCOLORS='BxBxhxDxfxhxhxhxhxcxcx'
fi
# List all files colorized in long format
#alias l="ls -lF ${colorflag}"
### MEGA: I want l and la ti return hisdden files
alias l="ls -laF ${colorflag}"
# List all files colorized in long format, including dot files
alias la="ls -laF ${colorflag}"
# List only directories
alias lsd="ls -lF ${colorflag} | grep --color=never '^d'"
# Always use color output for `ls`
alias ls="command ls ${colorflag}"
# Commonly Used Aliases
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ~="cd ~" # `cd` is probably faster to type though
alias -- -="cd -"
alias home="cd ~"
alias h="history"
alias j="jobs"
alias e='exit'
alias c="clear"
alias cla="clear && ls -l"
alias cll="clear && ls -la"
alias cls="clear && ls"
alias code="cd /var/www"
alias ea="vi ~/aliases"
# Always enable colored `grep` output
# Note: `GREP_OPTIONS="--color=auto"` is deprecated, hence the alias usage.
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias art="php artisan"
alias artisan="php artisan"
alias cdump="composer dump-autoload -o"
alias composer:dump="composer dump-autoload -o"
alias db:reset="php artisan migrate:reset && php artisan migrate --seed"
alias dusk="php artisan dusk"
alias fresh="php artisan migrate:fresh"
alias migrate="php artisan migrate"
alias refresh="php artisan migrate:refresh"
alias rollback="php artisan migrate:rollback"
alias seed="php artisan:seed"
alias serve="php artisan serve --quiet &"
alias phpunit="./vendor/bin/phpunit"
alias pu="phpunit"
alias puf="phpunit --filter"
alias pud='phpunit --debug'
alias cc='codecept'
alias ccb='codecept build'
alias ccr='codecept run'
alias ccu='codecept run unit'
alias ccf='codecept run functional'
alias g="gulp"
alias npm-global="npm list -g --depth 0"
alias ra="reload"
alias reload="source ~/.aliases && echo \"$COL_GREEN ==> Aliases Reloaded... $COL_RESET \n \""
alias run="npm run"
alias tree="xtree"
# Xvfb
alias xvfb="Xvfb -ac :0 -screen 0 1024x768x16 &"
# requires installation of 'https://www.npmjs.com/package/npms-cli'
alias npms="npms search"
# requires installation of 'https://www.npmjs.com/package/package-menu-cli'
alias pm="package-menu"
# requires installation of 'https://www.npmjs.com/package/pkg-version-cli'
alias pv="package-version"
# requires installation of 'https://github.com/sindresorhus/latest-version-cli'
alias lv="latest-version"
# git aliases
alias gaa="git add ."
alias gd="git --no-pager diff"
alias git-revert="git reset --hard && git clean -df"
alias gs="git status"
alias whoops="git reset --hard && git clean -df"
# Create a new directory and enter it
function mkd() {
mkdir -p "$@" && cd "$@"
}
function md() {
mkdir -p "$@" && cd "$@"
}
function xtree {
find ${1:-.} -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
}
# `tre` is a shorthand for `tree` with hidden files and color enabled, ignoring
# the `.git` directory, listing directories first. The output gets piped into
# `less` with options to preserve color and line numbers, unless the output is
# small enough for one screen.
function tre() {
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
}
# Determine size of a file or total size of a directory
function fs() {
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh;
else
local arg=-sh;
fi
if [[ -n "$@" ]]; then
du $arg -- "$@";
else
du $arg .[^.]* ./*;
fi;
}
+17
View File
@@ -0,0 +1,17 @@
#!/bin/bash
if [ ! -z ${PHP_CRONTABS_PATH+x} ] && [ "$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
printenv | grep -v "no_proxy" >> /etc/environment
/etc/init.d/cron start > /dev/null
fi
+62
View File
@@ -0,0 +1,62 @@
#!/bin/bash
/usr/local/bin/php -v
### create system user for php pool
if [ ! -z ${PHP_USER+x} ] && [ ! -z ${PHP_UID+x} ] && [ ! -z ${PHP_GID+x} ] && [ ! -z ${PHP_HOME+x} ] && [ "$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}"
groupadd -f $PHP_USER -g $PHP_GID && \
useradd -d $PHP_HOME -u $PHP_UID -g $PHP_GID -s /bin/false $PHP_USER
fi
### load PHP ini configurations
if [ ! -z ${PHP_INI_PATH+x} ] && [ "$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
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
### remove default www.conf pool
### and load PHP-FPM pool configurations
if [ ! -z ${PHP_POOL_PATH+x} ] && [ "$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
fi
### load boot bash scripts
for f in /usr/local/bin/*.sh; do
/bin/bash -c $f
done
### load bash 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##*/}
/bin/bash -c /usr/local/bin/${f##*/}
done
echo
fi
@@ -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 "$@"
+8
View File
@@ -0,0 +1,8 @@
#!/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
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);
+24
View File
@@ -0,0 +1,24 @@
#!/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 && \
sed -i 's/relayhost = //g' /etc/postfix/main.cf && \
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 [ ! -z ${PHP_SESSION_HANDLER+x} ] && [ ! -z ${PHP_SESSION_PATH+x} ] && [ "$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