# Dockerfile optimized for Google Cloud Run # Use PHP 5.6 with Apache (matches Laravel 5.0 requirements perfectly) FROM php:5.6-apache # Set working directory WORKDIR /var/www/html # Install system dependencies and PHP extensions required for Laravel RUN apt-get update && apt-get install -y \ libpng-dev \ libjpeg62-turbo-dev \ libfreetype6-dev \ libmcrypt-dev \ zlib1g-dev \ zip \ unzip \ git \ curl \ libxml2-dev \ && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ && docker-php-ext-install \ pdo \ pdo_mysql \ mbstring \ zip \ gd \ xml \ mcrypt \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Install Composer RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer # Enable Apache modules and configure RUN a2enmod rewrite headers RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf # Configure Apache document root for Laravel 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 # Copy Apache virtual host configuration COPY < ServerAdmin webmaster@localhost DocumentRoot /var/www/html/public AllowOverride All Require all granted # Logging ErrorLog \${APACHE_LOG_DIR}/error.log CustomLog \${APACHE_LOG_DIR}/access.log combined # Security headers Header always set X-Content-Type-Options nosniff Header always set X-Frame-Options DENY Header always set X-XSS-Protection "1; mode=block" Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains" Header always set Referrer-Policy "strict-origin-when-cross-origin" EOF # Copy application files COPY . /var/www/html/ # Fix Git ownership issue for the repository RUN git config --global --add safe.directory /var/www/html || true # Install PHP dependencies RUN composer install --no-dev --optimize-autoloader --no-interaction # Set proper permissions for Laravel RUN chown -R www-data:www-data /var/www/html \ && chmod -R 755 /var/www/html \ && chmod -R 775 /var/www/html/storage \ && chmod -R 775 /var/www/html/bootstrap/cache # Create .env file from .env.example if it doesn't exist RUN if [ ! -f /var/www/html/.env ]; then \ cp /var/www/html/.env.example /var/www/html/.env; \ fi # Switch to www-data user for Laravel commands to avoid ownership issues USER www-data # Generate application key (will be overridden by environment variables in Cloud Run) RUN php artisan key:generate || true # Clear and cache configuration for production RUN php artisan config:clear || true \ && php artisan route:clear || true \ && php artisan view:clear || true # Switch back to root for the remaining setup USER root # Create startup script COPY <