1 # Stage 1: Build PHP app and install dependencies
2 FROM php:8.3.12 AS builder
6 # Copy the application code
10 RUN apt-get update && apt-get install -y git unzip
13 RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
15 # Install dependencies
16 RUN COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev --optimize-autoloader
18 # Stage 2: Serve the application using Apache PHP
19 FROM php:8.3.12-apache
21 # Copy the built PHP app from the builder stage
22 COPY --from=builder /app /var/www/html
24 RUN apt-get update && apt-get install -y \
34 libmariadb-dev-compat \
37 && pip3 install --break-system-packages mysqlclient \
38 && rm -rf /var/lib/apt/lists/* \
39 && docker-php-ext-configure gd --with-freetype --with-jpeg \
40 && docker-php-ext-install -j$(nproc) gd \
41 && docker-php-ext-install -j$(nproc) pdo_mysql
43 RUN pecl install redis-6.0.2 \
44 && docker-php-ext-enable redis
46 # Use the default production configuration for PHP runtime arguments, see
47 # https://github.com/docker-library/docs/tree/master/php#configuration
48 RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
50 ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
51 RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
52 RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
54 RUN a2enmod rewrite headers && chown -R www-data:www-data /var/www/html
56 ADD ./docker-entrypoint.sh /usr/local/bin/
57 RUN chmod +x /usr/local/bin/docker-entrypoint.sh
59 # Switch to a non-privileged user (defined in the base image) that the app will run under.
60 # See https://docs.docker.com/go/dockerfile-user-best-practices/
65 ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]