PHP Laravel application with Docker Compose and Nginx for LOCAL development #nginx #laravel
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
docker run --rm --interactive --tty --volume $PWD:/app --volume ${COMPOSER_HOME:-$HOME/.composer}:/tmp composer update
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
opcache.enable=0