WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:01.016 --> 00:00:03.386 align:middle
We just deployed to SymfonyCloud!!!

00:00:04.006 --> 00:00:06.056 align:middle
Well, I mean, we did...

00:00:06.186 --> 00:00:07.326 align:middle
but it doesn't...

00:00:07.456 --> 00:00:07.946 align:middle
ya know...

00:00:07.946 --> 00:00:14.756 align:middle
work yet. Because this is the production
500 error, we can't see the real problem.

00:00:15.306 --> 00:00:16.456 align:middle
No worries!

00:00:16.736 --> 00:00:17.856 align:middle
Head back to your terminal.

00:00:18.666 --> 00:00:22.456 align:middle
The symfony command has an easy
way to check the production logs.

00:00:22.846 --> 00:00:29.066 align:middle
It is... symfony logs This
prints a list of all the logs.

00:00:29.336 --> 00:00:33.436 align:middle
The app/ directory is where our
application is deployed to -

00:00:33.436 --> 00:00:38.996 align:middle
so the first item is our
project's var/log/prod.log file.

00:00:39.676 --> 00:00:41.696 align:middle
You can also check out the raw access log...

00:00:41.696 --> 00:00:42.616 align:middle
or everything.

00:00:43.446 --> 00:00:46.516 align:middle
Hit 0 to "tail" the prod.log file.

00:00:47.266 --> 00:00:50.746 align:middle
And... there it is: An exception has occurred...

00:00:50.966 --> 00:00:52.506 align:middle
Connection refused.

00:00:53.116 --> 00:00:56.226 align:middle
I recognize this: it's a database error....

00:00:56.406 --> 00:00:57.426 align:middle
which... hmm...

00:00:57.506 --> 00:01:02.056 align:middle
makes sense: we haven't told
SymfonyCloud that we need a database!

00:01:02.666 --> 00:01:03.426 align:middle
Let's go do that!

00:01:04.806 --> 00:01:08.166 align:middle
Google for "SymfonyCloud MySQL" to find...

00:01:08.796 --> 00:01:12.766 align:middle
oh! A page that talks about exactly that.

00:01:13.826 --> 00:01:17.446 align:middle
Ok, we need to add a little
bit of config to 2 files.

00:01:17.446 --> 00:01:21.686 align:middle
The first is .symfony/services.yaml.

00:01:22.536 --> 00:01:26.666 align:middle
This is where you tell SymfonyCloud
about all the "services" you need -

00:01:27.126 --> 00:01:31.506 align:middle
like a database service,
ElasticSearch, Redis, RabbitMQ,

00:01:31.506 --> 00:01:36.226 align:middle
etc. Copy the config for
.symfony/services.yaml...

00:01:38.676 --> 00:01:41.086 align:middle
then open that file and paste.

00:01:42.936 --> 00:01:51.216 align:middle
The database is actually MariaDB, which is why
the version here is 10.2: MariaDB version 10.2.

00:01:52.616 --> 00:01:55.556 align:middle
Notice that we've used the key mydatabase.

00:01:55.876 --> 00:02:02.036 align:middle
That can be anything you want: we'll reference
this string from the other config file

00:02:02.036 --> 00:02:05.836 align:middle
that we need to change: .symfony.cloud.yaml.

00:02:06.766 --> 00:02:10.426 align:middle
Inside that file, we need a relationships key:

00:02:11.576 --> 00:02:16.766 align:middle
this is what binds the web
container to that database service.

00:02:17.896 --> 00:02:18.656 align:middle
Let's see...

00:02:18.656 --> 00:02:25.086 align:middle
we don't have a relationships key yet, so
let's add it: relationships and, below,

00:02:25.416 --> 00:02:34.586 align:middle
add our first relationship with a special
string: database set to mydatabase:mysql.

00:02:35.846 --> 00:02:36.876 align:middle
This syntax...

00:02:36.876 --> 00:02:38.816 align:middle
is a little funny.

00:02:39.346 --> 00:02:43.966 align:middle
The mydatabase part is referring
to whatever key we used

00:02:43.966 --> 00:02:47.336 align:middle
in services.yaml - and then we say :mysql...

00:02:47.336 --> 00:02:52.226 align:middle
because that service is a mysql type.

00:02:53.446 --> 00:02:58.646 align:middle
The really important thing is that
we called this relationship database.

00:02:59.536 --> 00:03:07.336 align:middle
Thanks to that SymfonyCloud will expose an
environment variable called DATABASE_URL

00:03:07.786 --> 00:03:13.926 align:middle
which contains the full MySQL connection
string: username, host, database name and all.

00:03:14.746 --> 00:03:19.036 align:middle
It's literally DATABASE_URL and not PIZZA_URL

00:03:19.356 --> 00:03:23.506 align:middle
because we called the relationship
database instead of pizza...

00:03:23.896 --> 00:03:28.006 align:middle
which would have been less
descriptive, but more delicious.

00:03:28.886 --> 00:03:33.856 align:middle
This is important because DATABASE_URL
happens to be the environment variable

00:03:33.856 --> 00:03:36.866 align:middle
that our app will use to
connect to the database.

00:03:37.786 --> 00:03:41.636 align:middle
In other words, our app will
instantly have database config.

00:03:43.026 --> 00:03:46.346 align:middle
Back at the terminal, hit
"Ctrl+C" to exit from logging.

00:03:47.556 --> 00:03:49.316 align:middle
Let's add the two changes and commit them:

00:03:50.016 --> 00:03:58.426 align:middle
git add .git commit -m "adding
SfCloud database" Now, deploy!

