From 9e6f6dc25b4fc2c522a3062e19826678c1e4fdb3 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 25 Oct 2023 11:54:07 -0400 Subject: [PATCH] docker: Use mpm_event and php-fpm instead of mpm_prefork and mod_php The main hope here is that using mpm_event rather than mpm_prefork will make our E2E tests run better. But mod_php is not compatible with mpm_event. The modern way to do things is to use php-fpm instead. And while we're at it, we may as well enable apache's http2 module too. Although actually making effective use of that may take more work (if anyone cares), since HTTP/2 likes to run with TLS but our dev environment doesn't do TLS. --- tools/docker/Dockerfile | 8 +++++--- tools/docker/bin/ensure-php-version.sh | 2 +- tools/docker/bin/run.sh | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index a3973b7a09306..265c2f7ce2876 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -27,7 +27,7 @@ RUN --mount=type=cache,target=/var/lib/apt/lists/,sharing=private \ && add-apt-repository ppa:ondrej/php \ && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \ && apt-get update \ - && apt-get install -y \ + && apt-get --purge install -y \ apache2 \ git \ jq \ @@ -38,14 +38,15 @@ RUN --mount=type=cache,target=/var/lib/apt/lists/,sharing=private \ ssmtp \ subversion \ sudo \ + systemd-standalone-tmpfiles \ unzip \ vim \ zip \ && apt-get remove --purge --auto-remove -y gpg software-properties-common \ && find /var/ -name '*-old' -delete && rm -rf /var/log/dpkg.log /var/log/alternatives.log /var/log/apt/ ~/.launchpadlib -# Enable mod_rewrite in Apache. -RUN a2enmod rewrite +# Enable various Apache modules. +RUN a2dismod mpm_prefork && a2enmod rewrite mpm_event proxy_fcgi http2 # Install requested version of PHP. COPY ./config/php.ini /var/lib/jetpack-config/php.ini @@ -53,6 +54,7 @@ RUN --mount=type=cache,target=/var/lib/apt/lists/,sharing=private \ --mount=type=bind,source=./bin/ensure-php-version.sh,target=/usr/local/bin/ensure-php-version.sh \ : "${PHP_VERSION:?Build argument PHP_VERSION needs to be set and non-empty.}" \ && ensure-php-version.sh "$PHP_VERSION" \ + && a2enconf "php$PHP_VERSION-fpm" \ && find /var/ -name '*-old' -delete && rm -rf /var/log/dpkg.log /var/log/alternatives.log /var/log/apt/ ~/.launchpadlib # Install requested version of Composer. diff --git a/tools/docker/bin/ensure-php-version.sh b/tools/docker/bin/ensure-php-version.sh index fa7c384213a52..1019233e52745 100755 --- a/tools/docker/bin/ensure-php-version.sh +++ b/tools/docker/bin/ensure-php-version.sh @@ -20,11 +20,11 @@ export DEBIAN_FRONTEND=noninteractive # Determine packages to install. PKGS=( - "libapache2-mod-php${VER}" "php${VER}" "php${VER}-bcmath" "php${VER}-cli" "php${VER}-curl" + "php${VER}-fpm" "php${VER}-intl" "php${VER}-ldap" "php${VER}-mbstring" diff --git a/tools/docker/bin/run.sh b/tools/docker/bin/run.sh index ad2ae6aa7106e..1d02ce843f06f 100755 --- a/tools/docker/bin/run.sh +++ b/tools/docker/bin/run.sh @@ -7,6 +7,8 @@ set -e # If you modify anything here, remember to build the image again by running: # jetpack docker build-image +source /etc/docker-args.sh + user="${APACHE_RUN_USER:-www-data}" group="${APACHE_RUN_GROUP:-www-data}" @@ -133,5 +135,7 @@ echo "Open http://${WP_DOMAIN}${WP_HOST_PORT}/ to see your site!" echo # Run apache in the foreground so the container keeps running +echo "Running php-fpm" +"/etc/init.d/php${PHP_VERSION}-fpm" start echo "Running Apache in the foreground" apachectl -D FOREGROUND