Symfony on fortrabbit
Published
Updated
Run Symfony on fortrabbit with Git deployment. The Symfony software template sets the root path, APP_ENV, APP_SECRET and DATABASE_URL, runs Composer, and clears the cache and migrates the database after each deployment.
Install Symfony locally
Set up Symfony in a local development environment, see the Symfony setup docs. fortrabbit serves PHP with Apache, so add the .htaccess rules of the Apache pack, and confirm the Flex recipe with y:
composer require symfony/apache-pack
Push the code to a GitHub repository for Git deployment, see the Git intro if Git is new.
Create an app
Create an app in the dashboard, choose Symfony as the software, and connect the GitHub repository.
Software template
The Symfony software template sets these values:
Symfony 8, 7, 6, 5
| Deployment | Value |
|---|---|
| Root path | public |
| Deploy strategy | replace |
| Excluded paths | /public/uploads/node_modules |
| Build commands | composer install --no-dev --prefer-dist --no-interaction --no-ansi --no-progress |
| Post-deploy commands | php bin/console cache:clearphp bin/console assets:install publicphp bin/console doctrine:migrations:migrate |
| Environment variables | Value |
|---|---|
| APP_DEBUG | false |
| APP_ENV | prod |
| APP_SECRET | !RANDOM_KEY! |
| Database environment variables | Value |
|---|---|
| DATABASE_URL | mysql://${FORTRABBIT_DB_USER}:${FORTRABBIT_DB_PASSWORD}@${FORTRABBIT_DB_HOST}:3306/${FORTRABBIT_DB_NAME} |
In short:
- The root path
public APP_ENV=prod,APP_DEBUG=falseand a randomAPP_SECRETDATABASE_URLfrom the MySQL component- Post deploy commands that clear the cache, install the assets and run the Doctrine migrations
/public/uploadsas an exclude pattern, so uploads survive deployments
With a package.json in the repository, the stack detector adds npm install and npm run build to the build commands. Apps created without the template need these settings by hand: ENV vars, root path and the deployment settings.
Commands over SSH
Run console commands over SSH, for example to load fixtures:
$ ssh {{app-env-id}}@ssh.{{region}}.frbit.app 'php bin/console doctrine:fixtures:load'
$ ssh {{app-env-id}}@ssh.{{region}}.frbit.app 'php bin/console cache:clear'
Tailwind
The TailwindBundle downloads the standalone Tailwind CLI, a binary the build cannot run, see limits of the build. Install Tailwind through npm instead, for example with Webpack Encore:
composer require symfony/webpack-encore-bundle
npm install -D tailwindcss postcss postcss-loader autoprefixer @tailwindcss/postcss
Enable PostCSS in webpack.config.js:
.enablePostCssLoader()
Create postcss.config.js in the project root:
module.exports = {
plugins: {
'@tailwindcss/postcss': {},
autoprefixer: {},
},
};
And import Tailwind in assets/styles/app.css:
@import 'tailwindcss';
@source '../../templates';
The build commands then compile it with each deployment.
Logging
Symfony logs with Monolog. Its default configuration for prod writes to php://stderr, which shows up in the logs of the dashboard. Keep that in config/packages/monolog.yaml.
Sending e-mail
fortrabbit has no sendmail. Configure the Symfony Mailer with the MAILER_DSN ENV var, pointing to SMTP or a transactional mail provider, see the Symfony Mailer docs.