Symfony Starter 4
Used to create new projects using Symfony 4 at XM Media.
Setting Up a New Site
- Download a copy of this repo (probably as a ZIP).
- Remove or update the
LICENSE
file. - Install Composer locally.
- Update
composer.json
:name
,license
(likelyprivate
) anddescription
- Update
package.json
:name
,version
,git.url
,license
,private
,script.dev-server
- Composer install & update (locally, no autoloader or scripts):
composer install && php -d memory_limit=-1 /usr/local/bin/composer update
- Run
yarn && yarn upgrade
locally. - Find and make changes near
@todo-symfony
comments throughout the site. - Setup server:
- Upload the files (exclude files that are OS dependent like
node_modules
&.env
or that are only for editing like.idea
and a lot of what's in.gitignore
). - Install Composer
- Install PHP packages/vendors:
php composer.phar install
- Update
.env
. - Install NVM: https://github.com/creationix/nvm#install-script
- Run
. ./node_setup.sh
(this will setup node & install the JS packages). - Run
yarn dev
oryarn build
(for production) to compile JS & CSS files. - Create the database:
bin/console doctrine:schema:create
- Create event streams & projections tables from: https://github.com/prooph/pdo-event-store/tree/master/scripts/mysql
- Create one or more event streams with the command
bin/console event-store:event-stream:create enquiry_event
- Create a user
bin/console fos:user:create
and then promote them (add the roleROLE_SUPER_ADMIN
)bin/console fos:user:promote
- Setup mail spool: add cron task similar to:
* * * * * cd <path> && bin/console swiftmailer:spool:send --message-limit=10 --time-limit=45 >> var/log/mailer.log 2>&1
- Upload the files (exclude files that are OS dependent like
- Delete starter files:
README.md
(or update),TEMPLATES.md
.
Dev site can be accessed at https://[domain]/
System Requirements
- PHP 7.2+
- MySQL 5.7+
- Yarn
Commands
- Production JS/CSS build:
yarn build
- Dev JS/CSS build:
yarn dev
- Dev JS/CSS watch:
yarn watch
(files will not be versioned) - Dev JS/CSS HMR server:
yarn dev-server
(see below) - Testing:
- JS unit tests:
yarn test:unit
- E2E tests using Cypress:
yarn test:e2e
- JS unit tests:
- Linting:
- JS:
yarn lint:js
oryarn lint:js:fix
- CSS:
yarn lint:css
oryarn lint:css:fix
- JS:
- PHPUnit:
composer test
- no memory limit
php -d memory_limit=-1 bin/simple-phpunit
- with coverage (HTML)
composer test:coverage
- PHP CS Fixer: (must be installed first)
- Dry run:
composer cs
- Fix:
composer cs:fix
- Dry run:
- PHP Static Analysis (PHPStan):
composer static
- Projections:
- All commands:
bin/console event-store:projection
- Run once:
bin/console event-store:projection:run enquiry_projection -o
- All commands:
Apache Config
The following is needed in the Apache VirtualHost for the Webpack Dev Server/HMR to work:
ProxyPassMatch ^(\/dev-server\/.+$)|(sockjs-node) http://localhost:<port>
ProxyPassReverse / http://localhost:<port>
You'll probably want to customize the port number in the Apache ProxyPass config
and in package.json
(script.dev-server
) to be unique to each project if
running multiple sites on one server.