00:03:59.376 --> 00:04:05.146 align:middle
symfony deploy Oh, duh - run with the --

00:04:05.336 --> 00:04:11.946 align:middle
bypass-checks flag: The deploy will still
take some time - it has a lot of work

00:04:11.946 --> 00:04:14.636 align:middle
to do - but it'll be faster than before.

00:04:16.836 --> 00:04:17.956 align:middle
When it finishes...

00:04:18.476 --> 00:04:21.836 align:middle
it dumps the same URL - that won't change.

00:04:22.516 --> 00:04:28.686 align:middle
But to be even lazier than last time, let's tell
the command to open this URL in my browser...

00:04:29.006 --> 00:04:36.516 align:middle
for me: symfony open:remote And...

00:04:36.876 --> 00:04:39.076 align:middle
we have a deployed site!

00:04:39.336 --> 00:04:42.186 align:middle
Woo! The database is empty...

00:04:42.396 --> 00:04:46.016 align:middle
but if this were a real app,
it would start to be populated

00:04:46.016 --> 00:04:50.096 align:middle
by real users entering their
real Bigfoot sightings...

00:04:50.406 --> 00:04:51.896 align:middle
cause Bigfoot is...

00:04:52.036 --> 00:04:52.726 align:middle
totally real.

00:04:53.566 --> 00:04:57.366 align:middle
But... to make this a bit
more interesting for us,

00:04:57.636 --> 00:05:01.476 align:middle
let's load the fixture data
one time on production.

00:05:02.586 --> 00:05:07.676 align:middle
This is a bit tricky because the fixture system
- which comes from DoctrineFixturesBundle -

00:05:07.996 --> 00:05:10.516 align:middle
is a composer "dev" dependency...

00:05:11.176 --> 00:05:14.526 align:middle
which means that it's not
even installed on production.

00:05:15.146 --> 00:05:16.716 align:middle
That's good for performance.

00:05:16.716 --> 00:05:24.066 align:middle
If it were installed, we could run:
symfony ssh to ssh into our container,

00:05:24.236 --> 00:05:26.836 align:middle
and then execute the command
to load the fixtures.

00:05:27.616 --> 00:05:29.336 align:middle
But... that won't work.

00:05:30.376 --> 00:05:30.876 align:middle
No problem!

00:05:31.236 --> 00:05:32.936 align:middle
We can do something cooler.

00:05:33.686 --> 00:05:43.046 align:middle
Exit out of ssh, and run: symfony
tunnel:open I love this feature.

00:05:44.106 --> 00:05:50.176 align:middle
Normally, the remote database isn't accessible
by anything other than our container:

00:05:50.946 --> 00:05:54.026 align:middle
you can't connect to it from
anywhere else on the Internet.

00:05:54.446 --> 00:05:56.016 align:middle
It's totally firewalled.

00:05:56.746 --> 00:06:03.766 align:middle
But suddenly, we can connect to the
production database locally on port 30000.

00:06:04.776 --> 00:06:11.916 align:middle
We can use that to run the fixtures command
locally - but send the data up to that database.

00:06:13.066 --> 00:06:13.706 align:middle
Do it by running:

00:06:14.096 --> 00:06:34.476 align:middle
DATABASE_URL=mysql://root:@127.0.0.1:30000/main
php bin/console doctrine:fixtures:load Ok,

00:06:34.586 --> 00:06:35.836 align:middle
let's break this down.

00:06:35.926 --> 00:06:41.056 align:middle
First, there is actually a much
easier way to do all of this...

00:06:41.106 --> 00:06:44.956 align:middle
but I'll save that for some
future SymfonyCloud tutorial.

00:06:46.146 --> 00:06:49.746 align:middle
Basically, we're running the
doctrine:fixtures:load command

00:06:50.176 --> 00:06:58.206 align:middle
but sending it a different DATABASE_URL:
one that points at our production database.

00:06:59.026 --> 00:07:02.786 align:middle
When you open a tunnel, you can
access the database with root user,

00:07:03.016 --> 00:07:06.046 align:middle
no password - and the database is called main.

00:07:06.046 --> 00:07:09.416 align:middle
The only problem is that this command...

00:07:09.566 --> 00:07:11.956 align:middle
takes forever to run.

00:07:12.876 --> 00:07:17.406 align:middle
I'm not sure exactly why - but it
is doing all of this over a network.

00:07:18.416 --> 00:07:20.766 align:middle
Go grab some coffee and come
back in a few minutes.

00:07:21.646 --> 00:07:22.956 align:middle
When it finishes...

00:07:23.446 --> 00:07:26.126 align:middle
yes! Go refresh the page!

00:07:28.576 --> 00:07:34.826 align:middle
Ha! We have a production site with at least
enough data to make profiling interesting.

00:07:36.016 --> 00:07:37.386 align:middle
Next, let's do that!

00:07:37.786 --> 00:07:40.176 align:middle
Let's configure Blackfire on production!

00:07:40.556 --> 00:07:42.046 align:middle
That's easy right?

00:07:42.446 --> 00:07:46.546 align:middle
Just repeat the Blackfire install
process on a different server...

00:07:46.956 --> 00:07:48.736 align:middle
right? Yep!

00:07:49.206 --> 00:07:50.956 align:middle
Wait, no! Yes!

00:07:51.116 --> 00:07:55.946 align:middle
Bah! To explain, we need to
talk about a wonderful concept

00:07:55.946 --> 00:07:58.436 align:middle
in Blackfire called "environments".

