dans symfony

How to deploy a Symfony app on Clever-Cloud

Clever-Cloud is just an amazing IT Automation Platform (i.e PaaS++). It allows you to deploy apps easily & quickly, really !

Above all, the platform is easy to use. I think they fell in love with KISS principle.

Let’s see how it works and how you can deploy easily Symfony on it.

This article is structured in three main parts: Create your app on Clever-Cloud, Edit Symfony configuration files and deploy Symfony.

I’ll assume that :

  • You have a Git repo with at least Symfony 3.2
  • Your project use a MySQL database
  • You have a ./web/uploads/ folder on your project with files (like img, attachments …)

I – Create your app on Clever-Cloud

Create an account

First of all, you’ll need to create an account & Login.

Create an application

create an application

  • Click on + Add an application
  • In my case, I’ll create a brand new app but you can link your github account if you want.

Select Application instance type

app creation - select instance type

  • Select PHP

Choose deployment type

app creation - deployment type

  • Select Git

Configure scalability

app creation - scalability

  • It depends on your needs. Nano will be enough for me.
  • Click next

Name your app

app creation - name

Select add-ons needed

We’ll need :

  • A MySQL database
  • A FS Buckets to store app uploads (img, pdf …)

select add-ons

  • Select MySQL
  • Depending on your DB size, select appropriated plan & name it.

db creation - plan

db creation - location

  • Add now FS Buckets add-on, link it to your app & name it

fs creation - plan

fs creation - link

fs creation - name

Configure environment variables for Symfony

  • Add following variables
    • PHP_VERSION : 7.0
    • ENABLE_APCU : true
    • SYMFONY_ENV : prod

environment variables

Note : if you use PHP 5.6, you’ll need to add ENABLE_APC : true. Learn more.

II – Edit Symfony configuration files

Use environment variables

Since Symfony3.2, we can use a new syntax to inject environment variables : http://symfony.com/blog/new-in-symfony-3-2-runtime-environment-variables

  • Edit app/config/config.yml

Redirect logs on stderr

It is optional, but still a best practice.

  • Edit app/config/config_prod.yml

Configure APCu

APCu is usefull. It improves Doctrine performances.

  • Edit app/config/config_prod.yml

  • Edit app/config/services.yml

Create a clevercloud folder with config files

At the root of your SF project (same level as app, src, web …), create a folder named « clevercloud ».

  • Add clevercloud/php.json

  • Add clevercloud/buckets.json

bucket_host can be found on sf-clever-cloud-fs add-on on « Addon dashboard » tab :

bucket fs informations

III – Deploy Symfony

  • Go to Information tab of « sf-clever-cloud-back » tab. Push to Clever Cloud instructions are given

  • Follow deployment on Log tab

composer logs

deployment ok

Congrat’s, your app is online !

  • Create a custom domain named sf-clever-cloud-back.cleverapps.io on « Domain names » tab

domain names

  • Check

symfony online

Note : this installation is Scale-Up & Scale-Out ready. Don’t forget to manage stuff like 12 factor if you want to Scale-Out on the right way. Moreover, session can be managed by using Redis in order to improve performances.

Conclusion

Deploying Symfony apps on Clever-Cloud is very fast & easy.

I’ve switched most of my websites (non profit, startup…) because even if I love infrastructure stuff, it allows me to keep focused on code and, above all, value creation.

My next blog post will explain how to create a « Symfony Continuous Delivery multi-stage pipeline by using Gitlab & Clever-Cloud », are you interested in ?

Ecrire un Commentaire

Commenter

  1. Hello David, Very interesting post! thanks for APCu tips.
    I’m very interested if you write an article « Symfony Continuous Delivery multi-stage pipeline by using Gitlab & Clever-Cloud » ».
    Best regards.

    • Hi Romain, thank you very much for this feedback.
      I’ll write about multi-stage CD with Symfony, Gitlab CI & Clever-Cloud in my next article (which will soon be published). I’ll let you know 🙂