# Use PHP 7.4 with Apache for Laravel 6.x FROM php:7.4-apache # Install system dependencies RUN apt-get update && apt-get install -y \ git \ curl \ libpng-dev \ libonig-dev \ libxml2-dev \ libzip-dev \ zip \ unzip \ libfreetype6-dev \ libjpeg62-turbo-dev \ openssh-client \ && docker-php-ext-configure gd --with-freetype --with-jpeg \ && docker-php-ext-install -j$(nproc) gd # Install PHP extensions (mcrypt removed - not available in PHP 7.4) RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath zip # Enable Apache mod_rewrite RUN a2enmod rewrite # Install Composer (version 2.x for Laravel 6.x) COPY --from=composer:2 /usr/bin/composer /usr/bin/composer # Set working directory WORKDIR /var/www/html # Copy existing application directory contents COPY . /var/www/html # Create storage directories and set permissions RUN mkdir -p storage/framework/views \ storage/framework/cache \ storage/framework/sessions \ storage/logs \ bootstrap/cache # Set proper ownership and permissions RUN chown -R www-data:www-data /var/www/html \ && chmod -R 775 /var/www/html/storage \ && chmod -R 775 /var/www/html/bootstrap/cache # Create .env file if it doesn't exist RUN if [ ! -f .env ]; then cp .env.example .env; fi # Install PHP dependencies # Note: composer install will be run via docker-entrypoint.sh or manually # to avoid build-time network timeouts # RUN composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader # Generate application key (will be done at runtime) # RUN php artisan key:generate || true # Cache Laravel configuration and routes (will be done at runtime) # RUN php artisan config:cache || true # RUN php artisan route:cache || true # Configure Apache DocumentRoot to point to Laravel's public directory ENV APACHE_DOCUMENT_ROOT=/var/www/html/public RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf # Suppress Apache ServerName warning RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf # Copy entrypoint script COPY docker-entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/docker-entrypoint.sh # Expose port 80 EXPOSE 80 # Use entrypoint to set up permissions before starting Apache ENTRYPOINT ["docker-entrypoint.sh"] CMD ["apache2-foreground"]