Here's my very minimal setup, which makes Laravel workable in Docker. Previously, it doesn't work, because it didn't include the following line in Nginx
container. (Although error happens in Laravel
container)
root /var/www/html/public;
FROM php:7.2.8-fpm-alpine3.7
# Install tools to download Laravel framework.
RUN apk update && \
apk add git && \
apk add unzip
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Download Laravel framework in correct directory.
RUN composer create-project --prefer-dist laravel/laravel /var/www/html/
# Copy and overwrite with files from host (including hidden file) to Laravel directory.
COPY . /tmp/files-from-host
RUN true | cp -ai /tmp/files-from-host/. /var/www/html/ 2>/dev/null
RUN rm -rf /tmp/files-from-host/
WORKDIR /var/www/html
# Avoid error "The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied"
RUN chown -R www-data:www-data /var/www/html/storage
CMD ["php-fpm", "-F"]
server {
listen 443;
ssl on;
root /var/www/html/public;
ssl_certificate /app/cert.pem;
ssl_certificate_key /app/key.pem;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass laravel:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
FROM nginx:1.13.9-alpine
COPY . /app
RUN rm /etc/nginx/conf.d/default.conf
COPY default.conf /etc/nginx/conf.d/
version: '2'
services:
# Note, SSL cert (cert.pem and key.pem) is generated from cloudflare.
nginx:
build:
context: ./nginx
dockerfile: Dockerfile
restart: always
ports:
- "2053:443"
laravel:
build:
context: ./laravel
dockerfile: Dockerfile
restart: always
You can then access Laravel app using
https://localhost:2053/
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community