Symfony guide

Symfony has been around for some while — but it doesn't look old. Install and tune Symfony on fortrabbit.

# Get ready

You should have a local PHP development environment running on your local machine.

# Install Symfony locally

Follow the official Symfony guides to create a local installation of Symfony if you not already have one.

Symfony has good backward compatibility, usually not introducing break changes, this guide most likely works for older versions as well. This can be an existing project or a new one, see the official download page for instructions for your local Operating System.

Given that fortrabbit uses Apache as a web server, consider fetching the default .htaccess file for Symfony. This can easily be done through (confirm the installation of the flex recipe by pressing y):

composer require symfony/apache-pack
shell

# Setup GitHub

Optional but recommended: To enable git deployments later on, init git and add GitHub as remote repo, either as a public or private.

# Create an app at fortrabbit

Create a new app in the fortrabbit dashboard. The wizard will guide you through the steps. You can connect the repo from GitHub.

Log in to see the link here.

# Root path

If you did not choose Symfony when creating the environment in the dashboard at first, please set the following: Go to the dashboard and set the root path to 'public'.

Log in to see the link here.

# ENV vars

Symfony environments are controlled by the APP_ENV ENV var. You can even use ENV vars in the .yml configurations now. To get you started quickly, we provide you with the following ENV vars by default when you have chosen the Symfony from when creating the App:

APP_ENV=prod
APP_DEBUG=0
APP_SECRET=SECRET
DATABASE_URL=mysql:host=${FORTRABBIT_MYSQL_HOST};port=3306;dbname=${FORTRABBIT_MYSQL_DATABASE}
shell

ENV vars can be changed with the dashboard. Modify APP_DEBUG or APP_ENV to change the behavior of your application.

Log in to see the link here.

# Git deployment

See the GitHub app guide on how to connect fortrabbit to your Git repo.

# MySQL

The database should be configured out of the box.

# Doctrine & symfony console

# Deployments through GitHub

The build and post-deploy commands should be detected by fortrabbit and provide sensible defaults.

Here is what we automatically set up for you:

  • Build commands:
composer install --no-dev --prefer-dist --no-interaction --no-ansi --no-progress
text

We also add node dependencies installation and build if detected:

npm install
npm run build
text
  • Post-deploy commands:
  • 'php bin/console cache:clear'
  • 'php bin/console assets:install public'
  • 'php bin/console doctrine:migrations:migrate'

# Non-git deployment

You may want to run migrations and maybe load fixtures on the instance. You can login via ssh in to your environment, or instead just fire single commands like so:

# doctrine
$ ssh {{app-env-id}}@ssh.{{region}}.frbit.app 'php bin/console doctrine:migrations:migrate'
$ ssh {{app-env-id}}@ssh.{{region}}.frbit.app 'php bin/console doctrine:fixtures:load'

# cache clear
$ ssh {{app-env-id}}@ssh.{{region}}.frbit.app 'php bin/console cache:clear'
shell

You can also add this migrate command to your composer.json to have it run automatically every time you push changes.

"scripts": {
  "post-install-cmd": [
    "php bin/console doctrine:migrations:migrate --no-interaction",
  ],
}
json

With that in place, any time you deploy your code, database changes will be applied immediately. If no database changes are required, nothing happens, so it is safe to run all the time. Just make sure to test your upgrades and migrations locally first.

# Tailwind usage

Unfortunately TailwindBundle uses Tailwind CLI which is not currently compatible with our service.

You can instead use Symfony Encore to install Tailwind.

composer require symfony/webpack-encore-bundle
npm install && npm install -D tailwindcss postcss postcss-loader autoprefixer @tailwindcss/postcss
text

Add this part in webpack.config.js:

    // enable PostCSS loader
    .enablePostCssLoader()
js

Create the following postcss.config.js file in the root directory:

module.exports = {
  plugins: {
    '@tailwindcss/postcss': {},
    autoprefixer: {},
  },
};
js

And finally add these lines to your app.css file:

@import 'tailwindcss';
@source "../../templates";
css

Since we detect node configuration this should then be deployed without any change of your configuration.

# Symfony installer

The symfony docs suggest to download a Symfony installer CLI. You can not do that on the remote environment. Do that in your local development environment.

# Logging

You can access all log files with the dashboard.

# Sending emails

You can not use sendmail on fortrabbit but you can use the Swiftmailer. Symfony provides a Mailer component that makes things easy. To configure the way your emails are sent, mind setting a MAILER_DSN environment variable. More on this in the official documentation.

Found a tpyo?Edit