Skip to content

Instantly share code, notes, and snippets.

@hbjydev
Created July 15, 2020 12:23
Show Gist options
  • Save hbjydev/4ef5bf019cf9fc5dccd210fa2d7f5626 to your computer and use it in GitHub Desktop.
Save hbjydev/4ef5bf019cf9fc5dccd210fa2d7f5626 to your computer and use it in GitHub Desktop.
Laravel Docker Setup
# image from php73.Dockerfile
FROM php73
# configure github auth
ARG github_token
RUN mkdir ~/.composer
RUN echo '{"github-oauth":{"github.com":"'$github_token'"}}' > ~/.composer/auth.json
# include source
COPY . .
# composer install
RUN DB_CONNECTION=sqlite DB_DATABASE=:memory: composer install --prefer-dist --no-interaction
# app setup
RUN DB_CONNECTION=sqlite DB_DATABASE=:memory: php artisan storage:link
# permissions
RUN chown -R www-data:www-data /var/www/html
RUN find /var/www/html -type f -exec chmod 644 {} \;
RUN find /var/www/html -type d -exec chmod 755 {} \;
FROM php:7.3-apache
RUN apt-get update
# 1. development packages
RUN apt-get install -y \
git \
zip \
curl \
sudo \
unzip \
libicu-dev \
libbz2-dev \
libpng-dev \
libjpeg-dev \
libmcrypt-dev \
libreadline-dev \
libfreetype6-dev \
libldap2-dev \
libzip-dev \
g++
# 2. apache configs + document root
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
# 3. mod_rewrite for URL rewrite and mod_headers for .htaccess extra headers like Access-Control-Allow-Origin-
RUN a2enmod rewrite headers
# 4. start with base php config, then add extensions
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
RUN docker-php-ext-install \
bz2 \
intl \
iconv \
bcmath \
opcache \
calendar \
mbstring \
pdo_mysql \
zip \
ldap \
gd
# 5. composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment