-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Environment configurator is a Composer plugin, it was created to automate frequent routine operations. With console command, this plugin executes sequences of these operations, stored in special repositories.
To show how it works, i prepared a demo, at the end of it you will have fully functional application, running inside Docker containers, with SonataDoctrineORMAdminBundle and FOSUserBundle installed and with configured user management inside admin panel. Please, follow instructions:
-
Configure local DNS
Add two records to
C:\WINDOWS\System32\Drivers\etc\hostsor/etc/hostsfile:docker.local 127.0.0.1andmysql 127.0.0.1. If you useDocker Toolboxand Windows as a host, executedocker-machine env, get IP-address fromDOCKER_HOSTvariable and add that IP instead of127.0.0.1 -
Create a new project
composer create-project symfony/skeleton . -
Install plugin, using global installation is recommended:
composer global require covex-nn/environment
After installation a new composer command
env:applywill be available. -
Install SonataDoctrineORMBundle and FOSUserBundle with user management
composer env:apply admin
-
Configure local
docker-composeenvironmentcomposer env:apply docker-compose
If you applied
docker-composebeforeadmin, replace host in.envfile forDATABASE_URLfrom127.0.0.1tomysqlmanualy. -
Run Web-server
Default environment uses PHP built-in Web-server
docker-compose up -d php -S 127.0.0.1:80 -t public
But if you want to use Nginx as Web server or if you do not have PHP 7.2 installed on your host, execute the following instead:
cp docker-compose.override.yml.dist docker-compose.override.yml docker-compose up -d docker-compose exec php bin/console cache:clear -
Update database schema and create admin user
php bin/console doctrine:schema:update --force php bin/console fos:user:create admin [email protected] php bin/console fos:user:promote admin ROLE_SUPER_ADMIN
or
docker-compose exec php bin/console doctrine:schema:update --force docker-compose exec php bin/console fos:user:create admin [email protected] docker-compose exec php bin/console fos:user:promote admin ROLE_SUPER_ADMIN
Even if you have chosen
nginxas your web-server, you can run console commands from host, it is not necessary to run them inside container. But in this case, there will be 2vardirectory: first on the host and the second inside container, and withphp bin/console cache:clearyou will clear cache on your host, not inside VM
Also, there is a package covex-nn/docker-symfony, it was created via composer env:apply docker-ci command. It contains same all docker files from above and some procedures for deployment with GitLab CI/CD Pipeline.