Skip to content
Permalink
Browse files

Merge pull request #2841 from forkcms/symfony-dotenv

Use Symfony's Dotenv so Symfony Server is more convenient
  • Loading branch information...
carakas committed Jul 3, 2019
2 parents 2aa9b1a + d1df2d0 commit a833612a66f8516e402cc13564dd2bd647299ca9
Showing with 41 additions and 11 deletions.
  1. +1 −1 .dockerignore
  2. +2 −0 .env
  3. +3 −1 .gitignore
  4. +3 −0 Dockerfile
  5. +26 −0 autoload.php
  6. +2 −0 docker-compose.yml
  7. +2 −7 docs/01. installation/07. docker.md
  8. +2 −2 index.php
  9. 0 .env.dist → var/docker/.env
@@ -8,7 +8,7 @@
**/.gitignore
**/Dockerfile
**/Thumbs.db
*.env.dist
.env.local
*.sublime-project
*.sublime-workspace
.editorconfig
2 .env
@@ -0,0 +1,2 @@
FORK_ENV=prod
FORK_DEBUG=0
@@ -25,4 +25,6 @@
# Docker
var/docker/db/data/*
docker-compose.override.yml
.env

# Symfony's dotenv
/.env.local
@@ -4,6 +4,9 @@ LABEL maintainer="Fork CMS <info@fork-cms.com>"
# Enable Apache mod_rewrite
RUN a2enmod rewrite

# Run apt from fresh debian sources
RUN printf "deb http://archive.debian.org/debian/ jessie main\ndeb-src http://archive.debian.org/debian/ jessie main\ndeb http://security.debian.org jessie/updates main\ndeb-src http://security.debian.org jessie/updates main" > /etc/apt/sources.list

# Install GD2
RUN apt-get update && apt-get install -y --no-install-recommends \
libfreetype6-dev \
@@ -1,6 +1,9 @@
<?php
// @TODO rename this file to bootstrap.php to better reflect its function
use Doctrine\Common\Annotations\AnnotationRegistry;
use Symfony\Component\Dotenv\Dotenv;
// use vendor generated autoloader
$loader = require __DIR__ . '/vendor/autoload.php';
@@ -10,4 +13,27 @@
set_include_path(__DIR__ . '/vendor/spoon/library' . PATH_SEPARATOR . get_include_path());
require_once 'spoon/spoon.php';
// load server variables
if (!array_key_exists('FORK_ENV', $_SERVER)) {
$_SERVER['FORK_ENV'] = $_ENV['FORK_ENV'] ?? null;
}
if ('prod' !== $_SERVER['FORK_ENV']) {
if (!class_exists(Dotenv::class)) {
throw new RuntimeException('The "FORK_ENV" environment variable is not set to "prod". Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
}
$dotenv = new Dotenv();
$dotenv->load(__DIR__ . '/.env');
// @TODO when updating to Fork 6, using Symfony 4, check if we still need to check the file's existence
if (file_exists(__DIR__ . '/.env.local')) {
$dotenv->load(__DIR__ . '/.env.local');
}
}
$_SERVER['FORK_ENV'] = $_ENV['FORK_ENV'] = $_SERVER['FORK_ENV'] ?: $_ENV['FORK_ENV'] ?: 'dev';
$_SERVER['FORK_DEBUG'] = $_SERVER['FORK_DEBUG'] ?? $_ENV['FORK_DEBUG'] ?? 'prod' !== $_SERVER['FORK_ENV'];
$_SERVER['FORK_DEBUG'] = $_ENV['FORK_DEBUG'] = (int) $_SERVER['FORK_DEBUG'] || filter_var($_SERVER['FORK_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
return $loader;
@@ -17,6 +17,8 @@ services:
volumes:
- .:/var/www/html:cached
- ./src/Frontend/Files:/var/www/html/src/Frontend/Files:cached
env_file:
- ./var/docker/.env

db:
image: "mariadb:latest"
@@ -151,14 +151,9 @@ You can easily use different credentials by adjusting them in the `docker-compos
### General setup and XDebug
[Video - watch how to setup PHPStorm and Xdebug](https://d.pr/v/6OXvva)

It's easy to setup PHPStorm in combination with Docker and Xdebug, one of the most popular tools to debug your PHP application.
It's easy to setup PHPStorm in combination with Docker and Xdebug, one of the most popular tools to debug your PHP application. In the `var/docker` folder you will find a `.env` file containing some defaults for Docker.

- First copy the .env.dist to .env in the root folder of your project
```
cp .env.dist .env
```

- You can edit the `.env` file to fill in some host-specific information and configure XDebug. By default it contains a special
- You can edit the `.env` file to add or change in some information for your system and configure XDebug. By default it contains a special
hostname available for Docker for Mac users, but you can change it to point to your own Docker host IP.
- Recreate your Docker containers, because you modified the environment variables.
```
@@ -21,8 +21,8 @@
use Symfony\Component\Debug\Debug;
// get environment and debug mode from environment variables
$env = getenv('FORK_ENV') ?: 'prod';
$debug = getenv('FORK_DEBUG') === '1';
$env = $_SERVER['FORK_ENV'] ?: 'prod';
$debug = $_SERVER['FORK_DEBUG'] === '1';
// Fork has not yet been installed
$parametersFile = __DIR__ . '/app/config/parameters.yml';
File renamed without changes.

0 comments on commit a833612

Please sign in to comment.
You can’t perform that action at this time.