Skip to content

Commit

Permalink
www-data home directory & more efficient build php container
Browse files Browse the repository at this point in the history
  • Loading branch information
jasperf committed Dec 28, 2024
1 parent a598fe3 commit 21a4841
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 121 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# macOS system files
.DS_Store
**/.DS_Store
# ACF Pro
site/auth.json
site/web/.bash_history
site/web/.lesshst
150 changes: 40 additions & 110 deletions container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,136 +3,73 @@ FROM php:8.3.13-fpm-bookworm
# Set up www-data user properly
RUN usermod -u 1000 www-data && \
usermod -s /bin/bash www-data && \
mkdir -p /srv/www/web && \
chown www-data:www-data /srv/www/web && \
usermod -d /srv/www/web www-data
mkdir -p /srv/www && \
mkdir -p /home/www-data && \
chown www-data:www-data /srv/www && \
chown www-data:www-data /home/www-data && \
usermod -d /home/www-data www-data

# PHP extensions for WordPress
RUN \
# Recommended extensions
# curl
# already built in and enabled
# dom
# already built in and enabled
# exif
# build and install using built-in docker script
docker-php-ext-configure exif && \
docker-php-ext-install -j$(nproc) exif && \
# fileinfo
# already built in and enabled
# hash
# already built in and enabled
# json
# already built in and enabled
# mbstring
# already built in and enabled
# mysqli
# build and install using built-in docker script
docker-php-ext-configure mysqli && \
docker-php-ext-install -j$(nproc) mysqli

RUN \
# sodium
# already built in and enabled
# openssl
# already built in and enabled
# pcre
# already built in and enabled
# imagick (+GhostScript for PDF support)
# install build dependencies
apt-get update && \
# Install all required system packages at once
RUN apt-get update && \
apt-get install -y \
libmagickwand-dev \
ghostscript \
imagemagick \
libmagickcore-dev \
--no-install-recommends && \
# Install specific stable imagick version compatible with PHP 8.3
libzip-dev \
libjpeg-dev \
libpng-dev \
libfreetype6-dev \
libmcrypt-dev \
git \
unzip \
sudo \
less \
--no-install-recommends

# Install PHP extensions
RUN \
# exif
docker-php-ext-configure exif && \
docker-php-ext-install -j$(nproc) exif && \
# mysqli
docker-php-ext-configure mysqli && \
docker-php-ext-install -j$(nproc) mysqli && \
# imagick
pecl install imagick-3.7.0 && \
docker-php-ext-enable imagick && \
# Verify imagick installation
php -m | grep imagick && \
# Configure policy to allow PDF operations
# Configure imagick policy
{ \
echo '<?xml version="1.0" encoding="UTF-8"?>'; \
echo '<policymap>'; \
echo ' <policy domain="coder" rights="read|write" pattern="PDF" />'; \
echo ' <policy domain="coder" rights="read|write" pattern="LABEL" />'; \
echo '</policymap>'; \
} > /etc/ImageMagick-6/policy.xml

RUN \
# xml
# already built in and enabled
# zip
# install build dependencies
apt-get update && \
apt-get install -y \
libzip-dev \
--no-install-recommends && \
# build and install using built-in docker script
} > /etc/ImageMagick-6/policy.xml && \
# zip
docker-php-ext-install -j$(nproc) zip && \
docker-php-ext-enable zip

RUN \
# fallback extensions
# filter
# already built in and enabled
# gd
# install build dependencies
apt-get update && \
apt-get install -y \
libjpeg-dev \
libpng-dev \
libzip-dev \
libfreetype6-dev \
--no-install-recommends && \
# build and install using built-in docker script
docker-php-ext-configure gd \
--with-freetype --with-jpeg && \
docker-php-ext-install -j$(nproc) gd

RUN \
# iconv
# already built in and enabled
# mcrypt
# install build dependencies
apt-get update && \
apt-get install -y \
libmcrypt-dev \
git \
--no-install-recommends && \
# build and install from source
docker-php-ext-enable zip && \
# gd
docker-php-ext-configure gd --with-freetype --with-jpeg && \
docker-php-ext-install -j$(nproc) gd && \
# mcrypt
mkdir -p /usr/src/php/ext/mcrypt && \
curl -fsSL https://github.com/php/pecl-encryption-mcrypt/archive/master.tar.gz | tar xvz -C "/usr/src/php/ext/mcrypt" --strip 1 && \
docker-php-ext-configure mcrypt && \
docker-php-ext-install mcrypt

RUN \
# simplexml
# already built in and enabled
# xmlreader
# already built in and enabled
# zlib
# already built in and enabled
# Trellis additional/differing extensions
# opcache
# build and install using built-in docker script
docker-php-ext-install mcrypt && \
# opcache
docker-php-ext-configure opcache && \
docker-php-ext-install -j$(nproc) opcache

# Install Composer, unzip, and git
RUN \
apt-get update && \
apt-get install -y unzip git --no-install-recommends && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
ln -s /usr/local/bin/composer /usr/local/bin/php-composer

# Install WP-CLI
RUN curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \
chmod +x wp-cli.phar && \
mv wp-cli.phar /usr/local/bin/wp && \
# Create wp-cli directory for www-data user
# Create wp-cli directory for www-data user in proper location
mkdir -p /srv/www/.wp-cli && \
chown www-data:www-data /srv/www/.wp-cli

Expand All @@ -141,13 +78,6 @@ RUN echo '#!/bin/sh' > /usr/local/bin/wp-cli && \
echo 'su -s /bin/bash www-data -c "wp $*"' >> /usr/local/bin/wp-cli && \
chmod +x /usr/local/bin/wp-cli

# Install required tools
RUN apt-get update && \
apt-get install -y \
sudo \
less \
--no-install-recommends

# Configure sudo for www-data
RUN echo "www-data ALL=(ALL) NOPASSWD: /usr/local/bin/wp" >> /etc/sudoers.d/wp-cli && \
chmod 0440 /etc/sudoers.d/wp-cli
Expand Down
19 changes: 12 additions & 7 deletions site/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ web/app/uploads/*
!web/app/uploads/.gitkeep
web/app/cache/*

# Container
web/.cache
web/.yarn
web/.composer
web/.wp-cli

# Database data
imwz_2024-11-14.sql

Expand All @@ -38,4 +32,15 @@ auth.json
wp-cli.local.yml

# trellis database uploads migration
database_backup/*
database_backup/*

# ACF
auth.json


# Docker
# .lesshst
# .bash_history
# .cache
# .composer
# .yarn

0 comments on commit 21a4841

Please sign in to comment.