# Use the official PHP image. FROM php:8.4-apache # Set working directory early. WORKDIR /var/www/html # 1. OPTIMIZATION: Combine PHP and Apache configuration into a single RUN layer. # This improves build speed by reducing the number of intermediate image layers. RUN set -ex; \ # Install PHP extensions docker-php-ext-install -j "$(nproc)" opcache mysqli; \ \ # --- PHP Configuration for Cloud Run --- \ # NOTE: Cloud Run enforces memory & timeouts; using 0 and -1 for max values \ echo "short_open_tag = 1" > /usr/local/etc/php/conf.d/cloud-run.ini; \ echo "memory_limit = -1" >> /usr/local/etc/php/conf.d/cloud-run.ini; \ echo "max_execution_time = 0" >> /usr/local/etc/php/conf.d/cloud-run.ini; \ \ # File upload settings \ echo "upload_max_filesize = 32M" >> /usr/local/etc/php/conf.d/cloud-run.ini; \ echo "post_max_size = 32M" >> /usr/local/etc/php/conf.d/cloud-run.ini; \ \ # Configure opcache for Containers \ echo "opcache.enable = 0" >> /usr/local/etc/php/conf.d/cloud-run.ini; \ echo "opcache.validate_timestamps = off" >> /usr/local/etc/php/conf.d/cloud-run.ini; \ \ # Configure opcache Memory (Application-specific) \ echo "opcache.memory_consumption = 32" >> /usr/local/etc/php/conf.d/cloud-run.ini; \ \ # Move the new cloud-run.ini to a production configuration location if desired, # but the conf.d directory is usually sufficient. Original command retained for consistency: # mv $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini.old; \ # mv $PHP_INI_DIR/conf.d/cloud-run.ini $PHP_INI_DIR/php.ini.old; \ \ # --- Apache Configuration --- \ a2enmod rewrite; \ \ # Replace default Apache port 80 with the dynamic $PORT environment variable \ sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf; \ \ # Allow .htaccess to override settings (needed for rewrite rules) \ sed -i '// { N; N; s/AllowOverride None/AllowOverride All/ }' /etc/apache2/apache2.conf # 2. OPTIMIZATION: Move COPY to the end to leverage Docker cache. # If you only change code, all steps above (including dependency installs) # will be reused (cached), significantly speeding up the build. COPY . . # Our own documentation (docs/) must not be public: move it out of the web root. # core/documentation-function.php reads it from /var/www/docs. RUN mv /var/www/html/docs /var/www/docs