-
Notifications
You must be signed in to change notification settings - Fork 6
Create a new Symfony application
This document contains information on how creating a Symfony application with Docker in less than 5 minutes.
You can clone this repo to get the code directly:
$ git clone https://github.com/Federkun/docker-skeleton-php.git docker-symfony-demo
$ cd docker-symfony-demo
Once you have the code, you'll need to copy .env.dist
to .env
:
$ cp .env.dist .env
Then you can use Composer to ease the creation of a new symfony project:
$ rm -rf app/* && docker-compose run --rm -u $(id -u):$(id -g) php composer create-project symfony/framework-standard-edition .
As from Symfony3.2 you can use the value of the environment variables into you service container configuration, using the %env(MYSQL_DATABASE)%
notation:
Composer will create a new Symfony Standard Edition application under the app/
directory.
A minimum configuration file to get your application running under Nginx is already provided from docker-skeleton-php
.
Remove the default.conf
file and rename symfony.conf.example
into symfony.conf
:
$ rm sites/default.conf
$ mv sites/symfony.conf.example sites/symfony.conf
Now remove the access check from app/web/app_dev.php
:
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']) || php_sapi_name() === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
After you deploy to production, make sure that you cannot access the
app_dev.php
You can start the containers now:
$ docker-compose up -d
-
How can I use Symfony's console?
Symfony 3:
$ docker-compose run --rm php php bin/console
Symfony 2:
$ docker-compose run --rm php php app/console