danielrataj
8/31/2019 - 12:08 PM

PHP Laravel application with Docker Compose and Nginx for LOCAL development #nginx #laravel

PHP Laravel application with Docker Compose and Nginx for LOCAL development #nginx #laravel

Installation

Create a blog:

docker run --rm --interactive --tty --volume $PWD:/app composer create-project --prefer-dist laravel/laravel APP_FOLDER

Copy docker-compose.yml and blog.conf files (bellow) to the root of your project.

Now start application:

docker-compose down --volumes && docker-compose up

Other tips

Install Composer dependencies

docker run --rm --interactive --tty --volume $PWD:/app   --volume ${COMPOSER_HOME:-$HOME/.composer}:/tmp composer update

Update composer dependencies

docker run --rm --interactive --tty --volume $PWD:/app   --volume ${COMPOSER_HOME:-$HOME/.composer}:/tmp composer update
server {
  listen 0.0.0.0:8080;
  server_name blog.com;
  root /app/public;

  add_header X-Frame-Options "SAMEORIGIN";
  add_header X-XSS-Protection "1; mode=block";
  add_header X-Content-Type-Options "nosniff";

  index index.html index.htm index.php;

  charset utf-8;

  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }

  location = /favicon.ico { access_log off; log_not_found off; }
  location = /robots.txt  { access_log off; log_not_found off; }

  error_page 404 /index.php;

  location ~ \.php$ {
    fastcgi_pass phpfpm:9000;
    fastcgi_index index.php;
    include fastcgi.conf;
  }

  location ~ /\.(?!well-known).* {
    deny all;
  }
}
version: '3'

services:
  phpfpm:
    tty: true
    image: 'bitnami/php-fpm:7.3'
    container_name: phpfpm
    networks:
      - laravel-tier
    volumes:
      - .:/app
      - ./php.ini:/opt/bitnami/php/etc/conf.d/php.ini

  laravel:
    tty: true
    image: 'bitnami/nginx:1.16'
    container_name: laravel
    networks:
      - laravel-tier
    ports:
      - '8080:8080'
    volumes:
      - ./blog.conf:/opt/bitnami/nginx/conf/server_blocks/blog.conf

networks:
  laravel-tier:
    driver: bridge