Description of Symfony project
- docker (min 17.03.1-ce)
- docker-compose (min 1.13.0)
In order to install latest Symfony within project/ folder you can run following command (before running it you actually need to remove project/ folder):
docker run -it -v $(pwd):/symfony ivanbarlog/symfony-installer new project && sudo chown -R $USER:$USER projector copy your symfony project over to project/ folder.
Following script will:
- set up the dev domain within
/etc/hosts - build and start development containers
- copy
parameters.yml.distover toparameters.yml - installs dependencies over
composer - create database if not exists
- update database schema
- fix file permissions
./ops initParameters in parameters.yml.dist should look like this:
parameters:
database_host: db
database_port: 3306
database_name: {database name}It is absolutely safe to remove following lines from project/web/app_dev.php since it is disabled in prod environment by nginx:
// 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 === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}You can remove any other code from app_dev.php and app.php which is related to PHP version lower then 7.0.
The project provides docker-compose wrapper which can be invoked by ./ops. Here are commands which can be used:
init - initializes the project from scratch
up - brings containers up
stop - stops containers
down - stops and removes containers
restart - stops, rebuilds and starts specified containers eg. '$0 restart nginx fpm' will restart nginx and fpm
bin/console - runs Symfony's bin/console within cli container
composer - runs composer within cli container
npm - runs npm within node container
encore - runs encore within cli container (you need to install encore and set-up your project for proper use with Symfony's webpack first)
cs - checks your src/ and tests/ with php-cs-fixer and phpmd utilities
test - run tests with phpunit
permissions - fixes permissions in var/ folder
mysql - connects to the database within db container
mysqldump - dumps the database to ./infrastructure/volumes/sqldump
compose - wrapper for docker-composesource ./infrastructure/.completion
./ops mysql -uroot -pdb container has attached special volume which can be used to import/export database. It's located in infrastructure/volumes/sqldump and within container it maps to /sqldump.
Hence you can copy your MySQL dump to infrastructure/volumes/sqldump and source it from MySQL console (checkout Connect to database) from /sqldump. Also you can export your database to /sqldump and access it in infrastructure/volumes/sqldump.
Copy ./env/symfony.env.dist to ./env/symfony.env and set up API keys.
You can access the environment variables within Symfony's config file like this:
# project/app/config/config.yml
everlution_file_jet:
storages:
- id: "%env(FILE_JET_ID)%"
api_key: "%env(FILE_JET_API_KEY)%"
name: defaultIf you want to change default ports, please copy ./env/docker.env.dist to ./env/docker.env and set up your custom ports there. You should also set up the domain name there.
Create assets and build folders:
mkdir -p project/assets/js
touch project/assets/js/main.js
mkdir -p project/assets/scss
touch project/assets/scss/global.scss
mkdir -p project/web/buildAdd node_modules and build folder to .gitignore:
echo "node_modules" >> project/.gitignore
echo "web/build" >> project/.gitignoreCreate webpack.config.js within the project folder:
var Encore = require('@symfony/webpack-encore');
Encore
.setOutputPath('web/build/')
.setPublicPath('/build')
.cleanupOutputBeforeBuild()
.addEntry('app', './assets/js/main.js')
.addStyleEntry('global', './assets/scss/global.scss')
.enableSassLoader()
.autoProvidejQuery()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning()
;
module.exports = Encore.getWebpackConfig();Enable asset versioning in Symfony's config:
framework:
assets:
json_manifest_path: '%kernel.project_dir%/web/build/manifest.json'Initialize npm package within your project file - this will be used for managing frontend dependencies instead of bower:
./ops npm init # follow the instructionsInstall encore and other dependencies:
./ops npm install @symfony/webpack-encore --save-dev
./ops npm install node-sass --save-dev
./ops npm install sass-loader --save-devRead more about Managing CSS and JavaScript