8000 feature: added Readme and updated to PHP 7.4 · ger86/symfony-docker@c432068 · GitHub
[go: up one dir, main page]

Skip to content

Commit c432068

Browse files
author
Gerardo Fernández
committed
feature: added Readme and updated to PHP 7.4
1 parent 6fdb78e commit c432068

File tree

10 files changed

+193
-62
lines changed

10 files changed

+193
-62
lines changed

.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
MYSQL_ROOT_PASSWORD=hello
2+
MYSQL_DATABASE=app_db
3+
MYSQL_USER=app_user
4+
MYSQL_PASSWORD=helloworld
5+
6+
TIMEZONE=Europe/Madrid

Dockerfile-php

Lines changed: 0 additions & 18 deletions
This file was deleted.

Readme.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# 🐳 Docker + PHP 7.4 + MySQL + Nginx + Symfony 5 Boilerplate
2+
3+
## Description
4+
5+
This is a complete stack for running Symfony 5 into Docker containers using docker-compose tool.
6+
7+
It is composed by 3 containers:
8+
9+
- `nginx`, acting as the webserver.
10+
- `php`, the PHP-FPM container with the 7.4 PHPversion.
11+
- `db` which is the MySQL database container with a **MySQL 8.0** image.
12+
13+
## Installation
14+
15+
1. 😀 Clone this rep.
16+
17+
2. Run `docker-compose up -d`
18+
19+
3. The 3 containers are deployed:
20+
21+
```
22+
Creating symfony-docker_db_1 ... done
23+
Creating symfony-docker_php_1 ... done
24+
Creating symfony-docker_nginx_1 ... done
25+
```
26+
27+
4. Use this value for the DATABASE_URL environment variable of Symfony:
28+
29+
```
30+
DATABASE_URL=mysql://app_user:helloworld@db:3306/app_db?serverVersion=5.7
31+
```
32+
33+
You could change the name, user and password of the database in the `env` file at the root of the project.
34+

build/nginx/default.conf

Lines changed: 0 additions & 24 deletions
This file was deleted.

docker-compose.yml

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
11
version: '3'
22

33
services:
4-
nginx:
5-
build:
6-
context: .
7-
dockerfile: Dockerfile-nginx
4+
db:
5+
image: mysql:8.0.20
6+
command: --default-authentication-plugin=mysql_native_password
87
volumes:
9-
- ./symfony/:/var/www/symfony/
8+
- "db_app:/var/lib/mysql"
9+
environment:
10+
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
11+
MYSQL_DATABASE: ${MYSQL_DATABASE}
12+
MYSQL_USER: ${MYSQL_USER}
13+
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
1014
ports:
11-
- 8001:80
15+
- 3306:3306
1216
networks:
1317
- symfony
1418
php:
1519
build:
1620
context: .
17-
dockerfile: Dockerfile-php
18-
environment:
19-
APP_ENV: dev
20-
DATABASE_URL: mysql://root:root@mysql:3306/symfony_db?serverVersion=5.7
21+
dockerfile: docker/php/Dockerfile
22+
args:
23+
TIMEZONE: ${TIMEZONE}
2124
volumes:
2225
- ./symfony/:/var/www/symfony/
2326
networks:
2427
- symfony
25-
depends_on:
26-
- mysql
27-
mysql:
28-
image: mysql
29-
command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password']
30-
environment:
31-
MYSQL_ROOT_PASSWORD: root
32-
ports:
33-
- 3306:3306
28+
nginx:
29+
build:
30+
context: .
31+
dockerfile: docker/nginx/Dockerfile
3432
volumes:
35-
- ./mysql:/var/lib/mysql
33+
- ./symfony/:/var/www/symfony/
34+
ports:
35+
- 80:80
3636
networks:
3737
- symfony
38+
39+
volumes:
40+
db_app:
41+
3842
networks:
3943
symfony:

docker/nginx/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM nginx:1.17.8-alpine
2+
3+
COPY docker/nginx/nginx.conf /etc/nginx/
4+
COPY docker/nginx/default.conf /etc/nginx/conf.d/
5+
RUN echo "upstream php-upstream { server php:9000; }" > /etc/nginx/conf.d/upstream.conf
6+
7+
EXPOSE 80
8+
EXPOSE 443

