Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine

Deploying to SymfonyCloud

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

Transition point! Everything we've talked about so far has included profiling our local version of the site. But things get even cooler when we start to profile our production site. Having real data often shows performance problems that you just can't anticipate locally. And because of the way that Blackfire works, we can create profiles on production without slowing down our servers and affecting real users. Plus, once we're profiling on production, we can unlock even more Blackfire features.

So... let's get this thing deployed! You can use any hosting system you want, but I'm going to deploy with SymfonyCloud: it's what we use for SymfonyCasts and it makes deployment dead-simple for Symfony apps. It also has a free trial if you want to code along with me.

Initializing your SymfonyCloud Project

Find your terminal and make sure you're on your master branch. That's not required, but will make life easier. Start by running:

symfony project:init

This will create a few config files that tell SymfonyCloud everything it needs to know to deploy our site. The most important file is .symfony.cloud.yaml:

name: app
type: php:7.1
runtime:
extensions:
- apcu
- mbstring
- ctype
- iconv
build:
flavor: none
web:
locations:
"/":
root: "public"
expires: 1h
passthru: "/index.php"
disk: 512
mounts:
"/var": { source: local, source_path: var }
hooks:
build: |
set -x -e
curl -s https://get.symfony.com/cloud/configurator | (>&2 bash)
(>&2 symfony-build)
deploy: |
set -x -e
(>&2 symfony-deploy)

Ah, this says we want PHP 7.1. Let's upgrade by changing that to 7.3:

... lines 1 - 2
type: php:7.3
... lines 4 - 39

Back at the terminal, copy the big git command: this will add all the new files to git and commit them:

git add .symfony.cloud.yaml .symfony/services.yaml .symfony/routes.yaml php.ini
git commit -m "Add SymfonyCloud configuration"

Next, to tell SymfonyCloud that we want a new "server" on their system, run:

symfony project:create

Every "site" in SymfonyCloud is known as a "project" and we only need to run this command once per app. You can ignore the big yellow warning - that's because I have a few other SymfonyCloud projects attached on my account. Let's call the project "Sasquatch Sightings" - that's just a name to help us identify it - and choose the "Development" plan.

The development plan includes a free 7 day trial... which is awesome. You do need to enter your credit card info - that's a way to prevent spammers from creating free trials - but it won't be charged unless you run symfony project:billing:accept later to keep this project permanently.

I already have a credit card on file, so I'll use that one. Once we confirm, this provisions our project in the background... I assume it's waking up thousands of friendly robots who are carefully creating our new space in... the "cloud". Hey! There's one now... dancing!

And... done!

Deploying & Security Checks

Ready for our first deploy? Just type:

symfony app:prepare:deploy --branch=master --confirm --this-is-not-a-real-command

Kidding! Just run:

symfony deploy

And... hello error! This is actually great. Really! The deploy command automatically checks your composer.lock file to see if you're using any dependencies with known security vulnerabilities. Some of my Symfony packages do have vulnerabilities... and if this were a real app, I would upgrade those to fix that problem. But... because this is a tutorial... I'm going to ignore this.

Our First Deploy

Run the command again with a --bypass-checks flag:

symfony deploy --bypass-checks

We still see the big message... but it's deploying! This takes care of many things automatically, like running composer install and executing database migrations. This first deploy will be slow - especially to download all the Composer dependencies. I'll fast-forward. It also handles setting up Webpack Encore... and even creates a shiny new SSL certificate. Those are busy robots!

And... done! It dumped out a funny-looking URL. Copy that. In a real project, you will attach your real domain to SymfonyCloud. But this "fake" domain will work beautifully for us.

Spin back over and pop that URL into your browser to see... a beautiful 500 error! Wah, wah. Actually, we're super close to this all working. Next, let's use a special command to debug this error, add a database to SymfonyCloud - yep, that's the piece we're missing - and load some dummy data over a "tunnel". Lots of good, nerdiness!

Leave a comment!

9
Login or Register to join the conversation
hanen Avatar
hanen Avatar hanen | posted 3 years ago | edited

hi .. Fatal error when I run git add


D:\project\blackfire\.symfony.cloud.yaml
D:\project\blackfire\.symfony\services.yaml
D:\project\blackfire\.symfony\routes.yaml
D:\project\blackfire\php.ini && git commit -m"Add SymfonyCloud configuration"

<blockquote>
fatal: D:projectblackfire.symfony.cloud.yaml: 'D:projectblackfire.symfony.cloud.yaml' is outside repository
</blockquote>

1 Reply
Victor Avatar Victor | SFCASTS | hanen | posted 3 years ago | edited

Hey Hanene,

Hm, try to do simpler:



$ git add .
$ git commit -m"Add SymfonyCloud configuration"

If still not work, please, make sure your have a Git repository initialiazed in the project root dir and those files are inside of your project root dir.

Cheers!

Reply
hanen Avatar

