0

I have a lot of difficulties setting up a Dockerfile with the relevant architecture and permissions for a Laravel app in an Appache server deployed in Cloud Run.

I am currently facing a 500 Internal Server Error with the current Dockerfile:

FROM php:7.4-apache

# intialize the machine with required apt-get packages and php extensions
RUN apt-get update && apt-get install -y libpng-dev zip unzip wget zlib1g-dev libicu-dev libzip-dev
RUN docker-php-ext-install mysqli pdo_mysql zip exif
RUN apt-get install -y \
    libwebp-dev \
    libjpeg62-turbo-dev \
    libpng-dev libxpm-dev \
    libfreetype6-dev
RUN docker-php-ext-install gd
COPY --from=composer:1.9 /usr/bin/composer /usr/bin/composer

# copy app in full
WORKDIR /var/www/
COPY . /var/www/

# install dependencies
RUN composer global require hirak/prestissimo && composer install

EXPOSE 8080
COPY docker/000-default.conf /etc/apache2/sites-available/000-default.conf
COPY .env.example /var/www/.env
RUN chmod 777 -R /var/www/storage/ && \
    echo "Listen 8080" >> /etc/apache2/ports.conf && \
    chown -R www-data:www-data /var/www/ && \
    a2enmod rewrite

And the following .htaccess in the public folder:

RewriteEngine On
RewriteBase /API/

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Authorization Headers
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

and the 000-default.conf:

<VirtualHost *:8080>

  ServerAdmin admin@email.com
  DocumentRoot /var/www/public/

  <Directory /var/www/>
    AllowOverride All
    Require all granted
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

I tried everything available online, but I really can't figure what's going on.

Could one of you spot any obvious flaws?

mikegross
  • 1,674
  • 2
  • 12
  • 27
  • Did you check the apache logs on the container instance? General logs and vhost-specific logs? – Jeto Aug 12 '20 at 21:09
  • I only get the error when I deploy the image in Cloud Run. And as far as I can see I can't ssh into the container... Is there a way to configure it? – mikegross Aug 12 '20 at 21:26
  • [Not easily](https://stackoverflow.com/questions/56342904/enter-a-docker-container-running-with-google-cloud-run), apparently. – Jeto Aug 12 '20 at 21:30
  • At the minimum you have to COPY before setting the workdir – jogarcia Mar 13 '23 at 01:04

0 Answers0