├── .env.dist ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── doc ├── custom.md ├── schema.png └── schema.pptx ├── docker-compose.yml ├── elk └── logstash │ ├── logstash.conf │ └── patterns │ ├── default.conf │ ├── nginx.conf │ └── symfony.conf ├── nginx ├── Dockerfile ├── nginx.conf └── symfony.conf └── php7-fpm └── Dockerfile /.env.dist: -------------------------------------------------------------------------------- 1 | # Symfony application's path (absolute or relative) 2 | SYMFONY_APP_PATH=../path/to/symfony/folder 3 | 4 | # MySQL 5 | MYSQL_ROOT_PASSWORD=root 6 | MYSQL_DATABASE=mydb 7 | MYSQL_USER=user 8 | MYSQL_PASSWORD=userpass 9 | 10 | # Timezone 11 | TIMEZONE=Europe/Paris 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /logs 2 | /.data 3 | .env 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | env: 4 | DOCKER_COMPOSE_VERSION: 1.8.1 5 | 6 | services: 7 | - docker 8 | 9 | before_install: 10 | - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose 11 | - chmod +x docker-compose 12 | - sudo mv docker-compose /usr/local/bin 13 | - docker-compose -v 14 | - docker -v 15 | # symfony application folder 16 | - mkdir symfony 17 | - cp .env.dist .env 18 | - cat docker-compose.yml 19 | 20 | script: 21 | - docker-compose build 22 | - docker-compose up -d 23 | - docker-compose ps 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Maxence POUTORD 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker Symfony (PHP7-FPM - NGINX - MySQL - ELK) 2 | 3 | [![Build Status](https://travis-ci.org/maxpou/docker-symfony.svg?branch=master)](https://travis-ci.org/maxpou/docker-symfony) 4 | 5 | ![](doc/schema.png) 6 | 7 | Docker-symfony gives you everything you need for developing Symfony application. This complete stack run with docker and [docker-compose (1.7 or higher)](https://docs.docker.com/compose/). 8 | 9 | ## Installation 10 | 11 | 1. Create a `.env` from the `.env.dist` file. Adapt it according to your symfony application 12 | 13 | ```bash 14 | cp .env.dist .env 15 | ``` 16 | 17 | 18 | 2. Build/run containers with (with and without detached mode) 19 | 20 | ```bash 21 | $ docker-compose build 22 | $ docker-compose up -d 23 | ``` 24 | 25 | 3. Update your system host file (add symfony.local) 26 | 27 | ```bash 28 | # UNIX only: get containers IP address and update host (replace IP according to your configuration) (on Windows, edit C:\Windows\System32\drivers\etc\hosts) 29 | $ sudo echo $(docker network inspect bridge | grep Gateway | grep -o -E '([0-9]{1,3}\.){3}[0-9]{1,3}') "symfony.local" >> /etc/hosts 30 | ``` 31 | 32 | **Note:** For **OS X**, please take a look [here](https://docs.docker.com/docker-for-mac/networking/) and for **Windows** read [this](https://docs.docker.com/docker-for-windows/#/step-4-explore-the-application-and-run-examples) (4th step). 33 | 34 | 4. Prepare Symfony app 35 | 1. Update app/config/parameters.yml 36 | 37 | ```yml 38 | # path/to/your/symfony-project/app/config/parameters.yml 39 | parameters: 40 | database_host: db 41 | ``` 42 | 43 | 2. Composer install & create database 44 | 45 | ```bash 46 | $ docker-compose exec php bash 47 | $ composer install 48 | # Symfony2 49 | $ sf doctrine:database:create 50 | $ sf doctrine:schema:update --force 51 | # Only if you have `doctrine/doctrine-fixtures-bundle` installed 52 | $ sf doctrine:fixtures:load --no-interaction 53 | # Symfony3 54 | $ sf3 doctrine:database:create 55 | $ sf3 doctrine:schema:update --force 56 | # Only if you have `doctrine/doctrine-fixtures-bundle` installed 57 | $ sf3 doctrine:fixtures:load --no-interaction 58 | ``` 59 | 60 | 5. Enjoy :-) 61 | 62 | ## Usage 63 | 64 | Just run `docker-compose up -d`, then: 65 | 66 | * Symfony app: visit [symfony.local](http://symfony.local) 67 | * Symfony dev mode: visit [symfony.local/app_dev.php](http://symfony.local/app_dev.php) 68 | * Logs (Kibana): [symfony.local:81](http://symfony.local:81) 69 | * Logs (files location): logs/nginx and logs/symfony 70 | 71 | ## Customize 72 | 73 | If you want to add optionnals containers like Redis, PHPMyAdmin... take a look on [doc/custom.md](doc/custom.md). 74 | 75 | ## How it works? 76 | 77 | Have a look at the `docker-compose.yml` file, here are the `docker-compose` built images: 78 | 79 | * `db`: This is the MySQL database container, 80 | * `php`: This is the PHP-FPM container in which the application volume is mounted, 81 | * `nginx`: This is the Nginx webserver container in which application volume is mounted too, 82 | * `elk`: This is a ELK stack container which uses Logstash to collect logs, send them into Elasticsearch and visualize them with Kibana. 83 | 84 | This results in the following running containers: 85 | 86 | ```bash 87 | $ docker-compose ps 88 | Name Command State Ports 89 | -------------------------------------------------------------------------------------------------- 90 | dockersymfony_db_1 /entrypoint.sh mysqld Up 0.0.0.0:3306->3306/tcp 91 | dockersymfony_elk_1 /usr/bin/supervisord -n -c ... Up 0.0.0.0:81->80/tcp 92 | dockersymfony_nginx_1 nginx Up 443/tcp, 0.0.0.0:80->80/tcp 93 | dockersymfony_php_1 php-fpm Up 0.0.0.0:9000->9000/tcp 94 | ``` 95 | 96 | ## Useful commands 97 | 98 | ```bash 99 | # bash commands 100 | $ docker-compose exec php bash 101 | 102 | # Composer (e.g. composer update) 103 | $ docker-compose exec php composer update 104 | 105 | # SF commands (Tips: there is an alias inside php container) 106 | $ docker-compose exec php php /var/www/symfony/app/console cache:clear # Symfony2 107 | $ docker-compose exec php php /var/www/symfony/bin/console cache:clear # Symfony3 108 | # Same command by using alias 109 | $ docker-compose exec php bash 110 | $ sf cache:clear 111 | 112 | # Retrieve an IP Address (here for the nginx container) 113 | $ docker inspect --format '{{ .NetworkSettings.Networks.dockersymfony_default.IPAddress }}' $(docker ps -f name=nginx -q) 114 | $ docker inspect $(docker ps -f name=nginx -q) | grep IPAddress 115 | 116 | # MySQL commands 117 | $ docker-compose exec db mysql -uroot -p"root" 118 | 119 | # F***ing cache/logs folder 120 | $ sudo chmod -R 777 app/cache app/logs # Symfony2 121 | $ sudo chmod -R 777 var/cache var/logs var/sessions # Symfony3 122 | 123 | # Check CPU consumption 124 | $ docker stats $(docker inspect -f "{{ .Name }}" $(docker ps -q)) 125 | 126 | # Delete all containers 127 | $ docker rm $(docker ps -aq) 128 | 129 | # Delete all images 130 | $ docker rmi $(docker images -q) 131 | ``` 132 | 133 | ## FAQ 134 | 135 | * Got this error: `ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running? 136 | If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.` ? 137 | Run `docker-compose up -d` instead. 138 | 139 | * Permission problem? See [this doc (Setting up Permission)](http://symfony.com/doc/current/book/installation.html#checking-symfony-application-configuration-and-setup) 140 | 141 | * How to config Xdebug? 142 | Xdebug is configured out of the box! 143 | Just config your IDE to connect port `9001` and id key `PHPSTORM` 144 | 145 | ## Contributing 146 | 147 | First of all, **thank you** for contributing ♥ 148 | If you find any typo/misconfiguration/... please send me a PR or open an issue. You can also ping me on [twitter](https://twitter.com/_maxpou). 149 | Also, while creating your Pull Request on GitHub, please write a description which gives the context and/or explains why you are creating it. 150 | -------------------------------------------------------------------------------- /doc/custom.md: -------------------------------------------------------------------------------- 1 | # How to customise this stack 2 | 3 | * [Add PHPMyAdmin](#Add-phpmyadmin) 4 | * [Add Redis](#Add-redis) 5 | 6 | ## Add PHPMyAdmin 7 | 8 | 1. Update docker-compose.yml file and add the following lines: 9 | 10 | ```yml 11 | service: 12 | # ... 13 | phpmyadmin: 14 | image: phpmyadmin/phpmyadmin 15 | ports: 16 | - "8080:80" 17 | ``` 18 | 19 | 2. Visit: [symfony.local:8080](http://symfony.local:8080) 20 | 21 | ## Add Redis 22 | 23 | 1. Update docker-compose.yml file and add the following lines: 24 | 25 | ```yml 26 | service: 27 | # ... 28 | redis: 29 | image: redis:alpine 30 | ports: 31 | - 6379:6379 32 | ``` 33 | 34 | 2. Adapt your Symfony configuration file 35 | 36 | ```yml 37 | # path/to/your/symfony-project/app/config/parameters.yml 38 | parameters: 39 | #... 40 | redis_host: redis 41 | ``` 42 | 43 | :question: Using [SncRedis](https://github.com/snc/SncRedisBundle)? 44 | Your Symfony config file should be like this: 45 | 46 | ```yml 47 | snc_redis: 48 | clients: 49 | default: 50 | type: predis 51 | alias: default 52 | dsn: redis://%redis_host% 53 | ``` 54 | 55 | Access to redis-cli with: 56 | 57 | ```bash 58 | # Redis commands 59 | $ docker-compose exec redis redis-cli 60 | ``` 61 | -------------------------------------------------------------------------------- /doc/schema.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maxpou/docker-symfony/0850b15fe31fdd29626d338e5125c44802c26196/doc/schema.png -------------------------------------------------------------------------------- /doc/schema.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maxpou/docker-symfony/0850b15fe31fdd29626d338e5125c44802c26196/doc/schema.pptx -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | db: 5 | image: mysql 6 | volumes: 7 | - "./.data/db:/var/lib/mysql" 8 | environment: 9 | MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} 10 | MYSQL_DATABASE: ${MYSQL_DATABASE} 11 | MYSQL_USER: ${MYSQL_USER} 12 | MYSQL_PASSWORD: ${MYSQL_PASSWORD} 13 | php: 14 | build: 15 | context: php7-fpm 16 | args: 17 | TIMEZONE: ${TIMEZONE} 18 | volumes: 19 | - ${SYMFONY_APP_PATH}:/var/www/symfony 20 | - ./logs/symfony:/var/www/symfony/app/logs 21 | nginx: 22 | build: nginx 23 | ports: 24 | - 80:80 25 | volumes_from: 26 | - php 27 | volumes: 28 | - ./logs/nginx/:/var/log/nginx 29 | elk: 30 | image: willdurand/elk 31 | ports: 32 | - 81:80 33 | volumes: 34 | - ./elk/logstash:/etc/logstash 35 | - ./elk/logstash/patterns:/opt/logstash/patterns 36 | volumes_from: 37 | - php 38 | - nginx 39 | -------------------------------------------------------------------------------- /elk/logstash/logstash.conf: -------------------------------------------------------------------------------- 1 | input { 2 | file { 3 | type => "nginx_access" 4 | path => "/var/log/nginx/symfony_access.log" 5 | start_position => beginning 6 | } 7 | file { 8 | type => "symfony_dev" 9 | path => "/var/www/symfony/app/logs/dev.log" 10 | start_position => beginning 11 | } 12 | file { 13 | type => "symfony_prod" 14 | path => "/var/www/symfony/app/logs/prod.log" 15 | start_position => beginning 16 | } 17 | } 18 | 19 | filter { 20 | if [type] == "nginx_access" { 21 | grok { 22 | patterns_dir => "./patterns" 23 | match => { "message" => "%{NGINXACCESS}"} 24 | } 25 | } 26 | else if [type] in ["symfony_dev", "symfony_prod"] { 27 | grok { 28 | patterns_dir => "./patterns" 29 | match => { "message" => "%{SYMFONY}"} 30 | } 31 | } 32 | } 33 | 34 | output { 35 | elasticsearch { 36 | host => "localhost" 37 | cluster => "logstash" 38 | } 39 | } -------------------------------------------------------------------------------- /elk/logstash/patterns/default.conf: -------------------------------------------------------------------------------- 1 | USERNAME [a-zA-Z0-9._-]+ 2 | USER %{USERNAME} 3 | INT (?:[+-]?(?:[0-9]+)) 4 | BASE10NUM (?[+-]?(?:(?:[0-9]+(?:\.[0-9]+)?)|(?:\.[0-9]+))) 5 | NUMBER (?:%{BASE10NUM}) 6 | BASE16NUM (?(?"(?>\\.|[^\\"]+)+"|""|(?>'(?>\\.|[^\\']+)+')|''|(?>`(?>\\.|[^\\`]+)+`)|``)) 17 | UUID [A-Fa-f0-9]{8}-(?:[A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12} 18 | # Networking 19 | MAC (?:%{CISCOMAC}|%{WINDOWSMAC}|%{COMMONMAC}) 20 | CISCOMAC (?:(?:[A-Fa-f0-9]{4}\.){2}[A-Fa-f0-9]{4}) 21 | WINDOWSMAC (?:(?:[A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2}) 22 | COMMONMAC (?:(?:[A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}) 23 | IPV6 ((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)? 24 | IPV4 (?/(?>[\w_%!$@:.,-]+|\\.)*)+ 33 | TTY (?:/dev/(pts|tty([pq])?)(\w+)?/?(?:[0-9]+)) 34 | WINPATH (?>[A-Za-z]+:|\\)(?:\\[^\\?*]*)+ 35 | URIPROTO [A-Za-z]+(\+[A-Za-z+]+)? 36 | URIHOST %{IPORHOST}(?::%{POSINT:port})? 37 | # uripath comes loosely from RFC1738, but mostly from what Firefox 38 | # doesn't turn into %XX 39 | URIPATH (?:/[A-Za-z0-9$.+!*'(){},~:;=@#%_\-]*)+ 40 | #URIPARAM \?(?:[A-Za-z0-9]+(?:=(?:[^&]*))?(?:&(?:[A-Za-z0-9]+(?:=(?:[^&]*))?)?)*)? 41 | URIPARAM \?[A-Za-z0-9$.+!*'|(){},~@#%&/=:;_?\-\[\]]* 42 | URIPATHPARAM %{URIPATH}(?:%{URIPARAM})? 43 | URI %{URIPROTO}://(?:%{USER}(?::[^@]*)?@)?(?:%{URIHOST})?(?:%{URIPATHPARAM})? 44 | # Months: January, Feb, 3, 03, 12, December 45 | MONTH \b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\b 46 | MONTHNUM (?:0?[1-9]|1[0-2]) 47 | MONTHNUM2 (?:0[1-9]|1[0-2]) 48 | MONTHDAY (?:(?:0[1-9])|(?:[12][0-9])|(?:3[01])|[1-9]) 49 | # Days: Monday, Tue, Thu, etc... 50 | DAY (?:Mon(?:day)?|Tue(?:sday)?|Wed(?:nesday)?|Thu(?:rsday)?|Fri(?:day)?|Sat(?:urday)?|Sun(?:day)?) 51 | # Years? 52 | YEAR (?>\d\d){1,2} 53 | HOUR (?:2[0123]|[01]?[0-9]) 54 | MINUTE (?:[0-5][0-9]) 55 | # '60' is a leap second in most time standards and thus is valid. 56 | SECOND (?:(?:[0-5]?[0-9]|60)(?:[:.,][0-9]+)?) 57 | TIME (?!<[0-9])%{HOUR}:%{MINUTE}(?::%{SECOND})(?![0-9]) 58 | # datestamp is YYYY/MM/DD-HH:MM:SS.UUUU (or something like it) 59 | DATE_US %{MONTHNUM}[/-]%{MONTHDAY}[/-]%{YEAR} 60 | DATE_EU %{MONTHDAY}[./-]%{MONTHNUM}[./-]%{YEAR} 61 | ISO8601_TIMEZONE (?:Z|[+-]%{HOUR}(?::?%{MINUTE})) 62 | ISO8601_SECOND (?:%{SECOND}|60) 63 | TIMESTAMP_ISO8601 %{YEAR}-%{MONTHNUM}-%{MONTHDAY}[T ]%{HOUR}:?%{MINUTE}(?::?%{SECOND})?%{ISO8601_TIMEZONE}? 64 | DATE %{DATE_US}|%{DATE_EU} 65 | DATESTAMP %{DATE}[- ]%{TIME} 66 | TZ (?:[PMCE][SD]T|UTC) 67 | DATESTAMP_RFC822 %{DAY} %{MONTH} %{MONTHDAY} %{YEAR} %{TIME} %{TZ} 68 | DATESTAMP_RFC2822 %{DAY}, %{MONTHDAY} %{MONTH} %{YEAR} %{TIME} %{ISO8601_TIMEZONE} 69 | DATESTAMP_OTHER %{DAY} %{MONTH} %{MONTHDAY} %{TIME} %{TZ} %{YEAR} 70 | DATESTAMP_EVENTLOG %{YEAR}%{MONTHNUM2}%{MONTHDAY}%{HOUR}%{MINUTE}%{SECOND} 71 | # Syslog Dates: Month Day HH:MM:SS 72 | SYSLOGTIMESTAMP %{MONTH} +%{MONTHDAY} %{TIME} 73 | PROG (?:[\w._/%-]+) 74 | SYSLOGPROG %{PROG:program}(?:\[%{POSINT:pid}\])? 75 | SYSLOGHOST %{IPORHOST} 76 | SYSLOGFACILITY <%{NONNEGINT:facility}.%{NONNEGINT:priority}> 77 | HTTPDATE %{MONTHDAY}/%{MONTH}/%{YEAR}:%{TIME} %{INT} 78 | # Shortcuts 79 | QS %{QUOTEDSTRING} 80 | # Log formats 81 | SYSLOGBASE %{SYSLOGTIMESTAMP:timestamp} (?:%{SYSLOGFACILITY} )?%{SYSLOGHOST:logsource} %{SYSLOGPROG}: 82 | COMMONAPACHELOG %{IPORHOST:clientip} %{USER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\] "(?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})" %{NUMBER:response} (?:%{NUMBER:bytes}|-) 83 | COMBINEDAPACHELOG %{COMMONAPACHELOG} %{QS:referrer} %{QS:agent} 84 | # Log Levels 85 | LOGLEVEL ([Aa]lert|ALERT|[Tt]race|TRACE|[Dd]ebug|DEBUG|[Nn]otice|NOTICE|[Ii]nfo|INFO|[Ww]arn?(?:ing)?|WARN?(?:ING)?|[Ee]rr?(?:or)?|ERR?(?:OR)?|[Cc]rit?(?:ical)?|CRIT?(?:ICAL)?|[Ff]atal|FATAL|[Ss]evere|SEVERE|EMERG(?:ENCY)?|[Ee]merg(?:ency)?) -------------------------------------------------------------------------------- /elk/logstash/patterns/nginx.conf: -------------------------------------------------------------------------------- 1 | NGINXACCESS %{IPORHOST:clientip} %{USER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\] "(?:%{WORD:verb} %{URIPATHPARAM:request}(?: HTTP/%{NUMBER:httpversion})?|-)" %{NUMBER:response} (?:%{NUMBER:bytes}|-) "(?:%{URI:referrer}|-)" %{QS:agent} %{NUMBER:request_time} %{NUMBER:upstream_response_time} %{NUMBER:gzip_ratio} (?:%{WORD:cache_hit}|-)%{GREEDYDATA} -------------------------------------------------------------------------------- /elk/logstash/patterns/symfony.conf: -------------------------------------------------------------------------------- 1 | VERYGREEDYDATA (.|\n)* 2 | 3 | SYMFONY_EXCEPTION [^:]* 4 | 5 | SYMFONY_LOG_TYPE request|security|app|profiler|doctrine|event 6 | SYMFONY_LOG_LEVEL DEBUG|INFO|WARNING|ERROR|CRITICAL|ALERT 7 | SYMFONY_LOG %{SYMFONY_LOG_TYPE:log_type}\.%{SYMFONY_LOG_LEVEL:log_level} 8 | 9 | SYMFONY_PARAMETER "[^"]*":( )?"[^"]*" 10 | SYMFONY_PARAMETERS (%{SYMFONY_PARAMETER}(, )?)* 11 | SYMFONY_CONTEXT {.*} 12 | SYMFONY_REQUEST_METHOD GET|POST|PUT|DELETE|HEAD|OPTIONS|CONNECT 13 | SYMFONY_REQUEST_PARAMETERS {"url":"%{GREEDYDATA:request_url}","ip":"%{IP:request_ip}","http_method":"%{SYMFONY_REQUEST_METHOD:request_method}"} 14 | 15 | SYMFONY_REQUEST_INFO Matched route "%{GREEDYDATA:route}" \(parameters: %{SYMFONY_PARAMETERS:parameters}\) 16 | SYMFONY_REQUEST_UNCAUGHT_EXCEPTION %{SYMFONY_EXCEPTION:exception}: %{VERYGREEDYDATA:exception_message} \(uncaught exception\) at %{VERYGREEDYDATA:exception_file} line %{NUMBER:exception_file_line} 17 | SYMFONY_REQUEST_CRITICAL Exception thrown when handling an exception \(ErrorException: %{GREEDYDATA:exception_message} in %{GREEDYDATA:exception_file} line %{NUMBER:exception_file_line}\) 18 | SYMFONY_SECURITY_WARNING_USER_MISSING Username "%{GREEDYDATA:user}" could not be found. 19 | SYMFONY_SECURITY_INFO_USER_AUTHENTICATED User "%{GREEDYDATA:user}" has been authenticated successfully 20 | SYMFONY_SECURITY_INFO_AUTHENTICATION_FAILED Authentication request failed: %{GREEDYDATA:authentication_fail_reason} 21 | SYMFONY_SECURITY_DEBUG Username "%{GREEDYDATA:user}" was reloaded from user provider. 22 | SYMFONY_EVENT_DEBUG_NOTIFICATION Notified event "%{GREEDYDATA:event}" to listener "%{GREEDYDATA:listener}". 23 | SYMFONY_EVENT_DEBUG_PROPAGATION_STOP Listener "%{GREEDYDATA:listener}" stopped propagation of the event "%{GREEDYDATA:event}". 24 | SYMFONY_DOCTRINE_DEBUG (?<=doctrine.DEBUG: ).* 25 | 26 | SYMFONY_REQUEST %{SYMFONY_REQUEST_INFO}|%{SYMFONY_REQUEST_UNCAUGHT_EXCEPTION}|%{SYMFONY_REQUEST_CRITICAL} 27 | SYMFONY_SECURITY %{SYMFONY_SECURITY_WARNING_USER_MISSING}|%{SYMFONY_SECURITY_INFO_USER_AUTHENTICATED}|%{SYMFONY_SECURITY_DEBUG}|%{SYMFONY_SECURITY_INFO_AUTHENTICATION_FAILED} 28 | SYMFONY_EVENT %{SYMFONY_EVENT_DEBUG_NOTIFICATION}|%{SYMFONY_EVENT_DEBUG_PROPAGATION_STOP} 29 | SYMFONY_DOCTRINE %{SYMFONY_DOCTRINE_DEBUG:doctrine_sql_query} 30 | SYMFONY_VARIOUS_INFO Write SecurityContext in the session|Reloading user from user provider.|Read SecurityContext from the session|Populated SecurityContext with an anonymous Token|Access is denied (and user is neither anonymous, nor remember-me)|Unable to store the profiler information.|Remember-me cookie accepted. 31 | 32 | SYMFONY_LOG_MESSAGE %{SYMFONY_REQUEST}|%{SYMFONY_SECURITY}|%{SYMFONY_EVENT}|%{SYMFONY_DOCTRINE}|%{SYMFONY_VARIOUS_INFO:log_various_info}|%{VERYGREEDYDATA:log_unparsed_message} 33 | 34 | SYMFONY ^\[%{TIMESTAMP_ISO8601:date}\] %{SYMFONY_LOG}: %{SYMFONY_LOG_MESSAGE:log_message} (\[\]|%{SYMFONY_CONTEXT:log_context}) (\[\]|%{SYMFONY_REQUEST_PARAMETERS:log_request}) -------------------------------------------------------------------------------- /nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:jessie 2 | 3 | MAINTAINER Maxence POUTORD 4 | 5 | RUN apt-get update && apt-get install -y \ 6 | nginx 7 | 8 | ADD nginx.conf /etc/nginx/ 9 | ADD symfony.conf /etc/nginx/sites-available/ 10 | 11 | RUN ln -s /etc/nginx/sites-available/symfony.conf /etc/nginx/sites-enabled/symfony \ 12 | && rm /etc/nginx/sites-enabled/default 13 | 14 | RUN echo "upstream php-upstream { server php:9000; }" > /etc/nginx/conf.d/upstream.conf 15 | 16 | RUN usermod -u 1000 www-data 17 | 18 | CMD ["nginx"] 19 | 20 | EXPOSE 80 21 | EXPOSE 443 22 | -------------------------------------------------------------------------------- /nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | user www-data; 2 | worker_processes 4; 3 | pid /run/nginx.pid; 4 | 5 | events { 6 | worker_connections 2048; 7 | multi_accept on; 8 | use epoll; 9 | } 10 | 11 | http { 12 | server_tokens off; 13 | sendfile on; 14 | tcp_nopush on; 15 | tcp_nodelay on; 16 | keepalive_timeout 15; 17 | types_hash_max_size 2048; 18 | include /etc/nginx/mime.types; 19 | default_type application/octet-stream; 20 | access_log off; 21 | error_log off; 22 | gzip on; 23 | gzip_disable "msie6"; 24 | include /etc/nginx/conf.d/*.conf; 25 | include /etc/nginx/sites-enabled/*; 26 | open_file_cache max=100; 27 | } 28 | 29 | daemon off; 30 | -------------------------------------------------------------------------------- /nginx/symfony.conf: -------------------------------------------------------------------------------- 1 | server { 2 | server_name symfony.local; 3 | root /var/www/symfony/web; 4 | 5 | location / { 6 | try_files $uri @rewriteapp; 7 | } 8 | 9 | location @rewriteapp { 10 | rewrite ^(.*)$ /app.php/$1 last; 11 | } 12 | 13 | location ~ ^/(app|app_dev|config)\.php(/|$) { 14 | fastcgi_pass php-upstream; 15 | fastcgi_split_path_info ^(.+\.php)(/.*)$; 16 | include fastcgi_params; 17 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 18 | fastcgi_param HTTPS off; 19 | } 20 | 21 | error_log /var/log/nginx/symfony_error.log; 22 | access_log /var/log/nginx/symfony_access.log; 23 | } 24 | -------------------------------------------------------------------------------- /php7-fpm/Dockerfile: -------------------------------------------------------------------------------- 1 | # See https://github.com/docker-library/php/blob/master/7.1/fpm/Dockerfile 2 | FROM php:7.1-fpm 3 | ARG TIMEZONE 4 | 5 | MAINTAINER Maxence POUTORD 6 | 7 | RUN apt-get update && apt-get install -y \ 8 | openssl \ 9 | git \ 10 | unzip 11 | 12 | # Install Composer 13 | RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ 14 | && composer --version 15 | 16 | # Set timezone 17 | RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone \ 18 | && printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini \ 19 | && "date" 20 | 21 | # Type docker-php-ext-install to see available extensions 22 | RUN docker-php-ext-install pdo pdo_mysql 23 | 24 | 25 | # install xdebug 26 | RUN pecl install xdebug \ 27 | && docker-php-ext-enable xdebug \ 28 | && echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ 29 | && echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ 30 | && echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ 31 | && echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ 32 | && echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ 33 | && echo "xdebug.idekey=\"PHPSTORM\"" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ 34 | && echo "xdebug.remote_port=9001" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini 35 | 36 | 37 | RUN echo 'alias sf="php app/console"' >> ~/.bashrc \ 38 | && echo 'alias sf3="php bin/console"' >> ~/.bashrc 39 | 40 | WORKDIR /var/www/symfony 41 | --------------------------------------------------------------------------------