Skip to content

Commit 46f138a

Browse files
authored
Merge branch 'main' into feat/super-linter
2 parents 4ff224d + 9ac02d6 commit 46f138a

File tree

6 files changed

+91
-6
lines changed

6 files changed

+91
-6
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ with [FrankenPHP](https://frankenphp.dev) and [Caddy](https://caddyserver.com/)
3737
5. [Debugging with Xdebug](docs/xdebug.md)
3838
6. [TLS Certificates](docs/tls.md)
3939
7. [Using a Makefile](docs/makefile.md)
40-
8. [Troubleshooting](docs/troubleshooting.md)
41-
9. [Updating the template](docs/updating.md)
40+
8. [Using MySQL instead of PostgreSQL](docs/mysql.md)
41+
9. [Troubleshooting](docs/troubleshooting.md)
42+
10. [Updating the template](docs/updating.md)
4243

4344
## License
4445

docs/extra-services.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,11 @@ The currently supported packages are:
88
* `symfony/orm-pack`: install a PostgreSQL service
99
* `symfony/mercure-bundle`: use the Mercure.rocks module shipped with Caddy
1010
* `symfony/panther`: install chromium and these drivers
11-
* `symfony/mailer`: install a MailCatcher service
11+
* `symfony/mailer`: install a Mailpit service
1212
* `blackfireio/blackfire-symfony-meta`: install a Blackfire service
13+
14+
> [!NOTE]
15+
> If a recipe modifies the Dockerfile, the container needs to be rebuilt.
16+
17+
> [!WARNING]
18+
> We recommend that you use the `composer require` command inside the container in development mode so that recipes can be applied correctly

docs/mysql.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Using MySQL
2+
3+
The Docker configuration of this repository is extensible thanks to Flex recipes. By default, the recipe installs PostgreSQL.
4+
If you prefer to work with MySQL, follow these steps:
5+
6+
First, install the `symfony/orm-pack` package as described: `docker compose exec php composer req symfony/orm-pack`
7+
8+
## Docker Configuration
9+
Change the database image to use MySQL instead of PostgreSQL in `compose.yaml`:
10+
11+
```diff
12+
###> doctrine/doctrine-bundle ###
13+
- image: postgres:${POSTGRES_VERSION:-15}-alpine
14+
+ image: mysql:${MYSQL_VERSION:-8}
15+
environment:
16+
- POSTGRES_DB: ${POSTGRES_DB:-app}
17+
+ MYSQL_DATABASE: ${MYSQL_DATABASE:-app}
18+
# You should definitely change the password in production
19+
+ MYSQL_RANDOM_ROOT_PASSWORD: "true"
20+
- POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!}
21+
+ MYSQL_PASSWORD: ${MYSQL_PASSWORD:-!ChangeMe!}
22+
- POSTGRES_USER: ${POSTGRES_USER:-app}
23+
+ MYSQL_USER: ${MYSQL_USER:-app}
24+
volumes:
25+
- - database_data:/var/lib/postgresql/data:rw
26+
+ - database_data:/var/lib/mysql:rw
27+
# You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
28+
- # - ./docker/db/data:/var/lib/postgresql/data:rw
29+
+ # - ./docker/db/data:/var/lib/mysql:rw
30+
###< doctrine/doctrine-bundle ###
31+
```
32+
33+
Depending on the database configuration, modify the environment in the same file at `services.php.environment.DATABASE_URL`
34+
```
35+
DATABASE_URL: mysql://${MYSQL_USER:-app}:${MYSQL_PASSWORD:-!ChangeMe!}@database:3306/${MYSQL_DATABASE:-app}?serverVersion=${MYSQL_VERSION:-8}&charset=${MYSQL_CHARSET:-utf8mb4}
36+
```
37+
38+
Since we changed the port, we also have to define this in the `compose.override.yaml`:
39+
```diff
40+
###> doctrine/doctrine-bundle ###
41+
database:
42+
ports:
43+
- - "5432"
44+
+ - "3306"
45+
###< doctrine/doctrine-bundle ###
46+
```
47+
48+
Last but not least, we need to install the MySQL driver in `Dockerfile`:
49+
```diff
50+
###> doctrine/doctrine-bundle ###
51+
-RUN install-php-extensions pdo_pgsql
52+
+RUN install-php-extensions pdo_mysql
53+
###< doctrine/doctrine-bundle ###
54+
```
55+
56+
## Change Environment
57+
Change the database configuration in `.env`:
58+
59+
```dotenv
60+
DATABASE_URL=mysql://${MYSQL_USER:-app}:${MYSQL_PASSWORD:-!ChangeMe!}@database:3306/${MYSQL_DATABASE:-app}?serverVersion=${MYSQL_VERSION:-8}&charset=${MYSQL_CHARSET:-utf8mb4}
61+
```
62+
63+
## Final steps
64+
Rebuild the docker environment:
65+
```shell
66+
docker compose down --remove-orphans && docker compose build --pull --no-cache
67+
```
68+
69+
Test your setup:
70+
```shell
71+
docker compose exec php bin/console dbal:run-sql -q "SELECT 1" && echo "OK" || echo "Connection is not working"
72+
```

docs/troubleshooting.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ If you work on linux and cannot edit some of the project files right after the f
66

77
## HTTPS and Redirects
88

9-
If Symfony is generating an internal redirect for an `https://` URL, but the resulting URL is `http://`, you have to uncomment the `TRUSTED_PROXIES` setting in your `.env` file.
9+
If Symfony is generating an internal redirect for an `https://` URL, but the resulting URL is `http://`, you have to uncomment the `TRUSTED_PROXIES` setting in your `.env` file and add this line in `config/packages/framework.yaml`:
10+
```
11+
# config/packages/framework.yaml
12+
framework:
13+
trusted_proxies: '%env(TRUSTED_PROXIES)%'
14+
```
15+
1016
For more details see the [Symfony internal redirect documentation](https://symfony.com/doc/current/routing.html#redirecting-to-urls-and-routes-directly-from-a-route).
1117

1218
## TLS/HTTPS Issues

docs/updating.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ To import the changes made to the *Symfony Docker* template into your project, w
66
1. Run the script to synchronize your project with the latest version of the skeleton:
77

88
```console
9-
curl -sSL https://raw.githubusercontent.com/mano-lis/template-sync/main/template-sync.sh | sh -s -- https://github.com/dunglas/symfony-docker
9+
curl -sSL https://raw.githubusercontent.com/coopTilleuls/template-sync/main/template-sync.sh | sh -s -- https://github.com/dunglas/symfony-docker
1010
```
1111

1212
2. Resolve conflicts, if any

frankenphp/Caddyfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
}
2828

2929
root * /app/public
30-
encode zstd gzip
30+
encode zstd br gzip
3131

3232
mercure {
3333
# Transport to use (default to Bolt)

0 commit comments

Comments
 (0)