deploymate / app /templates /docker /dockerfile_php.j2
shakauthossain's picture
V2.0.0
2df0cf9 verified
# PHP {{ config.phpVersion or '8.3' }} Dockerfile with Apache
FROM php:{{ config.phpVersion or '8.3' }}-apache
WORKDIR /var/www/html
# Install system dependencies
RUN apt-get update && apt-get install -y \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
zip \
unzip \
git \
&& rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype --with-jpeg && \
docker-php-ext-install -j$(nproc) \
gd \
pdo \
pdo_mysql \
mysqli \
opcache
{% if config.composer %}
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Copy composer files
COPY composer.json composer.lock* ./
# Install dependencies
{% if config.developmentMode %}
RUN composer install --no-interaction
{% else %}
RUN composer install --no-dev --no-interaction --optimize-autoloader
{% endif %}
{% endif %}
# Copy application code
COPY . .
# Set permissions
RUN chown -R www-data:www-data /var/www/html && \
chmod -R 755 /var/www/html
{% if not config.developmentMode %}
# Enable Apache rewrite module
RUN a2enmod rewrite
# Configure Apache for production
RUN echo "ServerTokens Prod" >> /etc/apache2/apache2.conf && \
echo "ServerSignature Off" >> /etc/apache2/apache2.conf
{% endif %}
# Expose port
EXPOSE {{ config.port or '80' }}
{% if config.developmentMode %}
# Development mode
ENV ENVIRONMENT=development
CMD ["apache2-foreground"]
{% else %}
# Production mode
ENV ENVIRONMENT=production
# Start Apache
CMD ["apache2-foreground"]
{% endif %}