Skip to content

Commit 4c5b4a4

Browse files
committed
Docker: installation symfony demo
1 parent d699381 commit 4c5b4a4

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed

.docker/php/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM php:7.4-fpm
22

33
# Some libs
4-
RUN apt-get update && apt-get install -y --no-install-recommends vim curl locales apt-utils
4+
RUN apt-get update && apt-get install -y --no-install-recommends vim curl locales apt-utils unzip
55

66
# https://github.com/mlocati/docker-php-extension-installer
77
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/

.docker/php/symfony-demo.env

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# In all environments, the following files are loaded if they exist,
2+
# the latter taking precedence over the former:
3+
#
4+
# * .env contains default values for the environment variables needed by the app
5+
# * .env.local uncommitted file with local overrides
6+
# * .env.$APP_ENV committed environment-specific defaults
7+
# * .env.$APP_ENV.local uncommitted environment-specific overrides
8+
#
9+
# Real environment variables win over .env files.
10+
#
11+
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
12+
#
13+
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
14+
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
15+
16+
###> symfony/framework-bundle ###
17+
APP_ENV=dev
18+
APP_SECRET=2bd64f8d83b2e89d5f19d612841d6bb9
19+
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
20+
#TRUSTED_HOSTS='^(localhost|example\.com)$'
21+
###< symfony/framework-bundle ###
22+
23+
###> doctrine/doctrine-bundle ###
24+
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
25+
# For a MySQL database, use: "mysql://db_user:db_password@127.0.0.1:3306/db_name"
26+
# For a PostgreSQL database, use: "postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=11&charset=utf8"
27+
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
28+
DATABASE_URL=mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE}
29+
###< doctrine/doctrine-bundle ###
30+
31+
###> symfony/mailer ###
32+
MAILER_DSN=smtp://maildev:25
33+
###< symfony/mailer ###

Makefile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ install: docker-compose.override.yml build up composer-install perm ## Create a
3636
install-demo:
3737
@$(EXEC_ROOT) chmod 775 /var/www
3838
@$(EXEC_ROOT) chown www-data:www-data /var/www
39+
@rm -rf project/* project/.env
3940
$(call composer,create-project symfony/symfony-demo demo)
40-
@$(EXEC_ROOT) bash -c "mv demo/* . && rm -rf demo/"
41-
# todo: change doctrine config (use mysql instead sqlite)
42-
make clear-cache
41+
@cp .docker/php/symfony-demo.env project/.env
42+
@$(EXEC_ROOT) bash -c "mv demo/* . && rm -rf demo/ data/"
43+
@make restart perm db-create-migration db-install db-fixtures clear-cache
4344

4445
status: ## Docker container status
4546
@$(DOCKER_COMPOSE) ps
@@ -91,6 +92,9 @@ server-dump: ## [Dev only] Display dump() values with tail (ctrl+C to stop)
9192
db-diff: ## Generate a migration by comparing your current database to your mapping information
9293
@$(EXEC) $(CONSOLE) doctrine:migration:diff
9394

95+
db-create-migration: ## Create migration
96+
@$(EXEC) $(CONSOLE) make:migration
97+
9498
db-migrate: ## Migrate database schema to the latest available version
9599
@$(EXEC) $(CONSOLE) doctrine:migration:migrate -n --env=$(ENV)
96100

@@ -166,8 +170,8 @@ up-ci:
166170
@$(DOCKER_COMPOSE) up -d --remove-orphans
167171

168172
perm: ## Set folder permissions
169-
@$(EXEC_ROOT) chmod -R 775 var
170-
@$(EXEC_ROOT) chgrp -R www-data var
173+
@$(EXEC_ROOT) chmod -R 775 var migrations
174+
@$(EXEC_ROOT) chgrp -R www-data var migrations
171175
@$(EXEC_ROOT) bash -c "chmod +x bin/* vendor/bin/*"
172176

173177
#docker-compose.override.yml:

docker-compose.dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ services:
5353
- maildev.localhost.tv
5454

5555
traefik:
56-
image: traefik
56+
image: traefik:v1.7
5757
command: -c /dev/null --api --docker --docker.domain=.localhost.tv --logLevel=DEBUG
5858
ports:
5959
- 80:80

docker-compose.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ services:
1616
restart: always
1717
depends_on:
1818
- php
19-
user: "${VOLUME_USER_ID:-www-data}:www-data"
2019
networks:
2120
sfdemo:
2221
aliases:
@@ -40,6 +39,12 @@ services:
4039
php:
4140
build: .docker/php
4241
restart: always
42+
environment:
43+
MYSQL_HOST: db
44+
MYSQL_USER: ${MYSQL_USER}
45+
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
46+
MYSQL_PORT: ${MYSQL_PORT}
47+
MYSQL_DATABASE: ${MYSQL_DATABASE}
4348
volumes:
4449
- ./project:/var/www
4550
- ${COMPOSER_HOME:-/tmp/composer}:/home/www-data/.composer # Share composer cache

readme.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ A Docker image based on Ubuntu, serving PHP 5 or 7 running as Apache Module. Use
1111
## Installation
1212
Before use the docker version, check that ports 80/8080/443 are available. If an Apache / Nginx local server, another docker container are active, they can block access to these ports.
1313

14-
```bash
14+
```shell script
1515
make install
1616
```
1717

@@ -30,6 +30,11 @@ make install
3030
* php-zip
3131
* composer (php package manager)
3232

33+
For test Nginx/php container, you can install Symfony Demo
34+
```shell script
35+
make install-demo
36+
```
37+
3338

3439
## Usage
3540
Launch docker containers: `make up`, or stop with `make stop`, you can get command list with `make help`.

0 commit comments

Comments
 (0)