diff --git a/.devilbox/www/config.php b/.devilbox/www/config.php index a266d120..6c5f1051 100644 --- a/.devilbox/www/config.php +++ b/.devilbox/www/config.php @@ -13,8 +13,8 @@ error_reporting(-1); putenv('RES_OPTIONS=retrans:1 retry:1 timeout:1 attempts:1'); -$DEVILBOX_VERSION = 'v1.8.0'; -$DEVILBOX_DATE = '2020-11-08'; +$DEVILBOX_VERSION = 'v1.8.1'; +$DEVILBOX_DATE = '2020-11-12'; $DEVILBOX_API_PAGE = 'devilbox-api/status.json'; // diff --git a/.devilbox/www/htdocs/opcache.php b/.devilbox/www/htdocs/opcache.php index b1065ffc..3bdd3184 100644 --- a/.devilbox/www/htdocs/opcache.php +++ b/.devilbox/www/htdocs/opcache.php @@ -13,6 +13,7 @@ * @license MIT, http://acollington.mit-license.org/ */ +error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE); /* * User configuration diff --git a/.devilbox/www/htdocs/vendor/phpmemcachedadmin-1.3.0/Config/Memcache.php b/.devilbox/www/htdocs/vendor/phpmemcachedadmin-1.3.0/Config/Memcache.php index e52d40fd..dc74a90b 100644 --- a/.devilbox/www/htdocs/vendor/phpmemcachedadmin-1.3.0/Config/Memcache.php +++ b/.devilbox/www/htdocs/vendor/phpmemcachedadmin-1.3.0/Config/Memcache.php @@ -1,4 +1,5 @@ 'Server', 'slabs_api' => 'Server', diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 60e008d5..277dbb05 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -25,9 +25,10 @@ assignees: '' ### Checklist * [ ] `.env` file is attached -* [ ] `docker-compose.override.yml` is attached (if it exists) -* [ ] Custom configs from `cfg/` dir are attached (if customized) -* [ ] `docker-compose logs` and `log/` output is added +* [ ] `./check-config.sh` output is added below +* [ ] `docker-compose logs` output is added below +* [ ] `docker-compose.override.yml` is attached (if exists) +* [ ] Custom configs from `cfg/` dir are attached (if exist) * [ ] I've looked through the docs: https://devilbox.readthedocs.io/en/latest/ * [ ] I've looked through existing issues: https://github.com/cytopia/devilbox/issues * [ ] I've read troubleshooting: https://devilbox.readthedocs.io/en/latest/support/troubleshooting.html @@ -35,10 +36,10 @@ assignees: '' ### OS / ENVIRONMENT -1. Host operating system and version: -2. (Windows) Native Docker or Docker Toolbox: -3. Docker version: -4. Docker Compose version: +1. Host operating system and version: +2. (Windows only) Native Docker or Docker Toolbox: +3. Docker version: +4. Docker Compose version: 5. (Linux) Is SELinux enabled?: 6. What git commit hash are you on?: @@ -68,18 +69,17 @@ assignees: '' $ docker-compose up... ``` -#### File and user permissions (Linux & MacOS) - -``` -$ id +#### Outputs + +```bash +$ ./check-config.sh + +<<< REPLACE THIS LINE WITH OUTPUT FROM ABOVE COMMAND >>> ``` - -``` -$ ls -la -``` + +```bash +$ docker-compose logs - -``` -$ ls -la data/www +<<< REPLACE THIS LINE WITH OUTPUT FROM ABOVE COMMAND >>> ``` diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e064f588..1bfae76b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -48,3 +48,11 @@ jobs: run: | cd .tests/ make lint-tests + + - name: Check configuration + shell: bash + run: | + cp env-example .env + sed -i'' "s/^NEW_UID=.*/NEW_UID=$(id -u)/g" .env + sed -i'' "s/^NEW_GID=.*/NEW_GID=$(id -g)/g" .env + ./check-config.sh diff --git a/.gitignore b/.gitignore index 8a065cb2..a7c1eafb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ # to re-index the git index (if there are already # commited files) # -# $ git rm -r --cached . +# $ git rm -r -f --cached . # $ git add . # $ git commit -m ".gitignore index rebuild" # @@ -16,7 +16,6 @@ # Ignore variable data /.env /backups/* -/log/[a-z0-9-]* # Ignore Data dirs /data/www/* @@ -27,6 +26,28 @@ # Ignore compose override file /docker-compose.override.yml +# Ignore logs +/log/apache-2.2/* +/log/apache-2.4/* +/log/mariadb-10.3/* +/log/nginx-mainline/* +/log/nginx-stable/* +/log/php-fpm-5.2/* +/log/php-fpm-5.3/* +/log/php-fpm-5.4/* +/log/php-fpm-5.5/* +/log/php-fpm-5.6/* +/log/php-fpm-7.0/* +/log/php-fpm-7.1/* +/log/php-fpm-7.2/* +/log/php-fpm-7.3/* +/log/php-fpm-7.4/* +/log/php-fpm-8.0/* +/log/php-fpm-8.1/* +!/log/.keepme +!/log/*/.keepme + + # Ignore custom global vhost gen templates /cfg/vhost-gen/apache22.conf /cfg/vhost-gen/apache24.conf @@ -49,6 +70,7 @@ /cfg/mariadb-10.2/*.cnf /cfg/mariadb-10.3/*.cnf /cfg/mariadb-10.4/*.cnf +/cfg/mariadb-10.5/*.cnf /cfg/percona-5.5/*.cnf /cfg/percona-5.6/*.cnf /cfg/percona-5.7/*.cnf @@ -79,6 +101,7 @@ /cfg/php-fpm-7.3/*.conf /cfg/php-fpm-7.4/*.conf /cfg/php-fpm-8.0/*.conf +/cfg/php-fpm-8.1/*.conf # Ignore custom PHP-FPM startup scripts /autostart/*.sh @@ -93,6 +116,7 @@ /cfg/php-startup-7.3/*.sh /cfg/php-startup-7.4/*.sh /cfg/php-startup-8.0/*.sh +/cfg/php-startup-8.1/*.sh # Ignorecustom Varnish configs /cfg/varnish-4/*.vcl @@ -111,6 +135,7 @@ /mod/php-fpm-7.3/*.so /mod/php-fpm-7.4/*.so /mod/php-fpm-8.0/*.so +/mod/php-fpm-8.1/*.so # Ignore custom bash and other confi files /bash/* @@ -128,7 +153,7 @@ /.tests/tmp/* /.tests/www/* !/.tests/www/modules -!/.tests/www/rproxy/js +!/.tests/www/rproxy/js/index.js # Keep folders !.keepme @@ -140,7 +165,6 @@ ###### std ###### .lock -*.log ###### patches/diffs ###### *.patch @@ -204,4 +228,4 @@ $RECYCLE.BIN/ *.bbproject ###### VS Code ###### -/.vscode \ No newline at end of file +/.vscode diff --git a/.tests/tests/config-xdebug.sh b/.tests/tests/config-xdebug.sh index 4a8bf0f6..bd41b816 100755 --- a/.tests/tests/config-xdebug.sh +++ b/.tests/tests/config-xdebug.sh @@ -13,7 +13,7 @@ DVLBOX_PATH="$( cd "${SCRIPT_PATH}/../.." && pwd -P )" . "${SCRIPT_PATH}/../scripts/.lib.sh" RETRIES=10 -DISABLED_VERSIONS=("8.0" "8.1") +DISABLED_VERSIONS=("") echo @@ -60,23 +60,42 @@ fi ### Xdebug default disabled ### printf "[TEST] Xdebug default disabled" -if ! run "curl -sS --fail 'http://localhost:${HOST_PORT_HTTPD}/info_php.php' | tac | tac | grep 'xdebug.remote_enable' | grep -E 'Off.+Off' >/dev/null" "${RETRIES}" "" "0"; then - printf "\\r[FAIL] Xdebug default disabled\\n" - run "curl -sS 'http://localhost:${HOST_PORT_HTTPD}/info_php.php' | grep 'xdebug.remote_enable' || true" - exit 1 +if [ "${PHP_VERSION}" = "8.0" ] || [ "${PHP_VERSION}" = "8.1" ]; then + if ! run "curl -sS --fail 'http://localhost:${HOST_PORT_HTTPD}/info_php.php' | tac | tac | grep 'xdebug.mode' | grep -E 'develop.+develop' >/dev/null" "${RETRIES}" "" "0"; then + printf "\\r[FAIL] Xdebug default disabled\\n" + run "curl -sS 'http://localhost:${HOST_PORT_HTTPD}/info_php.php' | grep 'xdebug.mode' || true" + exit 1 + else + printf "\\r[OK] Xdebug default disabled\\n" + fi else - printf "\\r[OK] Xdebug default disabled\\n" + if ! run "curl -sS --fail 'http://localhost:${HOST_PORT_HTTPD}/info_php.php' | tac | tac | grep 'xdebug.remote_enable' | grep -E 'Off.+Off' >/dev/null" "${RETRIES}" "" "0"; then + printf "\\r[FAIL] Xdebug default disabled\\n" + run "curl -sS 'http://localhost:${HOST_PORT_HTTPD}/info_php.php' | grep 'xdebug.remote_enable' || true" + exit 1 + else + printf "\\r[OK] Xdebug default disabled\\n" + fi fi - ### ### Xdebug autostart disabled ### printf "[TEST] Xdebug autostart disabled" -if ! run "curl -sS --fail 'http://localhost:${HOST_PORT_HTTPD}/info_php.php' | tac | tac | grep 'xdebug.remote_autostart' | grep -E 'Off.+Off' >/dev/null" "${RETRIES}" "" "0"; then - printf "\\r[FAIL] Xdebug autostart disabled\\n" - run "curl 'http://localhost:${HOST_PORT_HTTPD}/info_php.php' | grep 'xdebug.remote_autostart' || true" - exit 1 +if [ "${PHP_VERSION}" = "8.0" ] || [ "${PHP_VERSION}" = "8.1" ]; then + if ! run "curl -sS --fail 'http://localhost:${HOST_PORT_HTTPD}/info_php.php' | tac | tac | grep 'xdebug.start_with_request' | grep -E 'default.+default' >/dev/null" "${RETRIES}" "" "0"; then + printf "\\r[FAIL] Xdebug autostart disabled\\n" + run "curl 'http://localhost:${HOST_PORT_HTTPD}/info_php.php' | grep 'xdebug.start_with_request' || true" + exit 1 + else + printf "\\r[OK] Xdebug autostart disabled\\n" + fi else - printf "\\r[OK] Xdebug autostart disabled\\n" + if ! run "curl -sS --fail 'http://localhost:${HOST_PORT_HTTPD}/info_php.php' | tac | tac | grep 'xdebug.remote_autostart' | grep -E 'Off.+Off' >/dev/null" "${RETRIES}" "" "0"; then + printf "\\r[FAIL] Xdebug autostart disabled\\n" + run "curl 'http://localhost:${HOST_PORT_HTTPD}/info_php.php' | grep 'xdebug.remote_autostart' || true" + exit 1 + else + printf "\\r[OK] Xdebug autostart disabled\\n" + fi fi diff --git a/CHANGELOG.md b/CHANGELOG.md index fd4a6d76..6f9ab9bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ major versions. ## Unreleased +## Release v1.8.1 (2020-11-12) + +#### Fixed +- Silence PHP warnings in phpmemcached and opcache GUIs +- [#746](https://github.com/cytopia/devilbox/issues/746) Fix xdebug config for PHP 8.0 and 8.1 + +#### Added +- Added `check-config.sh` script to check against correct Devilbox configuration + + ## Release v1.8.0 (2020-11-08) #### Fixed diff --git a/cfg/php-ini-8.0/devilbox-php.ini-xdebug b/cfg/php-ini-8.0/devilbox-php.ini-xdebug index d3e977b5..94f7ca77 100644 --- a/cfg/php-ini-8.0/devilbox-php.ini-xdebug +++ b/cfg/php-ini-8.0/devilbox-php.ini-xdebug @@ -21,16 +21,15 @@ [PHP] ; Xdebug +; https://3.xdebug.org/docs/upgrade_guide ; Use these settings to enable Xdebug for PHP ; Make sure to read up on Xdebug some settings might significantly slow down requests. ; The following is just an example configuration and should be adjusted -xdebug.default_enable = On -xdebug.profiler_enable = On -xdebug.remote_enable = On -xdebug.remote_autostart = On -xdebug.remote_handler = dbgp -xdebug.remote_port = 9000 -xdebug.idekey = PHPSTORM -xdebug.remote_log = /var/log/php/xdebug.log +xdebug.mode = debug +xdebug.start_with_request = yes +xdebug.remote_handler = dbgp +xdebug.remote_port = 9000 +xdebug.idekey = PHPSTORM +xdebug.remote_log = /var/log/php/xdebug.log ; vim: set ft=dosini: diff --git a/cfg/php-ini-8.1/devilbox-php.ini-xdebug b/cfg/php-ini-8.1/devilbox-php.ini-xdebug index d3e977b5..94f7ca77 100644 --- a/cfg/php-ini-8.1/devilbox-php.ini-xdebug +++ b/cfg/php-ini-8.1/devilbox-php.ini-xdebug @@ -21,16 +21,15 @@ [PHP] ; Xdebug +; https://3.xdebug.org/docs/upgrade_guide ; Use these settings to enable Xdebug for PHP ; Make sure to read up on Xdebug some settings might significantly slow down requests. ; The following is just an example configuration and should be adjusted -xdebug.default_enable = On -xdebug.profiler_enable = On -xdebug.remote_enable = On -xdebug.remote_autostart = On -xdebug.remote_handler = dbgp -xdebug.remote_port = 9000 -xdebug.idekey = PHPSTORM -xdebug.remote_log = /var/log/php/xdebug.log +xdebug.mode = debug +xdebug.start_with_request = yes +xdebug.remote_handler = dbgp +xdebug.remote_port = 9000 +xdebug.idekey = PHPSTORM +xdebug.remote_log = /var/log/php/xdebug.log ; vim: set ft=dosini: diff --git a/cfg/php-startup-5.2/.keepme b/cfg/php-startup-5.2/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/cfg/php-startup-5.3/.keepme b/cfg/php-startup-5.3/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/cfg/php-startup-5.4/.keepme b/cfg/php-startup-5.4/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/cfg/php-startup-5.5/.keepme b/cfg/php-startup-5.5/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/cfg/php-startup-5.6/.keepme b/cfg/php-startup-5.6/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/cfg/php-startup-7.0/.keepme b/cfg/php-startup-7.0/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/cfg/php-startup-7.1/.keepme b/cfg/php-startup-7.1/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/cfg/php-startup-7.2/.keepme b/cfg/php-startup-7.2/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/cfg/php-startup-7.3/.keepme b/cfg/php-startup-7.3/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/cfg/php-startup-7.4/.keepme b/cfg/php-startup-7.4/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/cfg/php-startup-8.0/.keepme b/cfg/php-startup-8.0/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/cfg/php-startup-8.1/.keepme b/cfg/php-startup-8.1/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/cfg/varnish-4/.keepme b/cfg/varnish-4/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/cfg/varnish-5/.keepme b/cfg/varnish-5/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/cfg/varnish-6/.keepme b/cfg/varnish-6/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/check-config.sh b/check-config.sh new file mode 100755 index 00000000..b2cf0e14 --- /dev/null +++ b/check-config.sh @@ -0,0 +1,560 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + + +#-------------------------------------------------------------------------------------------------- +# GLOBALS +#-------------------------------------------------------------------------------------------------- +RET_CODE=0 +MY_UID="$( id -u )" +MY_GID="$( id -g )" + + +#-------------------------------------------------------------------------------------------------- +# Functions +#-------------------------------------------------------------------------------------------------- + +### +### Logger functions +### +log_err() { + >&2 printf "\\e[1;31m[ERR] %s\\e[0m\\n" "${1}" +} + +log_info() { + printf "\\e[;34m[INFO] %s\\e[0m\\n" "${1}" +} + +log_ok() { + printf "\\e[;32m[SUCC] %s\\e[0m\\n" "${1}" +} + +### +### Output functions +### +print_head_1() { + printf "\\n# " + printf "%0.s=" {1..78} + printf "\\n" + + printf "# %s\\n" "${1}" + + printf "# " + printf "%0.s=" {1..78} + printf "\\n" +} + +### +### File functions +### +file_get_uid() { + stat -c '%u' "${1}" +} + +file_get_gid() { + stat -c '%g' "${1}" +} + +# Returns 4-digit format +file_get_perm() { + local perm + local len + + if [ "$(uname)" = "Linux" ]; then + # If no special permissions are set (no sticky bit...), linux will + # only output the 3 digit number + perm="$( stat --format '%a' "${1}" )" + else + perm="$( stat -f '%OLp' "${1}" )" + fi + + # For special cases check the length and add a leading 0 + len="$(echo "${perm}" | awk '{ print length() }')" + if [ "${len}" = "3" ]; then + perm="0${perm}" + fi + + echo "${perm}" +} + + +#-------------------------------------------------------------------------------------------------- +# Check git +#-------------------------------------------------------------------------------------------------- +print_head_1 "Checking git" + +GIT_STATUS="$( git status -s )" +if [ -z "${GIT_STATUS}" ]; then + log_info "git is clean" +else + log_err "git is unclean" + echo "${GIT_STATUS}" + RET_CODE=$(( RET_CODE + 1)) +fi + + +#-------------------------------------------------------------------------------------------------- +# Check env file +#-------------------------------------------------------------------------------------------------- +print_head_1 "Checking .env file" + +if [ -f .env ]; then + log_ok ".env file exists" +else + log_err ".env file does not exist" + RET_CODE=$(( RET_CODE + 1)) + exit 1 +fi +if [ -r .env ]; then + log_ok ".env file is readable" +else + log_err ".env file is not readable" + RET_CODE=$(( RET_CODE + 1)) + exit 1 +fi + +# Ensure all variables exist in .env file +ENV_VAR_MISSING=0 +while read -r env_var; do + if ! grep -E "^${env_var}=" .env >/dev/null; then + log_err "Variable '${env_var}' missing in .env file" + RET_CODE=$(( RET_CODE + 1)) + ENV_VAR_MISSING=1 + fi +done < <(grep -E '^[A-Z].+=' env-example | awk -F'=' '{print $1}') +if [ "${ENV_VAR_MISSING}" = "0" ]; then + log_ok "All variables are present in .env file" +fi + +# Ensure variables are not duplicated in .env +ENV_VAR_DUPLICATED=0 +while read -r env_var; do + OCCURANCES="$( grep -Ec "^${env_var}=" .env )" + if [ "${OCCURANCES}" != "1" ]; then + log_err "Variable '${env_var}' should only be defined once. Occurances: ${OCCURANCES}" + RET_CODE=$(( RET_CODE + 1)) + ENV_VAR_DUPLICATED=1 + fi +done < <(grep -E '^[A-Z].+=' env-example | awk -F'=' '{print $1}') +if [ "${ENV_VAR_DUPLICATED}" = "0" ]; then + log_ok "No variables is duplicated in .env file" +fi + + +#-------------------------------------------------------------------------------------------------- +# Check env file values +#-------------------------------------------------------------------------------------------------- +print_head_1 "Checking .env file values" + +WRONG_ENV_FILES_VALUES=0 +DEBUG_COMPOSE_ENTRYPOINT="$( grep -E '^DEBUG_COMPOSE_ENTRYPOINT=' .env | awk -F'=' '{print $2}' )" +if [ "${DEBUG_COMPOSE_ENTRYPOINT}" != "0" ] && [ "${DEBUG_COMPOSE_ENTRYPOINT}" != "1" ] && [ "${DEBUG_COMPOSE_ENTRYPOINT}" != "2" ]; then + log_err "Variable 'DEBUG_COMPOSE_ENTRYPOINT' should be 0, 1 or 2. Has: ${DEBUG_COMPOSE_ENTRYPOINT}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi + +DOCKER_LOGS="$( grep -E '^DOCKER_LOGS=' .env | awk -F'=' '{print $2}' )" +if [ "${DOCKER_LOGS}" != "0" ] && [ "${DOCKER_LOGS}" != "1" ]; then + log_err "Variable 'DOCKER_LOGS' should be 0 or 1. Has: ${DOCKER_LOGS}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi + +DEVILBOX_PATH="$( grep -E '^DEVILBOX_PATH=' .env | awk -F'=' '{print $2}' )" +if [ ! -d "${DEVILBOX_PATH}" ]; then + log_err "Variable 'DEVILBOX_PATH' directory does not exist: ${DEVILBOX_PATH}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi +DEVILBOX_PATH_PERM="$( file_get_perm "${DEVILBOX_PATH}" )" +if [ "${DEVILBOX_PATH_PERM}" != "0755" ] && [ "${DEVILBOX_PATH_PERM}" != "0775" ] && [ "${DEVILBOX_PATH_PERM}" != "0777" ]; then + log_err "Variable 'DEVILBOX_PATH' directory must be 0755, 0775 or 0777. Has: ${DEVILBOX_PATH_PERM}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi +DEVILBOX_PATH_PERM="$( file_get_uid "${DEVILBOX_PATH}" )" +if [ "${DEVILBOX_PATH_PERM}" != "${MY_UID}" ]; then + log_err "Variable 'DEVILBOX_PATH' directory uid must be ${MY_UID}. Has: ${DEVILBOX_PATH_PERM}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi +DEVILBOX_PATH_PERM="$( file_get_gid "${DEVILBOX_PATH}" )" +if [ "${DEVILBOX_PATH_PERM}" != "${MY_GID}" ]; then + log_err "Variable 'DEVILBOX_PATH' directory gid must be ${MY_GID}. Has: ${DEVILBOX_PATH_PERM}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi + +if [ "${WRONG_ENV_FILES_VALUES}" = "0" ]; then + log_ok "All .env file variables have correct values" +fi + +HOST_PATH_HTTPD_DATADIR="$( grep -E '^HOST_PATH_HTTPD_DATADIR=' .env | awk -F'=' '{print $2}' )" +if [ ! -d "${HOST_PATH_HTTPD_DATADIR}" ]; then + log_err "Variable 'HOST_PATH_HTTPD_DATADIR' directory does not exist: ${HOST_PATH_HTTPD_DATADIR}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi +HOST_PATH_HTTPD_DATADIR_PERM="$( file_get_perm "${HOST_PATH_HTTPD_DATADIR}" )" +if [ "${HOST_PATH_HTTPD_DATADIR_PERM}" != "0755" ] && [ "${HOST_PATH_HTTPD_DATADIR_PERM}" != "0775" ] && [ "${HOST_PATH_HTTPD_DATADIR_PERM}" != "0777" ]; then + log_err "Variable 'HOST_PATH_HTTPD_DATADIR' directory must be 0755, 0775 or 0777. Has: ${HOST_PATH_HTTPD_DATADIR_PERM}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi +HOST_PATH_HTTPD_DATADIR_PERM="$( file_get_uid "${HOST_PATH_HTTPD_DATADIR}" )" +if [ "${HOST_PATH_HTTPD_DATADIR_PERM}" != "${MY_UID}" ]; then + log_err "Variable 'HOST_PATH_HTTPD_DATADIR' directory uid must be ${MY_UID}. Has: ${HOST_PATH_HTTPD_DATADIR_PERM}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi +HOST_PATH_HTTPD_DATADIR_PERM="$( file_get_gid "${HOST_PATH_HTTPD_DATADIR}" )" +if [ "${HOST_PATH_HTTPD_DATADIR_PERM}" != "${MY_GID}" ]; then + log_err "Variable 'HOST_PATH_HTTPD_DATADIR' directory gid must be ${MY_GID}. Has: ${HOST_PATH_HTTPD_DATADIR_PERM}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi + +PHP_SERVER="$( grep -E '^PHP_SERVER=' .env | awk -F'=' '{print $2}' )" +if ! grep -E "^#?PHP_SERVER=${PHP_SERVER}\$" env-example >/dev/null; then + log_err "Variable 'PHP_SERVER' has wrong value: ${PHP_SERVER}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi +HTTPD_SERVER="$( grep -E '^HTTPD_SERVER=' .env | awk -F'=' '{print $2}' )" +if ! grep -E "^#?HTTPD_SERVER=${HTTPD_SERVER}\$" env-example >/dev/null; then + log_err "Variable 'HTTPD_SERVER' has wrong value: ${HTTPD_SERVER}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi +MYSQL_SERVER="$( grep -E '^MYSQL_SERVER=' .env | awk -F'=' '{print $2}' )" +if ! grep -E "^#?MYSQL_SERVER=${MYSQL_SERVER}\$" env-example >/dev/null; then + log_err "Variable 'MYSQL_SERVER' has wrong value: ${MYSQL_SERVER}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi +PGSQL_SERVER="$( grep -E '^PGSQL_SERVER=' .env | awk -F'=' '{print $2}' )" +if ! grep -E "^#?PGSQL_SERVER=${PGSQL_SERVER}\$" env-example >/dev/null; then + log_err "Variable 'PGSQL_SERVER' has wrong value: ${PGSQL_SERVER}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi +REDIS_SERVER="$( grep -E '^REDIS_SERVER=' .env | awk -F'=' '{print $2}' )" +if ! grep -E "^#?REDIS_SERVER=${REDIS_SERVER}\$" env-example >/dev/null; then + log_err "Variable 'REDIS_SERVER' has wrong value: ${REDIS_SERVER}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi +MEMCD_SERVER="$( grep -E '^MEMCD_SERVER=' .env | awk -F'=' '{print $2}' )" +if ! grep -E "^#?MEMCD_SERVER=${MEMCD_SERVER}\$" env-example >/dev/null; then + log_err "Variable 'MEMCD_SERVER' has wrong value: ${MEMCD_SERVER}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi +MONGO_SERVER="$( grep -E '^MONGO_SERVER=' .env | awk -F'=' '{print $2}' )" +if ! grep -E "^#?MONGO_SERVER=${MONGO_SERVER}\$" env-example >/dev/null; then + log_err "Variable 'MONGO_SERVER' has wrong value: ${MONGO_SERVER}" + RET_CODE=$(( RET_CODE + 1)) + WRONG_ENV_FILES_VALUES=1 +fi + +NEW_UID="$( grep -E '^NEW_UID=' .env | awk -F'=' '{print $2}' )" +if [ "${NEW_UID}" != "${MY_UID}" ]; then + log_err "Variable 'NEW_UID' has wrong value: '${NEW_UID}'. Should have: ${MY_UID}" + RET_CODE=$(( RET_CODE + 1)) +fi +NEW_GID="$( grep -E '^NEW_GID=' .env | awk -F'=' '{print $2}' )" +if [ "${NEW_GID}" != "${MY_GID}" ]; then + log_err "Variable 'NEW_GID' has wrong value: '${NEW_GID}'. Should have: ${MY_GID}" + RET_CODE=$(( RET_CODE + 1)) +fi + + +if [ "${WRONG_ENV_FILES_VALUES}" = "0" ]; then + log_ok "All .env file variables have correct values" +fi + + + +#-------------------------------------------------------------------------------------------------- +# Ensure cfg/, mod/ and log/ directories exist +#-------------------------------------------------------------------------------------------------- +print_head_1 "Checking required directories" + +# /cfg/php-fpm-VERSION +DIR_MISSING=0 +while read -r php_version; do + if [ ! -d "cfg/php-fpm-${php_version}" ]; then + log_err "Directory 'cfg/php-fpm-${php_version}' is missing" + RET_CODE=$(( RET_CODE + 1)) + DIR_MISSING=1 + fi +done < <(grep -E '^#?PHP_SERVER=' env-example | awk -F'=' '{print $2}') +if [ "${DIR_MISSING}" = "0" ]; then + log_ok "All PHP cfg/ sub directories are present" +fi + +# /log/php-fpm-VERSION +DIR_MISSING=0 +while read -r php_version; do + if [ ! -d "log/php-fpm-${php_version}" ]; then + log_err "Directory 'log/php-fpm-${php_version}' is missing" + RET_CODE=$(( RET_CODE + 1)) + DIR_MISSING=1 + fi +done < <(grep -E '^#?PHP_SERVER=' env-example | awk -F'=' '{print $2}') +if [ "${DIR_MISSING}" = "0" ]; then + log_ok "All PHP log/ sub directories are present" +fi + +# /mod/php-fpm-VERSION +DIR_MISSING=0 +while read -r php_version; do + if [ ! -d "mod/php-fpm-${php_version}" ]; then + log_err "Directory 'mod/php-fpm-${php_version}' is missing" + RET_CODE=$(( RET_CODE + 1)) + DIR_MISSING=1 + fi +done < <(grep -E '^#?PHP_SERVER=' env-example | awk -F'=' '{print $2}') +if [ "${DIR_MISSING}" = "0" ]; then + log_ok "All PHP mod/ sub directories are present" +fi + +# /cfg/apache|nginx-VERSION +DIR_MISSING=0 +while read -r httpd_version; do + if [ ! -d "cfg/${httpd_version}" ]; then + log_err "Directory 'cfg/${httpd_version}' is missing" + RET_CODE=$(( RET_CODE + 1)) + DIR_MISSING=1 + fi +done < <(grep -E '^#?HTTPD_SERVER=' env-example | awk -F'=' '{print $2}') +if [ "${DIR_MISSING}" = "0" ]; then + log_ok "All HTTPD cfg/ sub directories are present" +fi + +# /log/apache|nginx-VERSION +DIR_MISSING=0 +while read -r httpd_version; do + if [ ! -d "log/${httpd_version}" ]; then + log_err "Directory 'log/${httpd_version}' is missing" + RET_CODE=$(( RET_CODE + 1)) + DIR_MISSING=1 + fi +done < <(grep -E '^#?HTTPD_SERVER=' env-example | awk -F'=' '{print $2}') +if [ "${DIR_MISSING}" = "0" ]; then + log_ok "All HTTPD log/ sub directories are present" +fi + + +#-------------------------------------------------------------------------------------------------- +# Directory permissions +#-------------------------------------------------------------------------------------------------- +print_head_1 "Checking directory permissions" + +DEVILBOX_DIRS=( + "autostart" + "backups" + "bash" + "ca" + "cfg" + "compose" + "log" + "mod" +) + +# Check allowed directory permissions: 0755 0775 0777 +DEVILBOX_DIR_PERM_WRONG=0 +for search_dir in "${DEVILBOX_DIRS[@]}"; do + while read -r my_dir; do + PERM="$( file_get_perm "${my_dir}" )" + if [ "${PERM}" != "0755" ] && [ "${PERM}" != "0775" ] && [ "${PERM}" != "0777" ]; then + log_err "Directory '${my_dir}' should have 0755, 0775 or 0777 permissions. Has: ${PERM} permissions" + RET_CODE=$(( RET_CODE + 1)) + DEVILBOX_DIR_PERM_WRONG=1 + fi + done < <(find "${search_dir}" -type d) +done +if [ "${DEVILBOX_DIR_PERM_WRONG}" = "0" ]; then + log_ok "All devilbox directories have correct permissions" +fi + +# Check allowed uid +DEVILBOX_DIR_PERM_WRONG=0 +for search_dir in "${DEVILBOX_DIRS[@]}"; do + while read -r my_dir; do + PERM="$( file_get_uid "${my_dir}" )" + if [ "${PERM}" != "${MY_UID}" ]; then + log_err "Directory '${my_dir}' should have uid '${MY_UID}' Has: '${PERM}'" + RET_CODE=$(( RET_CODE + 1)) + DEVILBOX_DIR_PERM_WRONG=1 + fi + done < <(find "${search_dir}" -type d) +done +if [ "${DEVILBOX_DIR_PERM_WRONG}" = "0" ]; then + log_ok "All devilbox directories have correct uid" +fi + +# Check allowed gid +DEVILBOX_DIR_PERM_WRONG=0 +for search_dir in "${DEVILBOX_DIRS[@]}"; do + while read -r my_dir; do + PERM="$( file_get_gid "${my_dir}" )" + if [ "${PERM}" != "${MY_GID}" ]; then + log_err "Directory '${my_dir}' should have gid '${MY_GID}' Has: '${PERM}'" + RET_CODE=$(( RET_CODE + 1)) + DEVILBOX_DIR_PERM_WRONG=1 + fi + done < <(find "${search_dir}" -type d) +done +if [ "${DEVILBOX_DIR_PERM_WRONG}" = "0" ]; then + log_ok "All devilbox directories have correct gid" +fi + + +#-------------------------------------------------------------------------------------------------- +# File permissions +#-------------------------------------------------------------------------------------------------- +print_head_1 "Checking file permissions" + +DEVILBOX_DIRS=( + "autostart" + "backups" + "ca" + "cfg" + "compose" + "mod" +) + +# Check allowed directory permissions: 0644 0664 0666 +DEVILBOX_DIR_PERM_WRONG=0 +for search_file in "${DEVILBOX_DIRS[@]}"; do + while read -r my_file; do + PERM="$( file_get_perm "${my_file}" )" + # Private CA file + if [ "${my_file}" = "ca/devilbox-ca.key" ]; then + if [ "${PERM}" != "0600" ]; then + log_err "File '${my_file}' should have 0600 permissions. Has: ${PERM} permissions" + RET_CODE=$(( RET_CODE + 1)) + DEVILBOX_DIR_PERM_WRONG=1 + fi + # Executable files + elif echo "${my_file}" | grep -E '.+\.sh(-example)?$' >/dev/null; then + if [ "${PERM}" != "0755" ] && [ "${PERM}" != "0775" ] && [ "${PERM}" != "0777" ]; then + log_err "File '${my_file}' should have 0755, 0775 or 0777 permissions. Has: ${PERM} permissions" + RET_CODE=$(( RET_CODE + 1)) + DEVILBOX_DIR_PERM_WRONG=1 + fi + # All other files + else + if [ "${PERM}" != "0644" ] && [ "${PERM}" != "0664" ] && [ "${PERM}" != "0666" ]; then + log_err "File '${my_file}' should have 0644, 0664 or 0666 permissions. Has: ${PERM} permissions" + RET_CODE=$(( RET_CODE + 1)) + DEVILBOX_DIR_PERM_WRONG=1 + fi + fi + done < <(find "${search_file}" -type f) +done +if [ "${DEVILBOX_DIR_PERM_WRONG}" = "0" ]; then + log_ok "All devilbox files have correct permissions" +fi + +# Check allowed uid +DEVILBOX_DIR_PERM_WRONG=0 +for search_file in "${DEVILBOX_DIRS[@]}"; do + while read -r my_file; do + PERM="$( file_get_uid "${my_file}" )" + if [ "${PERM}" != "${MY_UID}" ]; then + log_err "File '${my_file}' should have uid '${MY_UID}' Has: '${PERM}'" + RET_CODE=$(( RET_CODE + 1)) + DEVILBOX_DIR_PERM_WRONG=1 + fi + done < <(find "${search_file}" -type f) +done +if [ "${DEVILBOX_DIR_PERM_WRONG}" = "0" ]; then + log_ok "All devilbox files have correct uid" +fi + +# Check allowed gid +DEVILBOX_DIR_PERM_WRONG=0 +for search_file in "${DEVILBOX_DIRS[@]}"; do + while read -r my_file; do + PERM="$( file_get_gid "${my_file}" )" + if [ "${PERM}" != "${MY_GID}" ]; then + log_err "File '${my_file}' should have gid '${MY_GID}' Has: '${PERM}'" + RET_CODE=$(( RET_CODE + 1)) + DEVILBOX_DIR_PERM_WRONG=1 + fi + done < <(find "${search_file}" -type f) +done +if [ "${DEVILBOX_DIR_PERM_WRONG}" = "0" ]; then + log_ok "All devilbox files have correct gid" +fi + + +#-------------------------------------------------------------------------------------------------- +# Check projects +#-------------------------------------------------------------------------------------------------- +print_head_1 "Checking projects" + +HOST_PATH_HTTPD_DATADIR="$( grep -E '^HOST_PATH_HTTPD_DATADIR=' .env | awk -F'=' '{print $2}' )" + +DATA_DIR_PERM_WRONG=0 +while read -r project; do + PERM="$( file_get_perm "${project}" )" + if [ "${PERM}" != "0755" ] && [ "${PERM}" != "0775" ] && [ "${PERM}" != "0777" ]; then + log_err "Directory '${project}' should have 0755, 0775 or 0777 permissions. Has: ${PERM} permissions" + RET_CODE=$(( RET_CODE + 1)) + DATA_DIR_PERM_WRONG=1 + fi +done < <(find "${HOST_PATH_HTTPD_DATADIR}" -type d | grep -Ev "${HOST_PATH_HTTPD_DATADIR}/.+/.+") +if [ "${DATA_DIR_PERM_WRONG}" = "0" ]; then + log_ok "All project dirs have correct permissions" +fi + +DATA_DIR_PERM_WRONG=0 +while read -r project; do + PERM="$( file_get_uid "${project}" )" + if [ "${PERM}" != "${MY_UID}" ]; then + log_err "Directory '${project}' should have uid '${MY_UID}' Has: '${PERM}'" + RET_CODE=$(( RET_CODE + 1)) + DATA_DIR_PERM_WRONG=1 + fi +done < <(find "${HOST_PATH_HTTPD_DATADIR}" -type d | grep -Ev "${HOST_PATH_HTTPD_DATADIR}/.+/.+") +if [ "${DATA_DIR_PERM_WRONG}" = "0" ]; then + log_ok "All project dirs have correct uid" +fi + +DATA_DIR_PERM_WRONG=0 +while read -r project; do + PERM="$( file_get_gid "${project}" )" + if [ "${PERM}" != "${MY_GID}" ]; then + log_err "Directory '${project}' should have gid '${MY_GID}' Has: '${PERM}'" + RET_CODE=$(( RET_CODE + 1)) + DATA_DIR_PERM_WRONG=1 + fi +done < <(find "${HOST_PATH_HTTPD_DATADIR}" -type d | grep -Ev "${HOST_PATH_HTTPD_DATADIR}/.+/.+") +if [ "${DATA_DIR_PERM_WRONG}" = "0" ]; then + log_ok "All project dirs have correct gid" +fi + + +#-------------------------------------------------------------------------------------------------- +# Summary +#-------------------------------------------------------------------------------------------------- +print_head_1 "SUMMARY" + +if [ "${RET_CODE}" -gt "0" ]; then + log_err "Found ${RET_CODE} error(s)" + log_err "Devilbox might not work properly" + log_err "Fix the issues before submitting a bug report" + log_info "Ensure to run 'docker-compose stop; docker-compose rm -f' on changes in .env" + exit 1 +else + log_ok "Found no errors" + log_info "Ensure to run 'docker-compose stop; docker-compose rm -f' when .env was changed" + exit 0 +fi diff --git a/docker-compose.yml b/docker-compose.yml index cc0563fb..2619091f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -375,9 +375,6 @@ services: # ---- Format: ---- # HOST-DIRECTORY : DOCKER-DIRECTORY - # Mount logs - - ${DEVILBOX_PATH}/log/pgsql-${PGSQL_SERVER}:/var/log/postgresql:rw${MOUNT_OPTIONS} - # Mount PostgreSQL Data directory - devilbox-pgsql-${PGSQL_SERVER}:/var/lib/postgresql/data/pgdata:rw${MOUNT_OPTIONS} @@ -428,13 +425,6 @@ services: app_net: ipv4_address: 172.16.238.15 - volumes: - # ---- Format: ---- - # HOST-DIRECTORY : DOCKER-DIRECTORY - - # Mount logs - - ${DEVILBOX_PATH}/log/memcd-${MEMCD_SERVER}:/var/log/memcd:rw${MOUNT_OPTIONS} - depends_on: - bind - php diff --git a/docs/support/troubleshooting.rst b/docs/support/troubleshooting.rst index 418bd5ac..60920c02 100644 --- a/docs/support/troubleshooting.rst +++ b/docs/support/troubleshooting.rst @@ -60,6 +60,14 @@ Before going into the issues below, always do the following host> docker-compose up php httpd bind +**4. Run config checker** + + .. code-block:: bash + + # Run the bash script in the Devilbox git directory + host> ./check-config.sh + + General ======= diff --git a/log/apache-2.2/.keepme b/log/apache-2.2/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/apache-2.4/.keepme b/log/apache-2.4/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/mariadb-10.3/.keepme b/log/mariadb-10.3/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/nginx-mainline/.keepme b/log/nginx-mainline/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/nginx-stable/.keepme b/log/nginx-stable/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/php-fpm-5.2/.keepme b/log/php-fpm-5.2/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/php-fpm-5.3/.keepme b/log/php-fpm-5.3/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/php-fpm-5.4/.keepme b/log/php-fpm-5.4/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/php-fpm-5.5/.keepme b/log/php-fpm-5.5/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/php-fpm-5.6/.keepme b/log/php-fpm-5.6/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/php-fpm-7.0/.keepme b/log/php-fpm-7.0/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/php-fpm-7.1/.keepme b/log/php-fpm-7.1/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/php-fpm-7.2/.keepme b/log/php-fpm-7.2/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/php-fpm-7.3/.keepme b/log/php-fpm-7.3/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/php-fpm-7.4/.keepme b/log/php-fpm-7.4/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/php-fpm-8.0/.keepme b/log/php-fpm-8.0/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/log/php-fpm-8.1/.keepme b/log/php-fpm-8.1/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/mod/php-fpm-5.2/.keepme b/mod/php-fpm-5.2/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/mod/php-fpm-5.3/.keepme b/mod/php-fpm-5.3/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/mod/php-fpm-7.3/.keepme b/mod/php-fpm-7.3/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/mod/php-fpm-7.4/.keepme b/mod/php-fpm-7.4/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/mod/php-fpm-8.0/.keepme b/mod/php-fpm-8.0/.keepme new file mode 100644 index 00000000..e69de29b diff --git a/mod/php-fpm-8.1/.keepme b/mod/php-fpm-8.1/.keepme new file mode 100644 index 00000000..e69de29b