Skip to content

Commit 27a741b

Browse files
committed
[new] first blood
1 parent 977f9b3 commit 27a741b

File tree

10 files changed

+263
-2
lines changed

10 files changed

+263
-2
lines changed

Diff for: .docker/.env

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Prefix for Docker containers
2+
COMPOSE_PROJECT_NAME=symfony_webapp_docker
3+
4+
# User ID
5+
UID=1000
6+
7+
# DB connection
8+
MYSQL_ROOT_PASSWORD=Root+123
9+
MYSQL_DATABASE=symfony_webapp_docker
10+
MYSQL_USER=admin
11+
MYSQL_PASSWORD=Admin+123
12+
13+
# Timezone
14+
TIMEZONE=Europe/Prague

Diff for: .docker/.env.nginx

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NGINX_BACKEND_DOMAIN='production-domain.com'

Diff for: .docker/.env.nginx.local

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NGINX_BACKEND_DOMAIN='localhost'

Diff for: .docker/docker-compose.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
version: "3"
2+
3+
services:
4+
nginx:
5+
build:
6+
context: ./nginx
7+
volumes:
8+
- ../:/var/www/symfony
9+
ports:
10+
- 80:80
11+
networks:
12+
- symfony_app
13+
env_file:
14+
- .env.nginx.local
15+
php:
16+
user: ${UID}:${UID}
17+
build:
18+
context: ./php
19+
args:
20+
UID: ${UID}
21+
TIMEZONE: ${TIMEZONE}
22+
volumes:
23+
- ../:/var/www/symfony
24+
networks:
25+
- symfony_app
26+
db:
27+
image: mysql:8.0.35
28+
platform: linux/x86_64
29+
command: --default-authentication-plugin=mysql_native_password
30+
volumes:
31+
- "db_app:/var/lib/mysql"
32+
environment:
33+
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
34+
MYSQL_DATABASE: ${MYSQL_DATABASE}
35+
MYSQL_USER: ${MYSQL_USER}
36+
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
37+
ports:
38+
- 3307:3306
39+
networks:
40+
- symfony_app
41+
phpmyadmin:
42+
image: phpmyadmin/phpmyadmin
43+
environment:
44+
PMA_HOST: db
45+
PMA_PORT: 3306
46+
ports:
47+
- 8081:80
48+
networks:
49+
- symfony_app
50+
51+
volumes:
52+
db_app:
53+
54+
networks:
55+
symfony_app:

Diff for: .docker/nginx/Dockerfile

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

Diff for: .docker/nginx/nginx.conf

+32
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+
}

Diff for: .docker/nginx/templates/default.conf.template

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
server {
2+
listen 80;
3+
server_name ${NGINX_BACKEND_DOMAIN};
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+
}

Diff for: .docker/php/Dockerfile

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

Diff for: .docker/php/php.ini

+13
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

Diff for: README.md

+60-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,60 @@
1-
# symfony-webapp-docker
2-
Docker config for latest Symfony web apps with MySQL and phpMyAdmin
1+
# Docker Setup for Symfony 6.3.* Web Apps
2+
3+
Docker containers for traditional Symfony 6.3.* web apps, i.e., apps that you would usually create using the `--webapp` Symfony CLI option or the `composer require webapp` command.
4+
5+
## What is inside
6+
7+
- **Nginx** webserver
8+
- **PHP 8.2** (with `composer`)
9+
- **MySQL 8.0**
10+
- **phpMyAdmin**
11+
12+
## Local dev guide (Linux)
13+
14+
1. Clone the repo:
15+
```.sh
16+
git clone https://github.com/TOA-Anakin/symfony-webapp-docker.git
17+
```
18+
2. Rename the cloned repo as desired:
19+
```.sh
20+
mv symfony-webapp-docker your_project_name
21+
```
22+
3. Find your user ID using the `id -u` command and update the `.docker/.env` file accordingly.
23+
4. `cd` into the `.docker` directory and build the Docker containers:
24+
```.sh
25+
cd your_project_name/.docker
26+
docker compose up -d --build
27+
```
28+
Before the end of the process you should see a list of newly created (now running) containers:
29+
```.sh
30+
[+] Running 6/6
31+
✔ Network symfony_webapp_docker_symfony_app
32+
Created 0.1s
33+
✔ Volume "symfony_webapp_docker_db_app"
34+
Created 0.0s
35+
✔ Container symfony_webapp_docker-phpmyadmin-1
36+
Started 0.2s
37+
✔ Container symfony_webapp_docker-php-1
38+
Started 0.2s
39+
✔ Container symfony_webapp_docker-db-1
40+
Started 0.2s
41+
✔ Container symfony_webapp_docker-nginx-1
42+
Started 0.2s
43+
```
44+
5. Open the terminal of the PHP container (mine is named `symfony_webapp_docker-php-1`) and create a Symfony skeleton project using `composer`:
45+
```.sh
46+
docker exec -it symfony_webapp_docker-php-1 bash
47+
composer create-project symfony/skeleton:"6.3.*" temp_dir
48+
```
49+
Move the contents of `temp_dir` into the project root:
50+
```.sh
51+
mv temp_dir/* .
52+
mv temp_dir/.[!.]* .
53+
rmdir temp_dir
54+
```
55+
Install Symfony web app packages:
56+
```.sh
57+
composer require webapp
58+
```
59+
***Note:*** If you are prompted with a question `Do you want to include Docker configuration from recipes?`, answer `n [No]`.
60+
6. Access your Symfony web app at http://localhost, phpMyAdmin is accessible at http://localhost:8081

0 commit comments

Comments
 (0)