From 0d2013bfb7bfb0271e18e9f47a315e7b384d1ab3 Mon Sep 17 00:00:00 2001 From: Micha Krapp Date: Sun, 13 Jul 2025 12:13:40 +0200 Subject: [PATCH 1/7] Update .gitignore --- .gitignore | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7ad1606..435de94 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,10 @@ gp-data/ # Installed via Composer content/mu-plugins/php-basic-auth/ -content/plugins/query-monitor/ -content/plugins/wp-redis/ +content/plugins/ +!content/plugins/airplane-mode +!content/plugins/f-api +!content/plugins/f-gd-cron +!content/plugins/f-translate vendor/ wordpress/ - From 75eb751204a74cd68f0e5491fb10f89a0121a168 Mon Sep 17 00:00:00 2001 From: Micha Krapp Date: Sun, 13 Jul 2025 17:23:45 +0200 Subject: [PATCH 2/7] feat(local): add ddev basic config (wip) frontend runs. admin missing the /wordpress/ in the url --- .config/env.php | 3 + .ddev/.env | 22 ++ .ddev/addon-metadata/redis/manifest.yaml | 26 ++ .ddev/commands/host/redis-backend | 116 +++++++++ .ddev/commands/redis/redis-cli | 13 + .ddev/commands/redis/redis-flush | 12 + .ddev/config.yaml | 307 +++++++++++++++++++++++ .ddev/docker-compose.redis.yaml | 21 ++ .ddev/nginx_full/nginx-site.conf | 106 ++++++++ .ddev/redis/redis.conf | 13 + .gitignore | 1 + README.md | 12 +- docs/local_development.md | 58 +++++ wp-config.php | 10 +- 14 files changed, 707 insertions(+), 13 deletions(-) create mode 100644 .ddev/.env create mode 100644 .ddev/addon-metadata/redis/manifest.yaml create mode 100755 .ddev/commands/host/redis-backend create mode 100755 .ddev/commands/redis/redis-cli create mode 100755 .ddev/commands/redis/redis-flush create mode 100644 .ddev/config.yaml create mode 100644 .ddev/docker-compose.redis.yaml create mode 100644 .ddev/nginx_full/nginx-site.conf create mode 100644 .ddev/redis/redis.conf create mode 100644 docs/local_development.md diff --git a/.config/env.php b/.config/env.php index 1db1f35..2b76ab1 100644 --- a/.config/env.php +++ b/.config/env.php @@ -3,6 +3,9 @@ * Connect environment variables to WP constants. */ +defined( 'WP_HOME' ) or define( 'WP_HOME', getenv( 'WP_HOME' ) ); +defined( 'WP_SITEURL' ) or define( 'WP_SITEURL', getenv( 'WP_SITEURL' ) ); + defined( 'DB_HOST' ) or define( 'DB_HOST', getenv( 'DB_HOST' ) ); defined( 'DB_USER' ) or define( 'DB_USER', getenv( 'DB_USER' ) ); defined( 'DB_PASSWORD' ) or define( 'DB_PASSWORD', getenv( 'DB_PASSWORD' ) ); diff --git a/.ddev/.env b/.ddev/.env new file mode 100644 index 0000000..10d3170 --- /dev/null +++ b/.ddev/.env @@ -0,0 +1,22 @@ +# Database +DB_NAME="db" +DB_USER="db" +DB_PASSWORD="db" +DB_HOST="db" + +# WordPress +WP_ENVIRONMENT_TYPE="local" +WP_HOME="https://server.ddev.site" +WP_SITEURL="${WP_HOME}/wordpress" + +# Redis +REDIS_HOST="redis" +REDIS_PORT="6379" +WP_REDIS_HOST="redis" +WP_REDIS_PORT="6379" + +# Debug +WP_DEBUG="true" +WP_DEBUG_DISPLAY="true" +WP_DEBUG_LOG="true" +SCRIPT_DEBUG="true" \ No newline at end of file diff --git a/.ddev/addon-metadata/redis/manifest.yaml b/.ddev/addon-metadata/redis/manifest.yaml new file mode 100644 index 0000000..f25a4ae --- /dev/null +++ b/.ddev/addon-metadata/redis/manifest.yaml @@ -0,0 +1,26 @@ +name: redis +repository: ddev/ddev-redis +version: v2.1.1 +install_date: "2025-07-13T11:56:03+02:00" +project_files: + - docker-compose.redis.yaml + - redis/scripts/settings.ddev.redis.php + - redis/scripts/setup-drupal-settings.sh + - redis/scripts/setup-redis-optimized-config.sh + - redis/redis.conf + - redis/advanced.conf + - redis/append.conf + - redis/general.conf + - redis/io.conf + - redis/memory.conf + - redis/network.conf + - redis/security.conf + - redis/snapshots.conf + - commands/host/redis-backend + - commands/redis/redis-cli + - commands/redis/redis-flush +global_files: [] +removal_actions: + - | + #ddev-description:Remove redis settings for Drupal 9+ if applicable + rm -f "${DDEV_APPROOT}/${DDEV_DOCROOT}/sites/default/settings.ddev.redis.php" diff --git a/.ddev/commands/host/redis-backend b/.ddev/commands/host/redis-backend new file mode 100755 index 0000000..473c9dc --- /dev/null +++ b/.ddev/commands/host/redis-backend @@ -0,0 +1,116 @@ +#!/usr/bin/env bash +#ddev-generated + +## Description: Use a different key-value store for Redis +## Usage: redis-backend [optimize] +## Example: ddev redis-backend redis-alpine optimize + +REDIS_DOCKER_IMAGE=${1:-} +REDIS_CONFIG=${2:-} +NAME=$REDIS_DOCKER_IMAGE + +function show_help() { + cat < [optimize] + +Choose from predefined aliases, or provide any Redis-compatible Docker image. +Note that not every Docker image can work right away, and you may need to override +the "command:" in the docker-compose.redis_extra.yaml file + +Available aliases: + redis redis:7 + redis-alpine redis:7-alpine + valkey valkey/valkey:8 + valkey-alpine valkey/valkey:8-alpine + +Custom backend: + You can specify any Docker image, e.g.: + ddev redis-backend redis:6 + +Optional: + optimize Apply additional Redis configuration with resource limits + optimized Same as optimize + +Examples: + ddev redis-backend redis-alpine optimize + ddev redis-backend valkey + ddev redis-backend redis:7.2-alpine +EOF + exit 0 +} + +function optimize_config() { + [[ "$REDIS_CONFIG" != "optimized" && "$REDIS_CONFIG" != "optimize" ]] && return + ddev dotenv set .ddev/.env.redis --redis-optimized=true +} + +function cleanup() { + rm -f "$DDEV_APPROOT/.ddev/.env.redis" + rm -rf "$DDEV_APPROOT/.ddev/redis/" + rm -f "$DDEV_APPROOT/.ddev/docker-compose.redis.yaml" "$DDEV_APPROOT/.ddev/docker-compose.redis_extra.yaml" + + redis_volume="ddev-$(ddev status -j | docker run -i --rm ddev/ddev-utilities jq -r '.raw.name')_redis" + if docker volume ls -q | grep -qw "$redis_volume"; then + ddev stop + docker volume rm "$redis_volume" + fi +} + +function check_docker_image() { + echo "Pulling ${REDIS_DOCKER_IMAGE}..." + if ! docker pull "$REDIS_DOCKER_IMAGE"; then + echo >&2 "❌ Unable to pull ${REDIS_DOCKER_IMAGE}" + exit 2 + fi +} + +function use_docker_image() { + [[ "$REDIS_DOCKER_IMAGE" != "redis:7" ]] && ddev dotenv set .ddev/.env.redis --redis-docker-image="$REDIS_DOCKER_IMAGE" + REPO=$(ddev add-on list --installed -j 2>/dev/null | docker run -i --rm ddev/ddev-utilities jq -r '.raw[] | select(.Name=="redis") | .Repository // empty' 2>/dev/null) + ddev add-on get "${REPO:-ddev/ddev-redis}" +} + +case "$REDIS_DOCKER_IMAGE" in + redis) + NAME="Redis 7" + REDIS_DOCKER_IMAGE="redis:7" + ;; + redis-alpine) + NAME="Redis 7 Alpine" + REDIS_DOCKER_IMAGE="redis:7-alpine" + ;; + valkey) + NAME="Valkey 8" + REDIS_DOCKER_IMAGE="valkey/valkey:8" + ;; + valkey-alpine) + NAME="Valkey 8 Alpine" + REDIS_DOCKER_IMAGE="valkey/valkey:8-alpine" + ;; + ""|--help|-h) + show_help + ;; + *) + NAME="$REDIS_DOCKER_IMAGE" + # Allow unknown image, nothing to override + ;; +esac + +check_docker_image +cleanup +optimize_config +use_docker_image + +echo +echo "✅ Redis backend: $REDIS_DOCKER_IMAGE" +if [[ "$REDIS_CONFIG" == "optimized" || "$REDIS_CONFIG" == "optimize" ]]; then + echo "⚙️ Redis config: optimized" +else + echo "⚙️ Redis config: default" +fi + +echo +echo "📝 Commit the '.ddev' directory to version control" + +echo +echo "🔄 Redis config available after 'ddev restart'" diff --git a/.ddev/commands/redis/redis-cli b/.ddev/commands/redis/redis-cli new file mode 100755 index 0000000..faf556d --- /dev/null +++ b/.ddev/commands/redis/redis-cli @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +#ddev-generated +## Description: Run redis-cli inside the Redis container +## Usage: redis-cli [flags] [args] +## Example: "ddev redis-cli KEYS *" or "ddev redis-cli INFO" or "ddev redis-cli --version" +## Aliases: redis + +if [ -f /etc/redis/conf/security.conf ]; then + redis-cli -p 6379 -h redis -a redis --no-auth-warning $@ +else + redis-cli -p 6379 -h redis $@ +fi diff --git a/.ddev/commands/redis/redis-flush b/.ddev/commands/redis/redis-flush new file mode 100755 index 0000000..5d57c02 --- /dev/null +++ b/.ddev/commands/redis/redis-flush @@ -0,0 +1,12 @@ +#!/usr/bin/env sh + +#ddev-generated +## Description: Flush all cache inside the Redis container +## Usage: redis-flush +## Example: "ddev redis-flush" + +if [ -f /etc/redis/conf/security.conf ]; then + redis-cli -p 6379 -h redis -a redis --no-auth-warning FLUSHALL ASYNC +else + redis-cli -p 6379 -h redis FLUSHALL ASYNC +fi diff --git a/.ddev/config.yaml b/.ddev/config.yaml new file mode 100644 index 0000000..9d152aa --- /dev/null +++ b/.ddev/config.yaml @@ -0,0 +1,307 @@ +name: server +type: wordpress +docroot: "" +php_version: "8.3" +webserver_type: nginx-fpm +xdebug_enabled: false +additional_hostnames: [] +additional_fqdns: [] +database: + type: mysql + version: "8.0" +use_dns_when_possible: true +composer_version: "2" +web_environment: [] +corepack_enable: true +use_ssh_agent: true +host_db_port: "33333" +hooks: + post-start: + - composer: install --no-ansi --no-interaction --optimize-autoloader --apcu-autoloader + +# Key features of DDEV's config.yaml: + +# name: # Name of the project, automatically provides +# http://projectname.ddev.site and https://projectname.ddev.site +# If the name is omitted, the project will take the name of the enclosing directory, +# which is useful if you want to have a copy of the project side by side with this one. + +# type: # backdrop, cakephp, craftcms, drupal, drupal6, drupal7, drupal8, drupal9, drupal10, drupal11, generic, laravel, magento, magento2, php, shopware6, silverstripe, symfony, typo3, wordpress +# See https://ddev.readthedocs.io/en/stable/users/quickstart/ for more +# information on the different project types + +# docroot: # Relative path to the directory containing index.php. + +# php_version: "8.3" # PHP version to use, "5.6" through "8.4" + +# You can explicitly specify the webimage but this +# is not recommended, as the images are often closely tied to DDEV's' behavior, +# so this can break upgrades. + +# webimage: # nginx/php docker image. + +# database: +# type: # mysql, mariadb, postgres +# version: # database version, like "10.11" or "8.0" +# MariaDB versions can be 5.5-10.8, 10.11, and 11.4. +# MySQL versions can be 5.5-8.0. +# PostgreSQL versions can be 9-17. + +# router_http_port: # Port to be used for http (defaults to global configuration, usually 80) +# router_https_port: # Port for https (defaults to global configuration, usually 443) + +# xdebug_enabled: false # Set to true to enable Xdebug and "ddev start" or "ddev restart" +# Note that for most people the commands +# "ddev xdebug" to enable Xdebug and "ddev xdebug off" to disable it work better, +# as leaving Xdebug enabled all the time is a big performance hit. + +# xhgui_https_port: 8142 +# Can be used to change the router https port for xhgui application +# Very rarely used + +# xhgui_http_port: 8143 +# Can be used to change the router http port for xhgui application +# Very rarely used + +# host_xhgui_port: 8142 +# Can be used to change the host binding port of the xhgui +# application. Rarely used; only when port conflict and +# bind_all_ports is used (normally with router disabled) + +# xhprof_enabled: false # Set to true to enable Xhprof and "ddev start" or "ddev restart" +# Note that for most people the commands +# "ddev xhprof" to enable Xhprof and "ddev xhprof off" to disable it work better, +# as leaving Xhprof enabled all the time is a big performance hit. + +# xhprof_mode: [prepend|xhgui|global] +# Set to "xhgui" to enable XHGui features +# "xhgui" will become default in a future major release + +# webserver_type: nginx-fpm, apache-fpm, generic + +# timezone: Europe/Berlin +# If timezone is unset, DDEV will attempt to derive it from the host system timezone +# using the $TZ environment variable or the /etc/localtime symlink. +# This is the timezone used in the containers and by PHP; +# it can be set to any valid timezone, +# see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones +# For example Europe/Dublin or MST7MDT + +# composer_root: +# Relative path to the Composer root directory from the project root. This is +# the directory which contains the composer.json and where all Composer related +# commands are executed. + +# composer_version: "2" +# You can set it to "" or "2" (default) for Composer v2 or "1" for Composer v1 +# to use the latest major version available at the time your container is built. +# It is also possible to use each other Composer version channel. This includes: +# - 2.2 (latest Composer LTS version) +# - stable +# - preview +# - snapshot +# Alternatively, an explicit Composer version may be specified, for example "2.2.18". +# To reinstall Composer after the image was built, run "ddev debug rebuild". + +# nodejs_version: "22" +# change from the default system Node.js version to any other version. +# See https://ddev.readthedocs.io/en/stable/users/configuration/config/#nodejs_version for more information +# and https://www.npmjs.com/package/n#specifying-nodejs-versions for the full documentation, +# Note that using of 'ddev nvm' is discouraged because "nodejs_version" is much easier to use, +# can specify any version, and is more robust than using 'nvm'. + +# corepack_enable: false +# Change to 'true' to 'corepack enable' and gain access to latest versions of yarn/pnpm + +# additional_hostnames: +# - somename +# - someothername +# would provide http and https URLs for "somename.ddev.site" +# and "someothername.ddev.site". + +# additional_fqdns: +# - example.com +# - sub1.example.com +# would provide http and https URLs for "example.com" and "sub1.example.com" +# Please take care with this because it can cause great confusion. + +# upload_dirs: "custom/upload/dir" +# +# upload_dirs: +# - custom/upload/dir +# - ../private +# +# would set the destination paths for ddev import-files to /custom/upload/dir +# When Mutagen is enabled this path is bind-mounted so that all the files +# in the upload_dirs don't have to be synced into Mutagen. + +# disable_upload_dirs_warning: false +# If true, turns off the normal warning that says +# "You have Mutagen enabled and your 'php' project type doesn't have upload_dirs set" + +# ddev_version_constraint: "" +# Example: +# ddev_version_constraint: ">= 1.22.4" +# This will enforce that the running ddev version is within this constraint. +# See https://github.com/Masterminds/semver#checking-version-constraints for +# supported constraint formats + +# working_dir: +# web: /var/www/html +# db: /home +# would set the default working directory for the web and db services. +# These values specify the destination directory for ddev ssh and the +# directory in which commands passed into ddev exec are run. + +# omit_containers: [db, ddev-ssh-agent] +# Currently only these containers are supported. Some containers can also be +# omitted globally in the ~/.ddev/global_config.yaml. Note that if you omit +# the "db" container, several standard features of DDEV that access the +# database container will be unusable. In the global configuration it is also +# possible to omit ddev-router, but not here. + +# performance_mode: "global" +# DDEV offers performance optimization strategies to improve the filesystem +# performance depending on your host system. Should be configured globally. +# +# If set, will override the global config. Possible values are: +# - "global": uses the value from the global config. +# - "none": disables performance optimization for this project. +# - "mutagen": enables Mutagen for this project. +# - "nfs": enables NFS for this project. +# +# See https://ddev.readthedocs.io/en/stable/users/install/performance/#nfs +# See https://ddev.readthedocs.io/en/stable/users/install/performance/#mutagen + +# fail_on_hook_fail: False +# Decide whether 'ddev start' should be interrupted by a failing hook + +# host_https_port: "59002" +# The host port binding for https can be explicitly specified. It is +# dynamic unless otherwise specified. +# This is not used by most people, most people use the *router* instead +# of the localhost port. + +# host_webserver_port: "59001" +# The host port binding for the ddev-webserver can be explicitly specified. It is +# dynamic unless otherwise specified. +# This is not used by most people, most people use the *router* instead +# of the localhost port. + +# host_db_port: "59002" +# The host port binding for the ddev-dbserver can be explicitly specified. It is dynamic +# unless explicitly specified. + +# mailpit_http_port: "8025" +# mailpit_https_port: "8026" +# The Mailpit ports can be changed from the default 8025 and 8026 + +# host_mailpit_port: "8025" +# The mailpit port is not normally bound on the host at all, instead being routed +# through ddev-router, but it can be bound directly to localhost if specified here. + +# webimage_extra_packages: [php7.4-tidy, php-bcmath] +# Extra Debian packages that are needed in the webimage can be added here + +# dbimage_extra_packages: [telnet,netcat] +# Extra Debian packages that are needed in the dbimage can be added here + +# use_dns_when_possible: true +# If the host has internet access and the domain configured can +# successfully be looked up, DNS will be used for hostname resolution +# instead of editing /etc/hosts +# Defaults to true + +# project_tld: ddev.site +# The top-level domain used for project URLs +# The default "ddev.site" allows DNS lookup via a wildcard +# If you prefer you can change this to "ddev.local" to preserve +# pre-v1.9 behavior. + +# ngrok_args: --basic-auth username:pass1234 +# Provide extra flags to the "ngrok http" command, see +# https://ngrok.com/docs/ngrok-agent/config or run "ngrok http -h" + +# disable_settings_management: false +# If true, DDEV will not create CMS-specific settings files like +# Drupal's settings.php/settings.ddev.php or TYPO3's additional.php +# In this case the user must provide all such settings. + +# You can inject environment variables into the web container with: +# web_environment: +# - SOMEENV=somevalue +# - SOMEOTHERENV=someothervalue + +# no_project_mount: false +# (Experimental) If true, DDEV will not mount the project into the web container; +# the user is responsible for mounting it manually or via a script. +# This is to enable experimentation with alternate file mounting strategies. +# For advanced users only! + +# bind_all_interfaces: false +# If true, host ports will be bound on all network interfaces, +# not the localhost interface only. This means that ports +# will be available on the local network if the host firewall +# allows it. + +# default_container_timeout: 120 +# The default time that DDEV waits for all containers to become ready can be increased from +# the default 120. This helps in importing huge databases, for example. + +#web_extra_exposed_ports: +#- name: nodejs +# container_port: 3000 +# http_port: 2999 +# https_port: 3000 +#- name: something +# container_port: 4000 +# https_port: 4000 +# http_port: 3999 +# Allows a set of extra ports to be exposed via ddev-router +# Fill in all three fields even if you don’t intend to use the https_port! +# If you don’t add https_port, then it defaults to 0 and ddev-router will fail to start. +# +# The port behavior on the ddev-webserver must be arranged separately, for example +# using web_extra_daemons. +# For example, with a web app on port 3000 inside the container, this config would +# expose that web app on https://.ddev.site:9999 and http://.ddev.site:9998 +# web_extra_exposed_ports: +# - name: myapp +# container_port: 3000 +# http_port: 9998 +# https_port: 9999 + +#web_extra_daemons: +#- name: "http-1" +# command: "/var/www/html/node_modules/.bin/http-server -p 3000" +# directory: /var/www/html +#- name: "http-2" +# command: "/var/www/html/node_modules/.bin/http-server /var/www/html/sub -p 3000" +# directory: /var/www/html + +# override_config: false +# By default, config.*.yaml files are *merged* into the configuration +# But this means that some things can't be overridden +# For example, if you have 'use_dns_when_possible: true'' you can't override it with a merge +# and you can't erase existing hooks or all environment variables. +# However, with "override_config: true" in a particular config.*.yaml file, +# 'use_dns_when_possible: false' can override the existing values, and +# hooks: +# post-start: [] +# or +# web_environment: [] +# or +# additional_hostnames: [] +# can have their intended affect. 'override_config' affects only behavior of the +# config.*.yaml file it exists in. + +# Many DDEV commands can be extended to run tasks before or after the +# DDEV command is executed, for example "post-start", "post-import-db", +# "pre-composer", "post-composer" +# See https://ddev.readthedocs.io/en/stable/users/extend/custom-commands/ for more +# information on the commands that can be extended and the tasks you can define +# for them. Example: +#hooks: +# Un-comment to emit the WP CLI version after ddev start. +# post-start: +# - exec: wp cli version diff --git a/.ddev/docker-compose.redis.yaml b/.ddev/docker-compose.redis.yaml new file mode 100644 index 0000000..2711768 --- /dev/null +++ b/.ddev/docker-compose.redis.yaml @@ -0,0 +1,21 @@ +#ddev-generated +services: + redis: + container_name: ddev-${DDEV_SITENAME}-redis + image: ${REDIS_DOCKER_IMAGE:-redis:7} + # These labels ensure this service is discoverable by ddev. + labels: + com.ddev.site-name: ${DDEV_SITENAME} + com.ddev.approot: ${DDEV_APPROOT} + restart: "no" + expose: + - 6379 + volumes: + - ".:/mnt/ddev_config" + - "ddev-global-cache:/mnt/ddev-global-cache" + - "./redis:/etc/redis/conf" + - "redis:/data" + command: /etc/redis/conf/redis.conf + +volumes: + redis: diff --git a/.ddev/nginx_full/nginx-site.conf b/.ddev/nginx_full/nginx-site.conf new file mode 100644 index 0000000..3987467 --- /dev/null +++ b/.ddev/nginx_full/nginx-site.conf @@ -0,0 +1,106 @@ +# ddev wordpress config +# https://developer.wordpress.org/advanced-administration/server/web-server/nginx/ + +# If you want to take over this file and customize it, remove the line above +# and ddev will respect it and won't overwrite the file. +# See https://ddev.readthedocs.io/en/stable/users/extend/customization-extendibility/#custom-nginx-configuration + +# Much of this config is adapted from +# https://codex.wordpress.org/Nginx + +server { + listen 80 default_server; + listen 443 ssl default_server; + + root /var/www/html; + + ssl_certificate /etc/ssl/certs/master.crt; + ssl_certificate_key /etc/ssl/certs/master.key; + + include /etc/nginx/monitoring.conf; + + index index.php index.htm index.html; + + # Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html + sendfile off; + error_log /dev/stdout info; + access_log /var/log/nginx/access.log; + + # From wordpress demo global_restrictions.conf + # Global restrictions configuration file. + # Designed to be included in any server {} block. + location = /favicon.ico { + log_not_found off; + access_log off; + } + + location = /robots.txt { + allow all; + log_not_found off; + access_log off; + } + + # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). + # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) + location ~ /\. { + deny all; + } + + # Deny access to any files with a .php extension in the uploads directory + # Works in sub-directory installs and also in multisite network + # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) + location ~* /(?:uploads|files)/.*\.php$ { + deny all; + } + + # Redirect all wp-... request to the wordpress subfolder + location ~ ^/wp-(.*)$ { + return 301 /wordpress/wp-$1; + } + + location / { + absolute_redirect off; + # This is cool because no php is touched for static content. + # include the "?$args" part so non-default permalinks doesn't break when using query string + try_files $uri $uri/ /index.php?$args; + } + + # pass the PHP scripts to FastCGI server listening on socket + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass unix:/run/php-fpm.sock; + fastcgi_buffers 16 16k; + fastcgi_buffer_size 32k; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param SCRIPT_NAME $fastcgi_script_name; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_intercept_errors off; + # fastcgi_read_timeout should match max_execution_time in php.ini + fastcgi_read_timeout 10m; + fastcgi_param SERVER_NAME $host; + fastcgi_param HTTPS $fcgi_https; + # Pass the X-Accel-* headers to facilitate testing. + fastcgi_pass_header "X-Accel-Buffering"; + fastcgi_pass_header "X-Accel-Charset"; + fastcgi_pass_header "X-Accel-Expires"; + fastcgi_pass_header "X-Accel-Limit-Rate"; + fastcgi_pass_header "X-Accel-Redirect"; + } + + # Expire rules for static content + + # Media: images, icons, video, audio, HTC + location ~* \.(jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|webp|htc)$ { + expires max; + log_not_found off; + try_files $uri /index.php$is_args$args; + } + location ~* \.(js|css)$ { + expires -1; + log_not_found off; + } + include /etc/nginx/common.d/*.conf; + include /mnt/ddev_config/nginx/*.conf; +} diff --git a/.ddev/redis/redis.conf b/.ddev/redis/redis.conf new file mode 100644 index 0000000..937c4e5 --- /dev/null +++ b/.ddev/redis/redis.conf @@ -0,0 +1,13 @@ +# Redis configuration. +# #ddev-generated +# Example configuration files for reference: +# http://download.redis.io/redis-stable/redis.conf +# http://download.redis.io/redis-stable/sentinel.conf + +maxmemory 2048mb +maxmemory-policy allkeys-lfu + +# to disable Redis persistence, remove ddev-generated from this file, +# and uncomment the two lines below: +#appendonly no +#save "" diff --git a/.gitignore b/.gitignore index 435de94..4aa8173 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ content/plugins/ !content/plugins/f-translate vendor/ wordpress/ +content/debug.log diff --git a/README.md b/README.md index 4cc14d7..0845278 100644 --- a/README.md +++ b/README.md @@ -5,17 +5,7 @@ This is the overarching repo for the code deployed to our hosted server, running ## Local Development -This repository is pre-configured with wp-env configuration. (Better Docker Compose setup coming soon!) - -You can set up a local environment using: - -```sh -# First, install Composer dependencies. -composer install - -# Then, start an environment. -npx @wordpress/env start -``` +see [docs/local_development.md](docs/local_development.md) ## Deployment diff --git a/docs/local_development.md b/docs/local_development.md new file mode 100644 index 0000000..8f1918e --- /dev/null +++ b/docs/local_development.md @@ -0,0 +1,58 @@ +# local development + +## DDEV (preferred way) + +Prerequesites: + +https://ddev.readthedocs.io/en/stable/users/install/ddev-installation/ + +Then you can set up and start a local environment using: + +```sh +ddev start +``` + +DDEV will tell you, if anything else is missing to successfully run the local development server. + +If you get the `can not connect to database error` maybe the multisite installation is not finished. +Run in terminal: + +```sh +ddev wp core multisite-install --url=server.ddev.site --title=Server --admin_user=admin --admin_password=admin --admin_email=admin@fair.local +``` + +The local site can be reached at: +https://server.ddev.site + +Login via: +``` +user: admin +pw: admin +``` + +## Composer + +If you are using ddev, then `composer install ...` will be run automatically after ddev started. So you don't needd to manually run that. + +## WP -CLI + +If you use ddev, just add `ddev` in front of the command, to run it inside the docker environment. + +Like +``` +ddev wp core version +``` + +## WP ENV (previous way) + +This repository is pre-configured with wp-env configuration. + +You can set up a local environment using: + +```sh +# First, install Composer dependencies. +composer install + +# Then, start an environment. +npx @wordpress/env start +``` \ No newline at end of file diff --git a/wp-config.php b/wp-config.php index a0c358d..691e834 100644 --- a/wp-config.php +++ b/wp-config.php @@ -1,4 +1,6 @@ Date: Sun, 13 Jul 2025 17:24:12 +0200 Subject: [PATCH 3/7] chore(composer): rename to fairpm --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a51a72b..35c9585 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "openwebff/server", + "name": "fairpm/server", "type": "project", "repositories": [ { From 196feb8a3edf97547a6d2495fbc22adb2d3be848 Mon Sep 17 00:00:00 2001 From: Micha Krapp Date: Mon, 14 Jul 2025 02:43:44 +0200 Subject: [PATCH 4/7] fix(ddev): fix assets and login --- .config/env.php | 17 +++++++++++++++++ content/db.php | 1 + wp-config.php | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 120000 content/db.php diff --git a/.config/env.php b/.config/env.php index 2b76ab1..849ce87 100644 --- a/.config/env.php +++ b/.config/env.php @@ -5,19 +5,36 @@ defined( 'WP_HOME' ) or define( 'WP_HOME', getenv( 'WP_HOME' ) ); defined( 'WP_SITEURL' ) or define( 'WP_SITEURL', getenv( 'WP_SITEURL' ) ); +define( 'CURRENT_PATH', '/wordpress/' ); +// Multisite Cookie +define('ADMIN_COOKIE_PATH', '/'); +define('COOKIE_DOMAIN', ''); +define('COOKIEPATH', ''); +define('SITECOOKIEPATH', ''); + +// Database defined( 'DB_HOST' ) or define( 'DB_HOST', getenv( 'DB_HOST' ) ); defined( 'DB_USER' ) or define( 'DB_USER', getenv( 'DB_USER' ) ); defined( 'DB_PASSWORD' ) or define( 'DB_PASSWORD', getenv( 'DB_PASSWORD' ) ); defined( 'DB_NAME' ) or define( 'DB_NAME', getenv( 'DB_NAME' ) ); +// Elasticsearch define( 'ELASTICSEARCH_HOST', getenv( 'ELASTICSEARCH_HOST' ) ); define( 'ELASTICSEARCH_PORT', getenv( 'ELASTICSEARCH_PORT' ) ); +// AWS if ( ! defined( 'AWS_XRAY_DAEMON_IP_ADDRESS' ) ) { define( 'AWS_XRAY_DAEMON_IP_ADDRESS', gethostbyname( getenv( 'AWS_XRAY_DAEMON_HOST' ) ) ); } +// SSL +define('FORCE_SSL_ADMIN', true); +if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) { + $_SERVER['HTTPS']='on'; +} + +// Redis define( 'REDIS_HOST', getenv( 'REDIS_HOST' ) ); define( 'REDIS_PORT', getenv( 'REDIS_PORT' ) ); define( 'REDIS_SECURE', false ); diff --git a/content/db.php b/content/db.php new file mode 120000 index 0000000..9580696 --- /dev/null +++ b/content/db.php @@ -0,0 +1 @@ +/var/www/html/content/plugins/query-monitor/wp-content/db.php \ No newline at end of file diff --git a/wp-config.php b/wp-config.php index 691e834..12d5735 100644 --- a/wp-config.php +++ b/wp-config.php @@ -9,7 +9,7 @@ * phpcs:disable PSR1.Files.SideEffects */ - if ( defined( 'WP_CLI' ) && WP_CLI && ! isset( $_SERVER['HTTP_HOST'] ) ) $_SERVER['HTTP_HOST'] = ''; +if ( defined( 'WP_CLI' ) && WP_CLI && ! isset( $_SERVER['HTTP_HOST'] ) ) $_SERVER['HTTP_HOST'] = ''; if ( defined( 'WP_CLI' ) && WP_CLI && ! isset( $_SERVER['SERVER_PORT'] ) ) $_SERVER['SERVER_PORT'] = ''; // Load an escape hatch early load file, if it exists. From 7e8411aa70128044ab076bc3afc86a18dbd0662d Mon Sep 17 00:00:00 2001 From: Micha Krapp Date: Mon, 14 Jul 2025 02:44:01 +0200 Subject: [PATCH 5/7] feat(ddev): add phpmyadmin --- .ddev/addon-metadata/phpmyadmin/manifest.yaml | 10 +++++++ .ddev/commands/host/phpmyadmin | 19 ++++++++++++ .ddev/docker-compose.phpmyadmin.yaml | 30 +++++++++++++++++++ .ddev/docker-compose.phpmyadmin_norouter.yaml | 4 +++ 4 files changed, 63 insertions(+) create mode 100644 .ddev/addon-metadata/phpmyadmin/manifest.yaml create mode 100755 .ddev/commands/host/phpmyadmin create mode 100644 .ddev/docker-compose.phpmyadmin.yaml create mode 100644 .ddev/docker-compose.phpmyadmin_norouter.yaml diff --git a/.ddev/addon-metadata/phpmyadmin/manifest.yaml b/.ddev/addon-metadata/phpmyadmin/manifest.yaml new file mode 100644 index 0000000..b7ab021 --- /dev/null +++ b/.ddev/addon-metadata/phpmyadmin/manifest.yaml @@ -0,0 +1,10 @@ +name: phpmyadmin +repository: ddev/ddev-phpmyadmin +version: v1.0.0 +install_date: "2025-07-14T02:04:15+02:00" +project_files: + - docker-compose.phpmyadmin.yaml + - docker-compose.phpmyadmin_norouter.yaml + - commands/host/phpmyadmin +global_files: [] +removal_actions: [] diff --git a/.ddev/commands/host/phpmyadmin b/.ddev/commands/host/phpmyadmin new file mode 100755 index 0000000..c03ee85 --- /dev/null +++ b/.ddev/commands/host/phpmyadmin @@ -0,0 +1,19 @@ +#!/bin/bash + +## #ddev-generated: If you want to edit and own this file, remove this line. +## Description: Launch a browser with PhpMyAdmin +## Usage: phpmyadmin +## Example: "ddev phpmyadmin" + +DDEV_PHPMYADMIN_PORT=8036 +DDEV_PHPMYADMIN_HTTPS_PORT=8037 +if [ ${DDEV_PRIMARY_URL%://*} = "http" ] || [ -n "${GITPOD_WORKSPACE_ID:-}" ] || [ "${CODESPACES:-}" = "true" ]; then + # Gitpod: "gp preview" opens a blank page for PhpMyAdmin, use "xdg-open" instead + if [ "${OSTYPE:-}" = "linux-gnu" ] && [ -n "${GITPOD_WORKSPACE_ID:-}" ] && [ -z "${DDEV_DEBUG:-}" ]; then + xdg-open "$(DDEV_DEBUG=true ddev launch :$DDEV_PHPMYADMIN_PORT | grep "FULLURL" | awk '{print $2}')" + else + ddev launch :$DDEV_PHPMYADMIN_PORT + fi +else + ddev launch :$DDEV_PHPMYADMIN_HTTPS_PORT +fi diff --git a/.ddev/docker-compose.phpmyadmin.yaml b/.ddev/docker-compose.phpmyadmin.yaml new file mode 100644 index 0000000..4551e27 --- /dev/null +++ b/.ddev/docker-compose.phpmyadmin.yaml @@ -0,0 +1,30 @@ +#ddev-generated +services: + phpmyadmin: + container_name: ddev-${DDEV_SITENAME}-phpmyadmin + image: ${PHPMYADMIN_DOCKER_IMAGE:-phpmyadmin:5} + working_dir: "/root" + restart: "no" + labels: + com.ddev.site-name: ${DDEV_SITENAME} + com.ddev.approot: ${DDEV_APPROOT} + volumes: + - ".:/mnt/ddev_config" + - "ddev-global-cache:/mnt/ddev-global-cache" + expose: + - "80" + environment: + - PMA_USER=root + - PMA_PASSWORD=root + - PMA_HOST=db + - PMA_PORT=3306 + - VIRTUAL_HOST=$DDEV_HOSTNAME + - UPLOAD_LIMIT=4000M + - HTTP_EXPOSE=8036:80 + - HTTPS_EXPOSE=8037:80 + healthcheck: + interval: 120s + timeout: 2s + retries: 1 + depends_on: + - db diff --git a/.ddev/docker-compose.phpmyadmin_norouter.yaml b/.ddev/docker-compose.phpmyadmin_norouter.yaml new file mode 100644 index 0000000..f369b69 --- /dev/null +++ b/.ddev/docker-compose.phpmyadmin_norouter.yaml @@ -0,0 +1,4 @@ +#ddev-generated +# If omit_containers[ddev-router] then this file will be replaced +# with another with a `ports` statement to directly expose port 80 to 8036 +services: {} From 10fe37894bdeac4fd39214642f32053f841a2528 Mon Sep 17 00:00:00 2001 From: Micha Krapp Date: Mon, 14 Jul 2025 03:10:43 +0200 Subject: [PATCH 6/7] feat(local): add setup and upddate docs --- .ddev/commands/web/setup | 19 +++++++++++++++++++ docs/local_development.md | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 5 deletions(-) create mode 100755 .ddev/commands/web/setup diff --git a/.ddev/commands/web/setup b/.ddev/commands/web/setup new file mode 100755 index 0000000..9a89291 --- /dev/null +++ b/.ddev/commands/web/setup @@ -0,0 +1,19 @@ +#!/bin/bash + +## Description: Setup WordPress for first usage +## Usage: setup +## Example: "ddev setup" + +if ! wp core is-installed 2>/dev/null; then + # WP is not installed. Let's try installing it. + wp core multisite-install --url=server.ddev.site --title=Server --admin_user=admin --admin_password=admin --admin_email=admin@fair.site.ddev +fi + +# check for the admin urser +if ! wp user get admin 2>/dev/null; then + wp user create admin admin@fair.site.ddev --user_pass=admin +fi + +# set options +wp option update home "https://server.ddev.site" +wp option update siteurl "https://server.ddev.site/wordpress" \ No newline at end of file diff --git a/docs/local_development.md b/docs/local_development.md index 8f1918e..237fc65 100644 --- a/docs/local_development.md +++ b/docs/local_development.md @@ -14,15 +14,20 @@ ddev start DDEV will tell you, if anything else is missing to successfully run the local development server. -If you get the `can not connect to database error` maybe the multisite installation is not finished. +The local site can be reached at: +https://server.ddev.site + +## Installation / Setup + +If you have not setup WordPress before, get the `can not connect to database error` or any related error, maybe the multisite installation is not finished. Run in terminal: ```sh -ddev wp core multisite-install --url=server.ddev.site --title=Server --admin_user=admin --admin_password=admin --admin_email=admin@fair.local +ddev setup ``` -The local site can be reached at: -https://server.ddev.site +Admin URL: +https://server.ddev.site/wordpress/wp-admin/ Login via: ``` @@ -30,11 +35,18 @@ user: admin pw: admin ``` +## DB URLs update + +If you had previously used wp-env the URLs have to be set to the new ddev one. +``` +ddev wp search-replace '' 'https://server.ddev.site' --network +```` + ## Composer If you are using ddev, then `composer install ...` will be run automatically after ddev started. So you don't needd to manually run that. -## WP -CLI +## WP-CLI If you use ddev, just add `ddev` in front of the command, to run it inside the docker environment. @@ -43,6 +55,22 @@ Like ddev wp core version ``` +## Mails + +DDEV has mailpit integrated for local mail handling. +When ddev is running, open it with +``` +ddev mailpit +```` + +## PHPMyAdmin + +The ddev setup has phpmyadmin integrated to easily check db entries. +When ddev is running, open it with +``` +ddev phpmyadmin +```` + ## WP ENV (previous way) This repository is pre-configured with wp-env configuration. From 13f4e9689eec9b931c6b4679929618cce47cb299 Mon Sep 17 00:00:00 2001 From: Micha Krapp Date: Mon, 14 Jul 2025 03:21:44 +0200 Subject: [PATCH 7/7] chore(config): cleanup --- wp-config.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/wp-config.php b/wp-config.php index 12d5735..293f482 100644 --- a/wp-config.php +++ b/wp-config.php @@ -42,8 +42,6 @@ } if ( ! defined( 'WP_CONTENT_URL' ) ) { - //$protocol = ! empty( $_SERVER['HTTPS'] ) ? 'https' : 'http'; - //define( 'WP_CONTENT_URL', $protocol . '://' . $_SERVER['HTTP_HOST'] . '/content' ); define( 'WP_CONTENT_URL', WP_HOME . '/content' ); }