Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed to PHP7, added xdebug support, more reusable #58

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env
@@ -0,0 +1,2 @@
LOG_PATH=./logs
SRC_PATH=./symfony
27 changes: 25 additions & 2 deletions README.md
Expand Up @@ -14,7 +14,16 @@ First, clone this repository:
$ git clone git@github.com:eko/docker-symfony.git
```

Next, put your Symfony application into `symfony` folder and do not forget to add `symfony.dev` in your `/etc/hosts` file.
Add `symfony.dev` in your `/etc/hosts` file.

Either put your Symfony application into `symfony` folder or add `.env` to your symfony project with following content
```yaml
COMPOSE_FILE=../docker-symfony/docker-compose.yml
COMPOSE_PROJECT_NAME=PROJECT_NAME
LOG_PATH=../PROJECT_NAME/logs
SRC_PATH=../PROJECT_NAME/src
XDEBUG_IP_ADDRESS=
```

Make sure you adjust `database_host` in `parameters.yml` to the database container alias "db"

Expand Down Expand Up @@ -50,9 +59,23 @@ This results in the following running containers:
docker_db_1 /entrypoint.sh mysqld Up 0.0.0.0:3306->3306/tcp
docker_elk_1 /usr/bin/supervisord -n -c ... Up 0.0.0.0:81->80/tcp
docker_nginx_1 nginx Up 443/tcp, 0.0.0.0:80->80/tcp
docker_php_1 php5-fpm -F Up 9000/tcp
docker_php_1 php5-fpm -F Up 9001/tcp
```

# Development

Attach to php container to call compose or symfony.

```bash
$ docker-compose exec php /bin/sh
```

## XDebug

* Set local ip in .env, e.g. `XDEBUG_IP_ADDRESS=10.0.75.1` in .env (on windows/mac use VM IP)
* In your IDE set XDebug listen port to 9030. Depending on IDE set IP.
* Use XDebug Helper or similar to start debugging session

# Read logs

You can access Nginx and Symfony application logs in the following directories on your host machine:
Expand Down
10 changes: 6 additions & 4 deletions docker-compose.yml
Expand Up @@ -12,10 +12,12 @@ services:
php:
build: ./php-fpm
expose:
- "9000"
- "9001"
environment:
XDEBUG_CONFIG: remote_host=$XDEBUG_IP_ADDRESS remote_port=9030
volumes:
- ./symfony:/var/www/symfony
- ./logs/symfony:/var/www/symfony/app/logs
- $SRC_PATH:/var/www/symfony
- $LOG_PATH/symfony:/var/www/symfony/app/logs
links:
- db
nginx:
Expand All @@ -27,7 +29,7 @@ services:
volumes_from:
- php
volumes:
- ./logs/nginx/:/var/log/nginx
- $LOG_PATH/nginx/:/var/log/nginx
elk:
image: willdurand/elk
ports:
Expand Down
7 changes: 6 additions & 1 deletion elk/logstash/logstash.conf
Expand Up @@ -4,6 +4,11 @@ input {
path => "/var/log/nginx/symfony_access.log"
start_position => beginning
}
file {
type => "nginx_error"
path => "/var/log/nginx/symfony_error.log"
start_position => beginning
}
file {
type => "symfony_dev"
path => "/var/www/symfony/app/logs/dev.log"
Expand All @@ -17,7 +22,7 @@ input {
}

filter {
if [type] == "nginx_access" {
if [type] in ["nginx_access","nginx_error"] {
grok {
patterns_dir => "./patterns"
match => { "message" => "%{NGINXACCESS}"}
Expand Down
2 changes: 1 addition & 1 deletion nginx/nginx.conf
@@ -1,4 +1,4 @@
user www-data;
user nobody;
worker_processes 4;
pid /run/nginx.pid;

Expand Down
58 changes: 31 additions & 27 deletions php-fpm/Dockerfile
@@ -1,40 +1,44 @@
FROM alpine:3.4
FROM php:7-fpm-alpine

MAINTAINER Vincent Composieux <vincent.composieux@gmail.com>

RUN apk add --update \
php5-fpm \
php5-apcu \
php5-ctype \
php5-curl \
php5-dom \
php5-gd \
php5-iconv \
php5-imagick \
php5-json \
php5-intl \
php5-mcrypt \
php5-mysql \
php5-opcache \
php5-openssl \
php5-pdo \
php5-pdo_mysql \
php5-mysqli \
php5-xml \
php5-zlib \
php5-phar \
curl
RUN apk add --no-cache \
freetype \
libpng \
libjpeg-turbo \
freetype-dev \
libpng-dev \
libjpeg-turbo-dev \
icu-dev \
&& \
NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) && \
docker-php-ext-configure gd \
--with-gd \
--with-freetype-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ && \
docker-php-ext-install -j${NPROC} \
gd \
intl \
opcache \
pdo \
pdo_mysql \
mysqli \
&& apk add --no-cache --virtual .phpize-deps ${PHPIZE_DEPS} \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& apk del .phpize-deps

RUN rm -rf /var/cache/apk/* && rm -rf /tmp/*

RUN curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer
RUN curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony

ADD symfony.ini /etc/php5/fpm/conf.d/
ADD symfony.ini /etc/php5/cli/conf.d/
ADD symfony.ini /usr/local/etc/php/conf.d/

ADD symfony.pool.conf /etc/php5/fpm.d/
ADD symfony.pool.conf /usr/local/etc/php-fpm.d/

CMD ["php-fpm", "-F"]

WORKDIR /var/www/symfony
EXPOSE 9000
EXPOSE 9001
2 changes: 2 additions & 0 deletions php-fpm/symfony.ini
@@ -1 +1,3 @@
date.timezone = UTC
xdebug.remote_enable=on
xdebug.remote_autostart=off
1 change: 1 addition & 0 deletions php-fpm/symfony.pool.conf
Expand Up @@ -77,5 +77,6 @@ pm.max_spare_servers = 3
env[DB_1_ENV_MYSQL_DATABASE] = $DB_1_ENV_MYSQL_DATABASE
env[DB_1_ENV_MYSQL_USER] = $DB_1_ENV_MYSQL_USER
env[DB_1_ENV_MYSQL_PASSWORD] = $DB_1_ENV_MYSQL_PASSWORD
env[XDEBUG_CONFIG] = $XDEBUG_CONFIG

catch_workers_output = yes