From 29c2d595aed84848147f1a017c6268fd1f101b7c Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 4 Apr 2024 19:11:33 +0100 Subject: [PATCH] Switch from nginx to Apache So I can use a .htaccess file for wildcard redirects. --- .env.example | 2 +- Dockerfile | 20 +++++------------ build.yaml | 7 +++--- docker-compose.yaml | 14 +++--------- .../apache2/sites-available/000-default.conf | 8 +++++++ .../web/root/etc/nginx/conf.d/default.conf | 22 ------------------- 6 files changed, 22 insertions(+), 51 deletions(-) create mode 100644 tools/docker/images/php/root/etc/apache2/sites-available/000-default.conf delete mode 100644 tools/docker/images/web/root/etc/nginx/conf.d/default.conf diff --git a/.env.example b/.env.example index 0ab996e..4dccd6f 100644 --- a/.env.example +++ b/.env.example @@ -5,7 +5,7 @@ export DOCKER_UID=1000 export COMPOSE_PROJECT_NAME=oliverdavies-uk export COMPOSE_PROFILES=web,php,database -export DOCKER_WEB_VOLUME=.:/app +export DOCKER_WEB_VOLUME=.:/var/www/html export MYSQL_DATABASE=app export MYSQL_PASSWORD=app diff --git a/Dockerfile b/Dockerfile index 02289a6..fb5dda9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs. -FROM php:8.2-fpm-bullseye AS base +FROM php:8.2-apache AS base COPY --from=composer:2 /usr/bin/composer /usr/bin/composer RUN which composer && composer -V @@ -8,14 +8,14 @@ RUN which composer && composer -V ARG DOCKER_UID=1000 ENV DOCKER_UID="${DOCKER_UID}" -WORKDIR /app +WORKDIR /var/www/html RUN adduser --disabled-password --uid "${DOCKER_UID}" app \ - && chown app:app -R /app + && chown app:app -R /var/www/html USER app -ENV PATH="${PATH}:/app/bin:/app/vendor/bin" +ENV PATH="${PATH}:/var/www/html/bin:/var/www/html/vendor/bin" COPY --chown=app:app composer.* ./ @@ -25,6 +25,7 @@ FROM base AS build USER root +RUN a2enmod rewrite RUN apt-get update -yqq \ && apt-get install -yqq --no-install-recommends \ @@ -48,17 +49,8 @@ RUN composer install --quiet --no-progress COPY --chown=app:app tools/docker/images/php/root / ENTRYPOINT ["/usr/local/bin/docker-entrypoint-php"] -CMD ["php-fpm"] +CMD ["apache2-foreground"] -################################################################################ - -FROM nginx:1 as web - -EXPOSE 8080 - -WORKDIR /app - -COPY tools/docker/images/web/root / diff --git a/build.yaml b/build.yaml index 423957e..6070815 100644 --- a/build.yaml +++ b/build.yaml @@ -2,8 +2,10 @@ name: oliverdavies-uk type: drupal language: php +project_root: /var/www/html + web: - type: nginx + type: apache database: type: mariadb @@ -11,7 +13,7 @@ database: extra_databases: [] php: - version: 8.2-fpm-bullseye + version: 8.2-apache phpcs: paths: - web/modules/custom @@ -29,7 +31,6 @@ docker-compose: services: - database - php - - web dockerfile: stages: diff --git a/docker-compose.yaml b/docker-compose.yaml index fa1f56c..d6ba068 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -12,7 +12,7 @@ x-proxy: &default-proxy x-app: &default-app volumes: - - "${DOCKER_WEB_VOLUME:-./web:/app/web}" + - "${DOCKER_WEB_VOLUME:-./web:/var/www/html/web}" env_file: - .env restart: "${DOCKER_RESTART_POLICY:-unless-stopped}" @@ -28,24 +28,16 @@ x-app: &default-app tty: true services: - web: - <<: [*default-proxy, *default-app] - build: - context: . - target: web - depends_on: - - php - profiles: [web] php: - <<: [*default-app] + <<: [*default-proxy, *default-app] build: context: . target: build args: - "DOCKER_UID=${DOCKER_UID:-1000}" volumes: - - .:/app + - .:/var/www/html depends_on: - database profiles: [php] diff --git a/tools/docker/images/php/root/etc/apache2/sites-available/000-default.conf b/tools/docker/images/php/root/etc/apache2/sites-available/000-default.conf new file mode 100644 index 0000000..dcc84ea --- /dev/null +++ b/tools/docker/images/php/root/etc/apache2/sites-available/000-default.conf @@ -0,0 +1,8 @@ +# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs. + + + DocumentRoot /var/www/html/web + + ErrorLog ${APACHE_LOG_DIR}/error.log + CustomLog ${APACHE_LOG_DIR}/access.log combined + diff --git a/tools/docker/images/web/root/etc/nginx/conf.d/default.conf b/tools/docker/images/web/root/etc/nginx/conf.d/default.conf deleted file mode 100644 index 13e395a..0000000 --- a/tools/docker/images/web/root/etc/nginx/conf.d/default.conf +++ /dev/null @@ -1,22 +0,0 @@ -# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs. - -server { - server_name _; - - root /app/web; - - location / { - try_files $uri /index.php?$query_string; - } - - location ~ \.php(/|$) { - fastcgi_split_path_info ^(.+?\.php)(|/.*)$; - try_files $fastcgi_script_name =404; - include fastcgi_params; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param QUERY_STRING $query_string; - fastcgi_intercept_errors on; - fastcgi_pass php:9000; - } -}