diff --git a/.env b/.env new file mode 100644 index 0000000..3f30a1c --- /dev/null +++ b/.env @@ -0,0 +1,17 @@ +# Symfony application's path (absolute or relative) +SYMFONY_APP_PATH=./src/ + +# MySQL +MYSQL_ROOT_PASSWORD=root +MYSQL_DATABASE=sulu +MYSQL_USER=sulu +MYSQL_PASSWORD=sulu + +# MySQL test +TEST_MYSQL_ROOT_PASSWORD=root_test +TEST_MYSQL_DATABASE=sulu_test +TEST_MYSQL_USER=sulu_test +TEST_MYSQL_PASSWORD=sulu_test + +# Timezone +TIMEZONE=Europe/Paris diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cd757da --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea +.data +data +logs \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1f48fce --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,64 @@ +version: '2' + +services: + db: + image: mysql:5.7 + environment: + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} + MYSQL_DATABASE: ${MYSQL_DATABASE} + MYSQL_USER: ${MYSQL_USER} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} + ports: + - 8989:3306 + db_test: + image: mysql:5.7 + environment: + MYSQL_ROOT_PASSWORD: ${TEST_MYSQL_ROOT_PASSWORD} + MYSQL_DATABASE: ${TEST_MYSQL_DATABASE} + MYSQL_USER: ${TEST_MYSQL_USER} + MYSQL_PASSWORD: ${TEST_MYSQL_PASSWORD} + ports: + - 8990:3306 + php: + build: + context: docker/php7-fpm + args: + TIMEZONE: ${TIMEZONE} + volumes: + - ${SYMFONY_APP_PATH}:/var/www/symfony + - ./logs/symfony:/var/www/symfony/app/logs + links: + - db:db + - db_test:db_test + nginx: + build: docker/nginx + ports: + - 80:80 + volumes_from: + - php + volumes: + - ./logs/nginx/:/var/log/nginx + phpmyadmin: + image: phpmyadmin/phpmyadmin + environment: + - PMA_ARBITRARY=1 + - PMA_HOST=db + - PMA_USER=${MYSQL_USER} + - PMA_PASSWORD=${MYSQL_PASSWORD} + restart: always + ports: + - 181:80 + volumes: + - /sessions + phpmyadmin_test: + image: phpmyadmin/phpmyadmin + environment: + - PMA_ARBITRARY=1 + - PMA_HOST=db_test + - PMA_USER=${TEST_MYSQL_USER} + - PMA_PASSWORD=${TEST_MYSQL_PASSWORD} + restart: always + ports: + - 183:80 + volumes: + - /sessions \ No newline at end of file diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile new file mode 100644 index 0000000..8011b3a --- /dev/null +++ b/docker/nginx/Dockerfile @@ -0,0 +1,21 @@ +FROM debian:jessie + +MAINTAINER Maxence POUTORD + +RUN apt-get update && apt-get install -y \ + nginx + +ADD nginx.conf /etc/nginx/ +ADD symfony.conf /etc/nginx/sites-available/ + +RUN ln -s /etc/nginx/sites-available/symfony.conf /etc/nginx/sites-enabled/symfony +RUN rm /etc/nginx/sites-enabled/default + +RUN echo "upstream php-upstream { server php:9000; }" > /etc/nginx/conf.d/upstream.conf + +RUN usermod -u 1000 www-data + +CMD ["nginx"] + +EXPOSE 80 +EXPOSE 443 diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf new file mode 100644 index 0000000..a9ecf0e --- /dev/null +++ b/docker/nginx/nginx.conf @@ -0,0 +1,29 @@ +user www-data; +worker_processes 4; +pid /run/nginx.pid; + +events { + worker_connections 2048; + multi_accept on; + use epoll; +} + +http { + server_tokens off; + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 15; + types_hash_max_size 2048; + include /etc/nginx/mime.types; + default_type application/octet-stream; + access_log off; + error_log off; + gzip on; + gzip_disable "msie6"; + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*; + open_file_cache max=100; +} + +daemon off; diff --git a/docker/nginx/symfony.conf b/docker/nginx/symfony.conf new file mode 100644 index 0000000..118d46f --- /dev/null +++ b/docker/nginx/symfony.conf @@ -0,0 +1,47 @@ +server { + server_name symfony.local; + root /var/www/symfony/web; + + error_log /var/log/nginx/project_error.log; + access_log /var/log/nginx/project_access.log; + + # strip app.php/ prefix if it is present + rewrite ^/app\.php/?(.*)$ /$1 permanent; + + location /admin { + index admin.php; + try_files $uri @rewriteadmin; + } + + location @rewriteadmin { + rewrite ^(.*)$ /admin.php/$1 last; + } + + location / { + index website.php; + try_files $uri @rewritewebsite; + } + + # expire + location ~* \.(?:ico|css|js|gif|jpe?g|png|svg|woff|woff2|eot|ttf)$ { + try_files $uri /website.php/$1?$query_string; + access_log off; + expires 30d; + add_header Pragma public; + add_header Cache-Control "public"; + } + + location @rewritewebsite { + rewrite ^(.*)$ /website.php/$1 last; + } + + # pass the PHP scripts to FastCGI server from upstream phpfcgi + location ~ ^/(website|admin|app|app_dev|config)\.php(/|$) { + fastcgi_pass php-upstream; + fastcgi_split_path_info ^(.+\.php)(/.*)$; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param SYMFONY_ENV dev; + fastcgi_param HTTPS off; + } +} diff --git a/docker/php7-fpm/Dockerfile b/docker/php7-fpm/Dockerfile new file mode 100644 index 0000000..3838e09 --- /dev/null +++ b/docker/php7-fpm/Dockerfile @@ -0,0 +1,45 @@ +FROM php:7.2-fpm +ARG TIMEZONE + +MAINTAINER Maxence POUTORD + +RUN apt-get update && apt-get install -y \ + openssl \ + git \ + unzip \ + libpng-dev \ + zlib1g-dev \ + zip && docker-php-ext-install zip + +# Set timezone +RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone +RUN printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini +RUN "date" + +# Type docker-php-ext-install to see available extensions +RUN docker-php-ext-install pdo pdo_mysql + +# Install Composer +RUN curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer + +RUN echo "memory_limit = -1" \ + > /usr/local/etc/php/conf.d/php.ini + +RUN docker-php-ext-install gd + +# install xdebug +RUN pecl install xdebug +RUN docker-php-ext-enable xdebug +RUN echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini +RUN echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini +RUN echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini +RUN echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini +RUN echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini +RUN echo "xdebug.idekey=\"docker\"" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini +RUN echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini + + +RUN echo 'alias sf="php app/console"' >> ~/.bashrc +RUN echo 'alias sf3="php bin/console"' >> ~/.bashrc + +WORKDIR /var/www/symfony