docker/nginx/default.conf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
server {
2+
listen 80;
3+
server_name dev.symfony.com;
4+
root /var/www/symfony/public;
5+
6+
location / {
7+
try_files $uri /index.php$is_args$args;
8+
}
9+
10+
location ~ ^/index\.php(/|$) {
11+
if ($request_method = 'OPTIONS') {
12+
add_header 'Access-Control-Allow-Origin' '*' always;
13+
add_header 'Access-Control-Allow-Methods' 'GET, POST, DELETE, OPTIONS' always;
14+
add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
15+
add_header 'Access-Control-Max-Age' 1728000 always;
16+
add_header 'Content-Type' 'text/plain; charset=utf-8' always;
17+
add_header 'Content-Length' 0 always;
18+
return 204;
19+
}
20+
add_header 'Access-Control-Allow-Origin' '*' always;
21+
add_header 'Access-Control-Allow-Methods' 'GET, POST, DELETE, OPTIONS' always;
22+
add_header 'Access-Control-Allow-Headers' 'Authorization,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
23+
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
24+
25+
fastcgi_pass php:9000;
26+
fastcgi_split_path_info ^(.+\.php)(/.*)$;
27+
include fastcgi_params;
28+
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
29+
fastcgi_param DOCUMENT_ROOT $realpath_root;
30+
internal;
31+
}
32+
location ~ \.php$ {
33+
return 404;
34+
}
35+
36+
error_log /dev/stdout info;
37+
access_log /var/log/nginx/project_access.log;
38+
}

docker/nginx/nginx.conf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
user nginx;
3+
worker_processes auto;
4+
5+
error_log /var/log/nginx/error.log warn;
6+
pid /var/run/nginx.pid;
7+
8+
9+
events {
10+
worker_connections 1024;
11+
}
12+
13+
14+
http {
15+
include /etc/nginx/mime.types;
16+
default_type application/octet-stream;
17+
client_max_body_size 0;
18+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
19+
'$status $body_bytes_sent "$http_referer" '
20+
'"$http_user_agent" "$http_x_forwarded_for"';
21+
22+
access_log /var/log/nginx/access.log main;
23+
24+
sendfile on;
25+
#tcp_nopush on;
26+
27+
keepalive_timeout 65;
28+
29+
gzip on;
30+
31+
include /etc/nginx/conf.d/*.conf;
32+
}

docker/php/Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
FROM php:7.4-fpm-buster
2+
ARG TIMEZONE
3+
4+
COPY docker/php/php.ini /usr/local/etc/php/conf.d/docker-php-config.ini
5+
6+
RUN apt-get update && apt-get install -y \
7+
gnupg \
8+
g++ \
9+
procps \
10+
openssl \
11+
git \
12+
unzip \
13+
zlib1g-dev \
14+
libzip-dev \
15+
libfreetype6-dev \
16+
libpng-dev \
17+
libjpeg-dev \
18+
libicu-dev \
19+
libonig-dev \
20+
libxslt1-dev \
21+
acl \
22+
&& echo 'alias sf="php bin/console"' >> ~/.bashrc
23+
24+
RUN docker-php-ext-configure gd --with-jpeg --with-freetype
25+
26+
RUN docker-php-ext-install \
27+
pdo pdo_mysql zip xsl gd intl opcache exif mbstring
28+
29+
# Set timezone
30+
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone \
31+
&& printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini \
32+
&& "date"
33+
34+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
35+
&& composer --version \
36+
&& composer global require hirak/prestissimo
37+
38+
WORKDIR /var/www/symfony

docker/php/php.ini

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
memory_limit=1024M
2+
3+
opcache.enable=1
4+
opcache.revalidate_freq=10
5+
opcache.validate_timestamps=1
6+
opcache.max_accelerated_files=10000
7+
opcache.memory_consumption=192
8+
opcache.max_wasted_percentage=10
9+
opcache.interned_strings_buffer=1
10+
opcache.fast_shutdown=1
11+
12+
upload_max_filesize = 20M
13+
post_max_size = 20M

0 commit comments

Comments
 (0)
0