Permalink
Browse files

Step 1. Setup a basic Symfony 4 project with Docker

  • Loading branch information...
nielsvandermolen committed Oct 30, 2018
0 parents commit 45f0b8df038736edd3ef7c9db1bbdb227f3e7b7b
@@ -0,0 +1 @@
.idea/
@@ -0,0 +1,3 @@
# We use MariaDB, the schema is compatible with MYSQL.
FROM mariadb:10
@@ -0,0 +1,3 @@
FROM nginx:latest
COPY ./build/nginx/default.conf /etc/nginx/conf.d/
COPY . /var/www/project
@@ -0,0 +1,11 @@
FROM php:fpm
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
zlib1g-dev \
libxml2-dev \
&& docker-php-ext-install \
pdo_mysql \
zip
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
COPY . /var/www/project
WORKDIR /var/www/project/
22 LICENSE
@@ -0,0 +1,22 @@
MIT License
Copyright (c) 2018 Niels van der Molen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,3 @@
Repository related to this blog article:
[https://www.nielsvandermolen.com/tutorial-symfony-4-messenger/](https://www.nielsvandermolen.com/tutorial-symfony-4-messenger)
@@ -0,0 +1,24 @@
server {
listen 80;
root /var/www/project/public;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
# Connect to the Docker service using fpm
fastcgi_pass php:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /dev/stdout info;
access_log /var/log/nginx/project_access.log;
}
@@ -0,0 +1,43 @@
version: "3"
services:
php:
build: # Info to build the Docker image
context: . # Specify where the Dockerfile is located (e.g. in the root directory of the project)
dockerfile: Dockerfile-php # Specify the name of the Dockerfile
environment: # You can use this section to set environment variables. But you can also use the .env file.
- DATABASE_URL=mysql://root:root@db:3306/project_db # Connection string for the database.
volumes:
- ./project/:/var/www/project/ # Location of the project for php-fpm. Note this should be the same for NGINX.
networks:
- symfony # Docker containers (services) that need to connect to each other should be on the same network.
nginx:
build:
context: .
dockerfile: Dockerfile-nginx
volumes:
- ./project/:/var/www/project/
ports:
- 8001:80 # Ports that are exposed, you can connect to port 8001 to port 80 of the container.
networks:
- symfony
db:
build:
context: .
dockerfile: Dockerfile-db
environment:
- MYSQL_ROOT_PASSWORD=root # Setting the MYSQL credentials to root:root.
volumes:
- symfony_db:/var/lib/mysql:cached # Persist the database in a Docker volume.
ports:
- 3311:3306
networks:
- symfony
volumes:
symfony_db:
networks:
symfony:
@@ -0,0 +1,10 @@
# This file is a "template" of which env vars need to be defined for your application
# Copy this file to .env file for development, create environment variables when deploying to production
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=e5b4e6f29f5857791445a0decfe6c605
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
#TRUSTED_HOSTS=localhost,example.com
###< symfony/framework-bundle ###
@@ -0,0 +1,7 @@
###> symfony/framework-bundle ###
/.env
/public/bundles/
/var/
/vendor/
###< symfony/framework-bundle ###
@@ -0,0 +1,39 @@
#!/usr/bin/env php
<?php
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;
set_time_limit(0);
require __DIR__.'/../vendor/autoload.php';
if (!class_exists(Application::class)) {
throw new \RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
}
if (!isset($_SERVER['APP_ENV'])) {
if (!class_exists(Dotenv::class)) {
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
}
(new Dotenv())->load(__DIR__.'/../.env');
}
$input = new ArgvInput();
$env = $input->getParameterOption(['--env', '-e'], $_SERVER['APP_ENV'] ?? 'dev', true);
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true);
if ($debug) {
umask(0000);
if (class_exists(Debug::class)) {
Debug::enable();
}
}
$kernel = new Kernel($env, $debug);
$application = new Application($kernel);
$application->run($input);
@@ -0,0 +1,61 @@
{
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"symfony/console": "*",
"symfony/flex": "^1.1",
"symfony/framework-bundle": "*",
"symfony/yaml": "*"
},
"require-dev": {
"symfony/dotenv": "*"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"paragonie/random_compat": "2.*",
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "4.1.*"
}
}
}
Oops, something went wrong.

0 comments on commit 45f0b8d

Please sign in to comment.