Ok it works .Could you give the project Id

Reply

Hey Hanene,

Glad it works! Hm, what project ID are you talking about? :) Do you see a question about project ID in your console? After what command? Could you copy/paste it? :)

Cheers!

Reply
hanen Avatar

I run symfony.exe link [project-id] to get project IDs via symfony.exe projects... Infact I don't have a credit card :(...

Reply

Hey hanene,

Ah, it won't work :) I can't give you my project ID, because even if you would have my project ID - you won't be able to use it as you just don't have access to my project. You need to create your own project in SymfonyCloud and use it for training purposes if you want. Or just skip chapters that require SymfonyCloud account if you don't want to buy it.

Cheers!

Reply
hanen Avatar

it s Ok no problem :)) ;)

Reply
Rainer-S Avatar
Rainer-S Avatar Rainer-S | posted 9 months ago | edited

Hello.

After symfony deploy I get following error:

E: Error parsing configuration files:
      - applications./.platform.app.yaml.mounts.hooks: Expected a string, received None
      - applications./.platform.app.yaml.mounts.build: Unsupported volume URL
      - applications./.platform.app.yaml.mounts.deploy: Unsupported volume URL

.plaftorm.app.yaml contents:

name: app

type: php:8.1

runtime:
    extensions:
        - apcu
        - mbstring
        - sodium
        - iconv
        - ctype
        

#variables:
#    php:
#        # uncomment on PHP 7.4+
#        #opcache.preload: config/preload.php

build:
    flavor: none

disk: 512

web:
    locations:
        "/":
            root: "public"
            expires: 1h
            passthru: "/index.php"



mounts:
    "/var": { source: local, source_path: var }
    hooks:
    build: |
        set -x -e

        curl -fs https://get.symfony.com/cloud/configurator | bash
        
        symfony-build

    deploy: |
        set -x -e

        symfony-deploy
Reply

Hey Rainer-S,

Please, double-check the indentation in your .plaftorm.app.yaml - it seems you should indent the build & deploy items with 4 spaces back to the root of the file, i.e.:

# ...

mounts:
    "/var": { source: local, source_path: var }

hooks:
    build: |
        set -x -e

        curl -fs https://get.symfony.com/cloud/configurator | bash
        
        symfony-build

    deploy: |
        set -x -e

        symfony-deploy

Right now it looks like the "hooks" is nested into "mounts" that is not correct.

Cheers!

Reply
Cat in space

"Houston: no signs of life"
Start the conversation!

This tutorial can be used to learn how to profile any app - including Symfony 5.

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": "^7.1.3",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "blackfire/php-sdk": "^1.20", // v1.20.0
        "composer/package-versions-deprecated": "^1.11", // 1.11.99
        "doctrine/annotations": "^1.0", // v1.8.0
        "doctrine/doctrine-bundle": "^1.6.10|^2.0", // 1.11.2
        "doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
        "doctrine/orm": "^2.5.11", // v2.6.4
        "phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.2
        "sensio/framework-extra-bundle": "^5.4", // v5.5.1
        "symfony/console": "4.3.*", // v4.3.10
        "symfony/dotenv": "4.3.*", // v4.3.10
        "symfony/flex": "^1.9", // v1.18.7
        "symfony/form": "4.3.*", // v4.3.10
        "symfony/framework-bundle": "4.3.*", // v4.3.9
        "symfony/http-client": "4.3.*", // v4.3.10
        "symfony/property-access": "4.3.*", // v4.3.10
        "symfony/property-info": "4.3.*", // v4.3.10
        "symfony/security-bundle": "4.3.*", // v4.3.10
        "symfony/serializer": "4.3.*", // v4.3.10
        "symfony/twig-bundle": "4.3.*", // v4.3.10
        "symfony/validator": "4.3.*", // v4.3.10
        "symfony/webpack-encore-bundle": "^1.6", // v1.7.2
        "symfony/yaml": "4.3.*", // v4.3.10
        "twig/extensions": "^1.5" // v1.5.4
    },
    "require-dev": {
        "doctrine/doctrine-fixtures-bundle": "^3.2", // 3.2.2
        "easycorp/easy-log-handler": "^1.0.7", // v1.0.9
        "fzaninotto/faker": "^1.8", // v1.8.0
        "symfony/browser-kit": "4.3.*", // v4.3.10
        "symfony/css-selector": "4.3.*", // v4.3.10
        "symfony/debug-bundle": "4.3.*", // v4.3.10
        "symfony/maker-bundle": "^1.13", // v1.14.3
        "symfony/monolog-bundle": "^3.0", // v3.5.0
        "symfony/phpunit-bridge": "^5.0", // v5.0.3
        "symfony/stopwatch": "4.3.*", // v4.3.10
        "symfony/var-dumper": "4.3.*", // v4.3.10
        "symfony/web-profiler-bundle": "4.3.*" // v4.3.10
    }
}
userVoice