WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:00.246 --> 00:00:03.696 align:middle
Okay. Welcome.

00:00:04.216 --> 00:00:06.066 align:middle
Good morning.

00:00:07.976 --> 00:00:09.446 align:middle
Thank you.

00:00:15.276 --> 00:00:20.816 align:middle
So if you are in the stairs over there, I can
see empty seats everywhere here in the front.

00:00:21.776 --> 00:00:24.996 align:middle
So if you can come, as you like.

00:00:24.996 --> 00:00:29.266 align:middle
Okay. So today's talk is
about, it's a series of talks.

00:00:29.436 --> 00:00:32.466 align:middle
I'm going to give over the next few conferences.

00:00:32.986 --> 00:00:39.676 align:middle
Um, I talked about emails during SymfonyLive
London a few months ago and today it's going

00:00:39.676 --> 00:00:43.606 align:middle
to be another talk about
getting back to the basics.

00:00:44.166 --> 00:00:46.766 align:middle
And the topic is a local web server.

00:00:46.766 --> 00:00:49.436 align:middle
Are you excited about that?

00:00:50.666 --> 00:00:57.796 align:middle
No. Okay. Too bad anyway, Even
if you're not excited about that,

00:00:57.796 --> 00:01:02.416 align:middle
it's going to be what I'm
going to talk about today.

00:01:03.556 --> 00:01:08.976 align:middle
Okay. So a few month ago I talked about and,
and, and actually I asked people on Twitter

00:01:08.976 --> 00:01:15.976 align:middle
about which a web servers that we're using on
our local machines, uh, that's the results.

00:01:16.346 --> 00:01:19.516 align:middle
So as you can see a lot of
people are still using php -S

00:01:19.516 --> 00:01:21.716 align:middle
which is a builtin a php web server.

00:01:22.266 --> 00:01:26.536 align:middle
Um, and also using the symfony
server:start, which is exactly the same

00:01:26.536 --> 00:01:28.576 align:middle
because we understand that we are using php -S.

00:01:28.576 --> 00:01:34.286 align:middle
Anyway, a bunch of people are using
Docker, Nginx, Apache and Vagrant.

00:01:34.286 --> 00:01:37.596 align:middle
So the problem with that
is that php -S is great.

00:01:37.596 --> 00:01:38.456 align:middle
It is very easy.

00:01:38.456 --> 00:01:42.056 align:middle
You need to install the WebServerBundle
and then you can get started really easily.

00:01:42.056 --> 00:01:44.836 align:middle
The problem is that it comes
with many limitations

00:01:44.836 --> 00:01:46.256 align:middle
and I'm going to talk about that in minute.

00:01:46.896 --> 00:01:52.856 align:middle
Docker, well may be slow depending
on the platform, especially on a Mac.

00:01:53.566 --> 00:01:54.986 align:middle
I mean it is for me at least.

00:01:55.496 --> 00:02:00.276 align:middle
Um, and it's kind of inconvenient and
I'm going to talk about that as well.

00:02:00.756 --> 00:02:08.616 align:middle
Um, Nginx and Apache, it depends
on your skills on those um, uh...

00:02:09.346 --> 00:02:13.326 align:middle
programs, but it needs some
setup and it's not that easy.

00:02:13.326 --> 00:02:15.616 align:middle
It's not really nice if you ask me.

00:02:15.966 --> 00:02:19.966 align:middle
The great thing about using Nginx or Apache
on your local server, it's probably the same

00:02:19.966 --> 00:02:22.566 align:middle
that you're going to have
on your production machines.

00:02:22.946 --> 00:02:27.686 align:middle
So that's really nice and Vagrant is also
not very convenient because it's, you know,

00:02:27.686 --> 00:02:32.706 align:middle
something you need to install and then
you have some kind of, virtual machines.

00:02:33.766 --> 00:02:37.766 align:middle
So. Okay. So that's my setup.

00:02:37.766 --> 00:02:42.276 align:middle
The setup I would like: something that
is really fast and when I say fast, um,

00:02:42.326 --> 00:02:45.246 align:middle
I want the web server to be really responsive.

00:02:45.246 --> 00:02:47.616 align:middle
So I don't want to wait for something to happen.

00:02:47.936 --> 00:02:48.786 align:middle
And convenient.

00:02:49.426 --> 00:02:54.506 align:middle
And by convenient, I mean I want my
files to be locally on my laptop.

00:02:54.506 --> 00:02:59.326 align:middle
I don't want them to be on a
Docker share or NFS or whatever.

00:02:59.626 --> 00:03:02.406 align:middle
Or on the virtual machine because
then it's going to be slow.

00:03:02.996 --> 00:03:09.756 align:middle
I don't care about services so I don't care
if my MySQL database or Postgres or Redis is

00:03:09.756 --> 00:03:13.576 align:middle
on my laptop and actually I don't
want to install anything on my laptop.

00:03:14.016 --> 00:03:18.876 align:middle
So I like to be able to use remote services, it
can be Docker, can be Symfony Cloud, whatever.

00:03:19.406 --> 00:03:22.116 align:middle
And I want something that
works on all platforms.

00:03:22.116 --> 00:03:26.656 align:middle
Not that I have three different
laptops, but just because I care

00:03:26.656 --> 00:03:31.606 align:middle
about people in the room not using a Mac.

00:03:31.606 --> 00:03:32.916 align:middle
How many of you are using Windows?

00:03:41.336 --> 00:03:47.716 align:middle
One, two, three, four, five, six,
seven, eight, nine, 10 to 12.

00:03:49.496 --> 00:03:51.006 align:middle
Okay. Linux?

00:03:52.156 --> 00:03:52.496 align:middle
Much more.

00:03:53.516 --> 00:03:54.026 align:middle
And a Mac?

00:03:55.796 --> 00:03:56.416 align:middle
About the same.

00:03:56.766 --> 00:03:58.786 align:middle
Okay, cool.

00:04:00.016 --> 00:04:02.216 align:middle
So I was talking about the PHP built in server,

00:04:02.746 --> 00:04:05.486 align:middle
it's almost perfect, but
it has many limitations.

00:04:05.486 --> 00:04:09.476 align:middle
So the first one is that it can
only do one connection at a time,

00:04:09.476 --> 00:04:14.216 align:middle
which is kind of annoying sometimes when you
have a bunch of ESI's for instance and things

00:04:14.216 --> 00:04:17.636 align:middle
like that, your website can
you kind of slow, even locally.

00:04:18.156 --> 00:04:24.136 align:middle
No support for HTTP-2, no support for tls,
which is kind of a requirement nowadays.

00:04:24.556 --> 00:04:27.826 align:middle
And if you are using Symfony
4, with environment variables,

00:04:28.156 --> 00:04:30.656 align:middle
you might know that it does not
reload environment variables

00:04:30.656 --> 00:04:32.476 align:middle
from one request to the next.

00:04:32.476 --> 00:04:36.616 align:middle
So if you change your variables then you
need to stop and restart your web server.

00:04:37.316 --> 00:04:39.816 align:middle
And also it needs some tweaks
to make it work with Symfony.

00:04:40.016 --> 00:04:44.156 align:middle
So if you are just using php -S,
like that is not going to work well.

00:04:44.156 --> 00:04:48.136 align:middle
It kind of works, but we have a
special router to make it work.

00:04:48.136 --> 00:04:49.766 align:middle
That's why we have the WebServerBundle.

00:04:50.446 --> 00:04:55.926 align:middle
But it's nice because it's
local, it's using my local files.

00:04:55.926 --> 00:04:57.806 align:middle
It's really fast and it just works.

00:04:58.396 --> 00:05:02.516 align:middle
So in the last few weeks I've been
working on a better local web server

00:05:03.066 --> 00:05:05.706 align:middle
and that's what are we going to talk about.

00:05:06.476 --> 00:05:09.516 align:middle
And it's available via the
the new symfony binary.

00:05:09.516 --> 00:05:11.356 align:middle
I'm not sure if you are all aware about that.

00:05:11.356 --> 00:05:14.266 align:middle
I Tweeted about that yesterday or earlier today.

00:05:14.266 --> 00:05:14.946 align:middle
I don't remember.

00:05:15.396 --> 00:05:18.516 align:middle
And we had a blog post about
Symfony cloud a few days ago

00:05:19.026 --> 00:05:24.206 align:middle
and everything is available
via a new symfony binary.

00:05:24.356 --> 00:05:29.006 align:middle
So the new symfony binary is not just about
Symfony Cloud, it's about a bunch of things.

00:05:29.336 --> 00:05:34.096 align:middle
So I talked about two of them last week
in my blog post about Symfony Cloud.

00:05:34.096 --> 00:05:35.396 align:middle
The first one is security checks.

00:05:35.396 --> 00:05:40.586 align:middle
So if you want to check your
composer.json, for security issues,

00:05:41.046 --> 00:05:46.126 align:middle
you can use security.symfony.com
if you want and the API.

00:05:46.156 --> 00:05:52.016 align:middle
Or you can use symfony security:check, which
is nice because it does not connect to the API.

00:05:52.286 --> 00:05:54.136 align:middle
So it's, everything happens locally.

00:05:54.426 --> 00:05:59.056 align:middle
So it clones a GitHub repository
but then everything happens locally.

00:05:59.056 --> 00:06:03.926 align:middle
So that's a nice way to not
depend on security.symfony.com.

00:06:03.926 --> 00:06:07.936 align:middle
And symfony new is a way to
create a new symfony project.

00:06:07.936 --> 00:06:11.566 align:middle
It's just a thin wrapper on top of a composer,

00:06:12.016 --> 00:06:18.326 align:middle
so you don't have to remind the composer
create-project symfony/skeleton thing.

00:06:18.886 --> 00:06:20.916 align:middle
You can just use symfony new.

00:06:20.916 --> 00:06:24.106 align:middle
By default it creates a project
with symfony/skeleton

00:06:24.426 --> 00:06:28.186 align:middle
and then you can say I want
a demo or a full website

00:06:28.186 --> 00:06:30.076 align:middle
which is using the symfony/website-skeleton.

00:06:30.136 --> 00:06:31.886 align:middle
And then it does a few other things.

00:06:31.886 --> 00:06:34.336 align:middle
The first one is it does git init.

00:06:34.876 --> 00:06:39.426 align:middle
It also configure everything for Symfony
Cloud if you are interested in that.

00:06:39.426 --> 00:06:45.386 align:middle
Okay. And of course, as of today, it's
also about the symfony local web server.

00:06:45.386 --> 00:06:46.856 align:middle
So that's how you can use it.

00:06:47.186 --> 00:06:51.966 align:middle
You can just say symfony
server:start and it should just work.

00:06:52.936 --> 00:06:55.266 align:middle
So it uses the first available port.

00:06:55.266 --> 00:06:58.296 align:middle
Instead of 8000 you can configure
it if that makes sense for you.

00:06:58.666 --> 00:07:03.696 align:middle
And then you have all the logs from
PHP and, and a bunch of other things.

00:07:03.746 --> 00:07:09.056 align:middle
You can also start it in background with
-d and the great thing about that is

00:07:09.086 --> 00:07:11.636 align:middle
that then you can just fire and forget.

00:07:12.166 --> 00:07:15.646 align:middle
And the great thing - and that's very
different from what you get from php -S

00:07:15.646 --> 00:07:20.906 align:middle
that you can just say symfony server:log
to tail the logs of the server,

00:07:20.906 --> 00:07:22.436 align:middle
which is not possible with php -S.

00:07:22.436 --> 00:07:26.306 align:middle
And then you can say symfony open:local
to open a website in the browser.

00:07:27.586 --> 00:07:31.466 align:middle
Okay, so some of the features
from the symfony local web server.

00:07:31.466 --> 00:07:34.426 align:middle
The first one is don't need
to be root to run it.

00:07:34.426 --> 00:07:37.676 align:middle
It runs on a port more than 8000.

00:07:37.676 --> 00:07:38.576 align:middle
So that's not a problem.

00:07:38.866 --> 00:07:42.886 align:middle
It uses php-fpm, which is very
important because it's more similar

00:07:42.886 --> 00:07:44.616 align:middle
to what you would get in production.

00:07:45.086 --> 00:07:48.736 align:middle
But it does more than that because
I realized while working on that

00:07:48.736 --> 00:07:50.686 align:middle
and I wanted to make it work on Windows.

00:07:51.006 --> 00:07:54.816 align:middle
And now I realiz it was not really
necessary because you are not that many.

00:07:55.566 --> 00:07:59.066 align:middle
Um, it took me a lot of time really.

00:07:59.066 --> 00:08:02.216 align:middle
But now I have a virtual machine on my
laptop with windows, which is kind of nice.

00:08:02.746 --> 00:08:07.916 align:middle
I mean, Windows is much nicer than
it was 10 years ago, so that's great.

00:08:08.226 --> 00:08:13.146 align:middle
But php-fpm does not work or
it is not available on windows.

00:08:13.546 --> 00:08:19.056 align:middle
So when you don't have php-fpm, it falls
back to php-cgi, which is also fastcgi.

00:08:19.056 --> 00:08:22.406 align:middle
And then php -S if there is nothing else.

00:08:23.126 --> 00:08:28.576 align:middle
It supports HTTP-2, it supports
tls, some push support.

00:08:28.576 --> 00:08:34.256 align:middle
So if you have some link headers and - the
support and we do have support in Symfony -

00:08:34.536 --> 00:08:37.116 align:middle
then it's going to work with this web server.

00:08:37.776 --> 00:08:40.586 align:middle
It works with any PHP project,
there is no, nothing special.

00:08:40.586 --> 00:08:42.026 align:middle
So there's no configuration, nothing.

00:08:42.026 --> 00:08:46.506 align:middle
It just works with any PHP
framework or CMS's or whatever.

00:08:46.506 --> 00:08:52.746 align:middle
You can also use it, use it for a plain HTML
websites, if you have a nodejs thing, um,

00:08:52.746 --> 00:08:56.866 align:middle
or something that is only on,
on, on, on, on the frontend.

00:08:57.356 --> 00:08:59.756 align:middle
And hopefully it's a great developer experience.

00:08:59.756 --> 00:09:02.026 align:middle
And we are going to talk a bit more about that.

00:09:02.896 --> 00:09:10.676 align:middle
So the first big feature I wanted to mention
is that it also manages your local php version.

00:09:11.016 --> 00:09:14.636 align:middle
So it does not install php itself,
but if you have more than one version

00:09:14.686 --> 00:09:17.996 align:middle
on your machine, then you can use them.

00:09:18.086 --> 00:09:20.406 align:middle
And that's very interesting
because it allows you

00:09:20.406 --> 00:09:23.346 align:middle
to test a new version of PHP, uh, out of time.

00:09:23.346 --> 00:09:28.136 align:middle
So if you want to test your website on
php 7.3 for instance, that's a use case.

00:09:28.136 --> 00:09:31.156 align:middle
Or if you want to test a different
configuration with, with, you know,

00:09:31.156 --> 00:09:33.776 align:middle
a different php.ini file or something like that.

00:09:34.206 --> 00:09:36.996 align:middle
And of course if you're working
on different projects,

00:09:36.996 --> 00:09:39.376 align:middle
you might need more than one php version.

00:09:39.936 --> 00:09:42.606 align:middle
Um, and actually when I started to work on that,

00:09:42.606 --> 00:09:47.266 align:middle
I realized that most people do have
several php versions on their machine even

00:09:47.266 --> 00:09:48.916 align:middle
if they are not able to access them.

00:09:49.316 --> 00:09:52.396 align:middle
So for instance, if you are using
the Mac and you're using Homebrew

00:09:52.396 --> 00:09:56.536 align:middle
to install your php versions,
you do have more than one version

00:09:56.536 --> 00:09:59.476 align:middle
because whenever you are
upgrading to new version,

00:09:59.476 --> 00:10:02.896 align:middle
the oldest ones are still there on your machine.

00:10:03.266 --> 00:10:06.936 align:middle
And you can switch from one to the next
one, but that's the global configuration.

00:10:06.936 --> 00:10:09.126 align:middle
So I wanted something that
is local and not global.

00:10:10.116 --> 00:10:13.406 align:middle
So there is a command to do that.

00:10:13.406 --> 00:10:17.706 align:middle
So if you run this command, you will see all
the things that you have on your machine.

00:10:17.706 --> 00:10:22.656 align:middle
That's what I have right now on my machine and
it detects the kind of things that you have:

00:10:22.656 --> 00:10:26.166 align:middle
php-cli, php-fpm, php-cgi and things like that.

00:10:26.166 --> 00:10:29.036 align:middle
And you can see which one is going
to be used for the web server.

00:10:29.416 --> 00:10:30.186 align:middle
And a default one.

00:10:31.146 --> 00:10:35.336 align:middle
So if you want to change them, if you
want in a directory for a project,

00:10:35.336 --> 00:10:39.426 align:middle
if you want a very specific version
of PHP, that's how you can do that.

00:10:39.426 --> 00:10:41.916 align:middle
So you can create a .php-version file.

00:10:41.966 --> 00:10:52.516 align:middle
And then, um, I can say I want php 7 or php 7.1
or php 7.1.13 or whatever, and it's going to use

00:10:52.796 --> 00:10:56.016 align:middle
that specific version in
that specific directory.

00:10:56.016 --> 00:10:58.166 align:middle
So it's not going to be global,
it's really local.

00:10:59.456 --> 00:11:00.916 align:middle
Okay. So that's great.

00:11:01.626 --> 00:11:06.246 align:middle
Um, so when you, when you run server:start
depending on the current directory,

00:11:06.556 --> 00:11:10.026 align:middle
it's going to check for a .php-version file.

00:11:10.416 --> 00:11:13.006 align:middle
If there is one, it is going to
use the version from that, if not,

00:11:13.006 --> 00:11:18.906 align:middle
it falls back to .symfony.cloud.yaml and by
default it uses what you have in your path.

00:11:19.476 --> 00:11:26.296 align:middle
Um, it also, it's also about
having the best backend possible.

00:11:26.296 --> 00:11:30.646 align:middle
So again, php-fpm by default, if
it is not available, then php-cgi,

00:11:30.646 --> 00:11:33.896 align:middle
and as a last resort, it uses php -S.

00:11:34.776 --> 00:11:36.806 align:middle
Okay, it also works on your terminal.

00:11:36.806 --> 00:11:40.266 align:middle
So if you want to run PHP and have the
same version of the local web server,

00:11:40.586 --> 00:11:44.526 align:middle
that's how you can do that:
symfony php and whatever.

00:11:44.526 --> 00:11:47.326 align:middle
It uses the exact same algorithm
as the web server of course.

00:11:47.656 --> 00:11:49.466 align:middle
So that's very nice to be
able to have the same version

00:11:49.466 --> 00:11:53.866 align:middle
for the web server and also
for the command line.

00:11:54.486 --> 00:11:58.356 align:middle
Um, and you can also configure
PHP per directory.

00:11:58.356 --> 00:12:00.716 align:middle
I talked about that earlier.

00:12:01.016 --> 00:12:04.446 align:middle
So if you have, if you need a
special time zone, for instance,

00:12:04.446 --> 00:12:06.376 align:middle
for a project, that's how you can do it.

00:12:06.466 --> 00:12:11.616 align:middle
You can create a php.ini file when you
have some kind of php configuration there.

00:12:11.616 --> 00:12:17.336 align:middle
And then it's going to be loaded automatically
by symfony php and also by the web server.

00:12:17.336 --> 00:12:22.636 align:middle
So you have the exact same configuration for the
web server and also for php in the command line.

00:12:23.236 --> 00:12:25.856 align:middle
Okay. And of course, that's
something you can do as well.

00:12:26.586 --> 00:12:31.526 align:middle
You can just copy the symfony binary
and name it php, pecl, php-fpm,

00:12:31.526 --> 00:12:33.766 align:middle
php-config, and it's just a thin wrapper.

00:12:33.766 --> 00:12:37.846 align:middle
And it's going to act as symfony php,
which means that that's exactly what I have

00:12:37.986 --> 00:12:40.996 align:middle
on my laptop, which means that
whenever I type php something,

00:12:40.996 --> 00:12:45.556 align:middle
it's going to use the right version for the,
for the directory I'm in, which is kind of nice.

00:12:46.346 --> 00:12:48.026 align:middle
Okay. I talked about logs.

00:12:48.386 --> 00:12:50.526 align:middle
Logs are very important if
you wanted to debug things,

00:12:50.696 --> 00:12:53.426 align:middle
you need to have all the
logs failure but very easily.

00:12:53.806 --> 00:12:56.386 align:middle
Um, so that's how you can do that server:logs.

00:12:56.926 --> 00:13:01.636 align:middle
And then it's going to tail all
the logs from php, of course,

00:13:01.676 --> 00:13:05.716 align:middle
from php-fpm, but also for from symfony.

00:13:06.216 --> 00:13:10.966 align:middle
So as you can see here, we have some logs
from symfony, uh, and as you can see,

00:13:10.966 --> 00:13:16.406 align:middle
it's not exactly the same as the logs that
you have from the var/log/dev.log file,

00:13:16.406 --> 00:13:23.396 align:middle
because we actually parse all the
logs, we convert them to semantic JSON,

00:13:23.396 --> 00:13:28.096 align:middle
and then we kind of humanize them so
that it's easier to spot problems.

00:13:28.606 --> 00:13:32.986 align:middle
I don't know for you, but
sometimes when I'm tailing logs,

00:13:33.246 --> 00:13:36.426 align:middle
especially for the production environments
and there's some kind of a problem I need

00:13:36.426 --> 00:13:40.386 align:middle
to debug the problem, it's kind of
hard to figure out where the problem is

00:13:40.386 --> 00:13:41.926 align:middle
and where you got your exception.

00:13:41.926 --> 00:13:44.296 align:middle
So here we make it very clear.

00:13:44.296 --> 00:13:48.426 align:middle
So if there is an error like we
have here, you have this red thing

00:13:48.426 --> 00:13:50.666 align:middle
so that you can spot the problems really easily.

00:13:50.666 --> 00:13:56.466 align:middle
You can also use it even if you are not using
the web server by passing a file directly

00:13:56.756 --> 00:14:03.106 align:middle
to the command and it's going to read the
file and parse them and, and you manage them.

00:14:03.106 --> 00:14:05.026 align:middle
Okay. The next thing is TLS.

00:14:05.406 --> 00:14:10.966 align:middle
How many of you have a website in
production without https support?

00:14:13.296 --> 00:14:14.786 align:middle
Ah, you can raise your hand.

00:14:14.786 --> 00:14:17.016 align:middle
Okay, I'm going to raise my hand.

00:14:17.886 --> 00:14:18.716 align:middle
Nobody really?

00:14:18.796 --> 00:14:24.666 align:middle
Okay. The, so that's, just one, he's
not here, he's somewhere in the room.

00:14:24.966 --> 00:14:26.776 align:middle
So TLS is very important nowadays.

00:14:26.776 --> 00:14:29.476 align:middle
You need to have https support
so I think you need

00:14:29.476 --> 00:14:32.146 align:middle
to have support for your local, local server.

00:14:32.146 --> 00:14:34.866 align:middle
It's more similar to production.

00:14:34.906 --> 00:14:38.966 align:middle
You can detect mixed content early on
which is already, always a nightmare

00:14:38.966 --> 00:14:42.016 align:middle
if you not detect that before
going to production.

00:14:42.486 --> 00:14:46.596 align:middle
And sometimes it's also a requirement
for some JavaScript libraries.

00:14:46.596 --> 00:14:51.616 align:middle
For instance, if you are using stripe, if
you don't have https it's not going to work.

00:14:52.546 --> 00:14:55.416 align:middle
Okay. So the first step is, and
it works in the exact same way

00:14:55.416 --> 00:14:58.846 align:middle
on the three platforms, you
can use server:ca:install.

00:14:58.846 --> 00:15:02.706 align:middle
So what it does, behind the scenes, it
creates a local certificate authority.

00:15:03.216 --> 00:15:07.196 align:middle
It is going to register it
on your system trust store,

00:15:07.286 --> 00:15:09.316 align:middle
which is different depending on the platform.

00:15:09.766 --> 00:15:15.916 align:middle
It registers it on firefox because Firefox
is using its on mechanism for that.

00:15:15.916 --> 00:15:21.646 align:middle
So, uh, that's also something we do and then
it creates a default certificate for localhost.

00:15:21.646 --> 00:15:28.286 align:middle
Uh, so that when you actually
access your website is https,

00:15:28.636 --> 00:15:31.306 align:middle
you have a default certificate to work with.

00:15:31.776 --> 00:15:36.776 align:middle
So it's everything is stored under your own
directory, under the .symfony directory,

00:15:36.776 --> 00:15:39.616 align:middle
and then certs and you can see, um, the,

00:15:39.616 --> 00:15:43.616 align:middle
the local certificate authority
and a default certificate.

00:15:45.686 --> 00:15:52.936 align:middle
And done. So now when you start a
server and you have this tls support,

00:15:53.186 --> 00:15:56.056 align:middle
you are going to be using https by default.

00:15:56.396 --> 00:15:59.186 align:middle
And by the way, we have http
and https on the same port.

00:15:59.186 --> 00:16:02.916 align:middle
So you don't need to remember
two different ports for that.

00:16:02.916 --> 00:16:07.716 align:middle
And by default we redirect http to https.

00:16:08.326 --> 00:16:12.376 align:middle
Okay, so the next step is
having local domain names.

00:16:12.476 --> 00:16:15.196 align:middle
And that's also nice because
of a bunch of reasons.

00:16:15.196 --> 00:16:19.036 align:middle
So the first one is that, you know,
some project depend on the domain name.

00:16:19.036 --> 00:16:23.416 align:middle
That's the case for the symfony live
conference website for instance, we have Lisbon,

00:16:23.416 --> 00:16:25.286 align:middle
we have Paris, two different domain names.

00:16:25.286 --> 00:16:30.316 align:middle
And depending on the domain, the website
is not going to be exactly the same.

00:16:30.406 --> 00:16:34.126 align:middle
You don't need to remember the ports, so
don't need to remember that this website is

00:16:34.126 --> 00:16:38.496 align:middle
on port 8000 or that one on another one.

00:16:38.496 --> 00:16:42.796 align:middle
So you have something that is stable, it
can be stable across machines as well.

00:16:42.796 --> 00:16:48.506 align:middle
We can use the same domain names on two
different machines and it uses regular ports.

00:16:48.506 --> 00:16:55.716 align:middle
So it's, you're going to use port 80 and port
443 for https, which is again more similar

00:16:55.716 --> 00:16:57.736 align:middle
to work you would have in production.

00:16:57.736 --> 00:16:59.716 align:middle
And that's always a nice to have.

00:17:00.746 --> 00:17:04.066 align:middle
It's totally optional, so
you don't need to use it.

00:17:04.066 --> 00:17:07.486 align:middle
If you want to use it, you can start a proxy.

00:17:07.566 --> 00:17:08.826 align:middle
So symfony proxy:start.

00:17:09.226 --> 00:17:10.476 align:middle
you don't need to be root.

00:17:10.476 --> 00:17:11.726 align:middle
And that's very important for me.

00:17:11.906 --> 00:17:14.376 align:middle
You don't need to be root to use the proxy even

00:17:14.376 --> 00:17:19.366 align:middle
if you are using port 80
and 443 just for a reason.

00:17:19.596 --> 00:17:22.856 align:middle
And the reason is that we are using
a proxy configuration that works

00:17:22.856 --> 00:17:24.976 align:middle
in the exact same way on the three platforms.

00:17:25.506 --> 00:17:29.886 align:middle
Uh, so you have nothing to install, you
don't have to install DNS mask or whatever.

00:17:29.886 --> 00:17:34.126 align:middle
You don't need to mess with
your local DNS configuration,

00:17:34.126 --> 00:17:38.306 align:middle
you don't need to edit your
/etc/hosts file, for instance,

00:17:38.846 --> 00:17:42.826 align:middle
and it does not intercept regular
traffic because that's the configuration.

00:17:42.826 --> 00:17:48.646 align:middle
So if you want to have a look at how it works,
you can curl this URL and you will see piece of,

00:17:48.756 --> 00:17:58.106 align:middle
JavaScript, and if the domain name is wip, which
is the default TLD we are using for the proxy,

00:17:58.346 --> 00:17:59.836 align:middle
then it's going to use the proxy.

00:17:59.836 --> 00:18:06.796 align:middle
If not, it's just, you know, doing nothing
and, and, and, and not intercepting traffic.

00:18:07.386 --> 00:18:12.036 align:middle
Okay? So, so the first thing you do
is you attach domain to a directory

00:18:12.036 --> 00:18:14.126 align:middle
so you can do to your project directory.

00:18:14.126 --> 00:18:15.546 align:middle
Then you attach a domain.

00:18:15.916 --> 00:18:19.736 align:middle
So here I'm going to attach
symfony.com On this symfony.com website,

00:18:20.156 --> 00:18:23.426 align:middle
and then you start the server
if it's not already done,

00:18:23.426 --> 00:18:29.706 align:middle
and it's going to attach a
domain name with the right port.

00:18:29.936 --> 00:18:31.206 align:middle
So that's done automatically.

00:18:31.206 --> 00:18:34.046 align:middle
You don't need to configure that.

00:18:34.046 --> 00:18:38.416 align:middle
You can edit all the configuration
under the proxy.json configuration file.

00:18:38.716 --> 00:18:42.206 align:middle
So wip is the default if you want
to use .sf that's also possible.

00:18:42.596 --> 00:18:44.206 align:middle
I think that's kind of nice.

00:18:44.256 --> 00:18:48.536 align:middle
Um, we have wildcard support, so
if you need more than one domain

00:18:48.536 --> 00:18:54.126 align:middle
for a project that's also possible and all
the tls certificates are going to be created

00:18:54.126 --> 00:18:57.316 align:middle
on demand locally, so we don't need to be
connected to the internet to make it work.

00:18:57.556 --> 00:19:03.946 align:middle
It works locally, so it's not using a,
it's not using a letsencrypt, for instance.

00:19:04.156 --> 00:19:10.176 align:middle
Uh, the nice thing about the fact that
you have a proxy for the whole tld is

00:19:10.406 --> 00:19:15.406 align:middle
that if you are hitting something that
does not exist, then you have, um,

00:19:15.406 --> 00:19:18.576 align:middle
a good error message saying that,
okay, it's not linked to any directory.

00:19:18.576 --> 00:19:21.836 align:middle
If you want to do that, you can
run this command to make it work.

00:19:21.836 --> 00:19:27.126 align:middle
Um, and if you go to the proxy directly, you
have the list of all the domains that you have

00:19:27.126 --> 00:19:30.766 align:middle
in all the projects that you have on
your machine that can just click on them.

00:19:31.926 --> 00:19:37.816 align:middle
And it does work with curl as well, so you
can just export HTTP_PROXY and HTTPS_PROXY

00:19:37.816 --> 00:19:43.586 align:middle
with proxy url and it's going to work for curl
or, or whatever you're using because of course,

00:19:43.766 --> 00:19:49.176 align:middle
not of course, but curl does
not use your system cert store.

00:19:49.176 --> 00:19:53.566 align:middle
So you need to do that to make it work,
if not, you're going to have an error.

00:19:54.426 --> 00:19:58.416 align:middle
Okay, so now I'm going to talk a bit
about the integration with Symfony

00:19:58.416 --> 00:20:07.136 align:middle
because in the Symfony world and it's a trend
that we can see over the last few years,

00:20:07.136 --> 00:20:09.536 align:middle
I would say, where we have more

00:20:09.536 --> 00:20:13.606 align:middle
and more long-running commands
in the Symfony world, right?

00:20:13.606 --> 00:20:20.896 align:middle
We have one for a dumping, the var-dumper,
things that you might have in your project.

00:20:21.256 --> 00:20:25.816 align:middle
We have one to consume messages
from the Messenger component.

00:20:26.216 --> 00:20:32.306 align:middle
We also have, Encore, if you are using
Encore or yarn or whatever, you want,

00:20:32.306 --> 00:20:34.826 align:middle
you might want to watch what's
going on in your project

00:20:34.826 --> 00:20:37.856 align:middle
so that I can compile their
assets whenever they change.

00:20:38.186 --> 00:20:40.336 align:middle
So we do have support for that as well.

00:20:40.806 --> 00:20:44.586 align:middle
A symfony run, I'm not sure I
mentioned symfony run before.

00:20:44.726 --> 00:20:52.726 align:middle
So symfony run is a way to run a command
with some nice features and I'm going

00:20:52.726 --> 00:20:54.656 align:middle
to talk about them after the slides.

00:20:54.656 --> 00:21:00.716 align:middle
Anyway, so symfony run -d daemon and then you
can type whatever you want and it's going to run

00:21:00.716 --> 00:21:05.396 align:middle
in the background for you and
manage the background process.

00:21:05.706 --> 00:21:11.416 align:middle
The nice thing about that is that when you
are using server:log, then you are also going

00:21:11.416 --> 00:21:15.656 align:middle
to have the command log, so all the
logs from php-fpm, Symfony project

00:21:15.656 --> 00:21:19.636 align:middle
and also all the commands that you
run via the symfony run command.

00:21:20.356 --> 00:21:23.736 align:middle
And if you say symfony server:status,
you can see that you have the web server

00:21:23.736 --> 00:21:25.896 align:middle
and the command that is running on this PID.

00:21:25.896 --> 00:21:29.546 align:middle
And you stop the server then it's
going to also stop the command.

00:21:29.546 --> 00:21:36.416 align:middle
So you can run any numbers of commands and
they are going to be attached to your project.

00:21:36.416 --> 00:21:40.786 align:middle
Okay. Of course it's also fully
integrated with Symfony Cloud

00:21:40.786 --> 00:21:42.586 align:middle
and optimized for Symfony projects.

00:21:42.586 --> 00:21:51.436 align:middle
So the previous one - you will be able to take
a photo in a minute - at the previous one,

00:21:51.476 --> 00:21:57.336 align:middle
so you know encore it's, it's not really linked
to Symfony, so you can use it for any project.

00:21:57.336 --> 00:22:02.166 align:middle
But now I'm going to talk about things that
are really optimized for a Symfony project.

00:22:02.166 --> 00:22:04.606 align:middle
So I talked about logs and
Symfony logs that we parse.

00:22:04.886 --> 00:22:06.236 align:middle
But we have more than that.

00:22:06.236 --> 00:22:11.626 align:middle
So the first one is that, and I talked
about that at the beginning of the session,

00:22:11.886 --> 00:22:14.836 align:middle
I want to be able to use my
local server with my local files,

00:22:14.866 --> 00:22:21.946 align:middle
but I don't want to install a database
server or redis or whatever on my machine.

00:22:22.356 --> 00:22:26.456 align:middle
So I'm going to show you how you
can do that with Symfony Cloud.

00:22:26.646 --> 00:22:29.796 align:middle
And I think that's a very nice scenario.

00:22:29.796 --> 00:22:35.306 align:middle
So let's say that we have a project hosted on
Symfony Cloud with the demo.com domain name.

00:22:35.306 --> 00:22:36.476 align:middle
That's how you can get started.

00:22:36.476 --> 00:22:38.926 align:middle
You have your project, you run project:init

00:22:38.926 --> 00:22:42.856 align:middle
so that you generate a default
configuration for Symfony Cloud.

00:22:43.326 --> 00:22:46.856 align:middle
Then use symfony deploy it's going
to deploy a cluster of containers,

00:22:47.426 --> 00:22:50.486 align:middle
for php of course, for all your services.

00:22:51.526 --> 00:22:57.236 align:middle
It's going to provision a tls certificate
as well, and then when you deploy,

00:22:57.236 --> 00:22:59.736 align:middle
it's going to be your master branch,

00:22:59.736 --> 00:23:03.586 align:middle
which is the production environment
in terms of Symfony Cloud.

00:23:04.126 --> 00:23:10.216 align:middle
And then you can attach domain more or less like
what we had before for the proxy and it's going

00:23:10.216 --> 00:23:12.596 align:middle
to attach a demo.com domain to your project.

00:23:12.846 --> 00:23:17.976 align:middle
And by default, of course, the environment
is production and debug is set to false.

00:23:18.906 --> 00:23:22.746 align:middle
Now, let's say I want to work
on a new feature or I have a bug

00:23:22.746 --> 00:23:25.156 align:middle
in production and wanted to debug the problem.

00:23:25.526 --> 00:23:31.026 align:middle
Instead of working directly in production
and, uh, um, or working on my local machine

00:23:31.026 --> 00:23:35.696 align:middle
with fake data, I want to have a
replicate of what I have in production.

00:23:35.696 --> 00:23:40.336 align:middle
So what you can do is, you can
use the env:create command.

00:23:41.126 --> 00:23:44.776 align:middle
It's going to create a new git branch
for your code locally, of course.

00:23:45.196 --> 00:23:48.096 align:middle
Then it's going to deploy a
new cluster of containers,

00:23:48.096 --> 00:23:51.546 align:middle
which is going to be the exact same
cluster as what you have in production.

00:23:51.546 --> 00:23:58.106 align:middle
So the same services, but also it's going to
copy the data, the exact same data that you have

00:23:58.106 --> 00:24:03.356 align:middle
in production, and then you can
use symfony open:remote to get...

00:24:03.356 --> 00:24:06.176 align:middle
the website is going to be exactly,
exactly the same as production

00:24:06.176 --> 00:24:08.376 align:middle
with environment production as well.

00:24:08.376 --> 00:24:14.656 align:middle
Uh, let's say that you have a problem, you
can use symfony:log to get all the logs

00:24:14.656 --> 00:24:20.706 align:middle
from the remote web server, so that's the same
as server:log, but for the remote services.

00:24:21.516 --> 00:24:25.146 align:middle
But by default we want to replicate
the production environment.

00:24:25.146 --> 00:24:28.106 align:middle
So the environment is production,
even for this branch.

00:24:28.486 --> 00:24:32.536 align:middle
If you want to switch to the debug mode you
can use symfony debug and it's going to switch

00:24:32.726 --> 00:24:36.826 align:middle
to the development environment
and set debug to true.

00:24:37.866 --> 00:24:39.426 align:middle
Okay, so that's remote.

00:24:39.526 --> 00:24:41.136 align:middle
I have all my services remote now.

00:24:41.136 --> 00:24:43.216 align:middle
I want to debug things locally on my machine.

00:24:43.256 --> 00:24:52.946 align:middle
So I have attached my local web server
to the demo.com.wip domain name.

00:24:53.466 --> 00:24:57.636 align:middle
I'm running a local web server and if I
opened the website I'm going to have an error

00:24:57.636 --> 00:24:59.906 align:middle
because I don't have the database locally.

00:25:00.256 --> 00:25:02.456 align:middle
Right? And I don't want to
install the database locally.

00:25:02.456 --> 00:25:07.006 align:middle
So what I want to be able to do is
develop locally with my file on my laptop,

00:25:07.356 --> 00:25:10.966 align:middle
but I want the data from
the production environments.

00:25:13.636 --> 00:25:16.306 align:middle
So the way to do that is that you open a tunnel

00:25:16.776 --> 00:25:21.116 align:middle
between your local machine
and the remote services.

00:25:21.766 --> 00:25:24.466 align:middle
And that's all, that's all.

00:25:25.096 --> 00:25:28.796 align:middle
You refresh the page, don't need to
restart anything and it just works.

00:25:29.366 --> 00:25:37.426 align:middle
It just works because behind the scenes we are
getting the information from the remote services

00:25:37.736 --> 00:25:42.416 align:middle
and we are, we are exposing those
information to the web server directly.

00:25:43.016 --> 00:25:46.646 align:middle
And as you can see on the, on the
right side of the screen here,

00:25:47.336 --> 00:25:50.556 align:middle
we inject a piece of code
in the web debug toolbar.

00:25:51.116 --> 00:25:56.416 align:middle
It tells you that the tunnel is
open for the some-bug branch.

00:25:56.886 --> 00:25:58.456 align:middle
So that's what it is using.

00:25:58.516 --> 00:26:02.676 align:middle
And if you have a look at the profiler.

00:26:03.046 --> 00:26:06.516 align:middle
So that's my .env file here in my project.

00:26:06.516 --> 00:26:10.336 align:middle
You can see I'm using the sqlite
database, uh, and I've removed the file.

00:26:10.336 --> 00:26:12.046 align:middle
So that's why I had an error.

00:26:12.536 --> 00:26:18.996 align:middle
And here you can see that it's not in the .env,
uh, on the right side, which is the profiler,

00:26:19.256 --> 00:26:23.976 align:middle
it's not there because by default the
local web server detected the tunnel

00:26:24.536 --> 00:26:31.306 align:middle
and it exposed the service as environment
variables in php-fpm automatically.

00:26:31.846 --> 00:26:35.176 align:middle
And as Symfony and Symfony Cloud
share the same conventions,

00:26:35.676 --> 00:26:39.636 align:middle
it means that Symfony can read the
environment variable and boom just works.

00:26:40.156 --> 00:26:47.596 align:middle
Um, it doesn't work by default if you
are doing the same with the master branch

00:26:47.636 --> 00:26:49.156 align:middle
because we are talking about production.

00:26:49.156 --> 00:26:52.636 align:middle
I don't want you to mess up
with the production data.

00:26:52.826 --> 00:26:54.106 align:middle
So by default it doesn't work.

00:26:54.536 --> 00:26:58.396 align:middle
You can make it work by setting a very
long environment variable to be sure

00:26:58.396 --> 00:27:00.026 align:middle
that that's really what you want to do.

00:27:00.276 --> 00:27:01.826 align:middle
But by default it's disabled.

00:27:02.696 --> 00:27:04.696 align:middle
So let's recap.

00:27:04.936 --> 00:27:09.726 align:middle
So you have your web server in production,
on Symfony Cloud with your services.

00:27:09.726 --> 00:27:11.816 align:middle
Here, I just have a database.

00:27:12.386 --> 00:27:18.346 align:middle
I use a symfony env:create to
duplicate my environment so it's going

00:27:18.346 --> 00:27:22.966 align:middle
to duplicate all the files and the
infrastructure in a local git branch.

00:27:23.896 --> 00:27:32.746 align:middle
Then we open a tunnel which exposes the
DATABASE_URL here for a database to PostreSQL,

00:27:32.746 --> 00:27:37.426 align:middle
which is a link to the database
for the some-bug branch.

00:27:38.076 --> 00:27:43.156 align:middle
And then that's read by the server:start,
which means that locally I have the web server,

00:27:43.156 --> 00:27:47.076 align:middle
but it points to the db from
my some-bug environment.

00:27:47.716 --> 00:27:55.236 align:middle
Which means that now I can debug locally with
the production data, which is kind of nice,

00:27:55.636 --> 00:28:00.646 align:middle
which is what we did 20 years ago when
I started to work, uh, with the web.

00:28:01.336 --> 00:28:07.336 align:middle
Whenever we had a problem, uh, we had
to connect to the machine and mess

00:28:07.336 --> 00:28:11.466 align:middle
up with the code directly in production
to find a bug and, and fix that.

00:28:11.506 --> 00:28:13.386 align:middle
That's not needed anymore.

00:28:13.496 --> 00:28:15.226 align:middle
But the experience is exactly the same.

00:28:16.286 --> 00:28:19.276 align:middle
And from time to time, if
fixing the bug takes time,

00:28:19.586 --> 00:28:22.556 align:middle
what you can do is you can use
the symfony env:sync command,

00:28:22.946 --> 00:28:29.546 align:middle
which is going to sync the production
environment data back to your, uh,

00:28:29.706 --> 00:28:34.996 align:middle
some-bug branch, which, which means that you
will get that also on your local machine.

00:28:35.926 --> 00:28:43.506 align:middle
Okay? So you work on the problem, you can fix
the code, you can update a database schema

00:28:43.506 --> 00:28:47.786 align:middle
if you want, you can change some services,
so you can add service to fix the bug

00:28:47.786 --> 00:28:53.626 align:middle
or add a new feature, we can upgrade to a new
version of the database or whatever you commit.

00:28:53.626 --> 00:28:56.696 align:middle
So when you commit, you're going to
commit the infrastructure changes

00:28:56.696 --> 00:28:59.286 align:middle
and also the code and then you deploy.

00:28:59.556 --> 00:29:01.876 align:middle
So it's going to deploy on the demo....

00:29:02.156 --> 00:29:05.036 align:middle
uh, the some-bug branch.

00:29:05.516 --> 00:29:08.196 align:middle
You can use symfony open:remote
to check that everything is good.

00:29:08.786 --> 00:29:11.686 align:middle
Um, and remember the big difference here is

00:29:11.686 --> 00:29:13.776 align:middle
that remotely we are using
the production environment.

00:29:13.776 --> 00:29:16.476 align:middle
So it's nice to be able to check
that in the production environment,

00:29:16.476 --> 00:29:18.966 align:middle
it works in the exact same way as the local one.

00:29:19.656 --> 00:29:21.906 align:middle
And when you're ready, you can checkout master,

00:29:22.446 --> 00:29:26.486 align:middle
you merge your git branch
and then you deploy again.

00:29:26.556 --> 00:29:30.046 align:middle
And the nice thing about that is
that it's going to be really fast

00:29:30.146 --> 00:29:35.736 align:middle
because we are using the exact same container
images from the some-bug environment.

00:29:35.936 --> 00:29:41.586 align:middle
So when we deploy to some-bug environment, we
created a container with all the information,

00:29:41.586 --> 00:29:44.676 align:middle
the code and, and, and, and, and
the configuration and everything,

00:29:44.676 --> 00:29:49.706 align:middle
and it reuses this image when you deploy to
production so you can deploy with confidence

00:29:49.746 --> 00:29:53.476 align:middle
because you checked that everything
worked well into the some-bug environment.

00:29:54.746 --> 00:29:57.126 align:middle
Okay. It also works in a terminal.

00:29:57.126 --> 00:30:01.156 align:middle
So if you open a tunnel and
then if you say symfony php,

00:30:01.156 --> 00:30:04.276 align:middle
and I want to get the DATABASE_URL
environment variables,

00:30:04.276 --> 00:30:07.176 align:middle
you will get the one from the remote service.

00:30:07.176 --> 00:30:11.656 align:middle
If you want to run something with symfony
console, you can say just symfony console.

00:30:11.906 --> 00:30:13.856 align:middle
It also works with some commands.

00:30:13.856 --> 00:30:18.686 align:middle
So for instance, if you say symfony
run psql, it uses the binary,

00:30:18.806 --> 00:30:22.356 align:middle
the psql binary that you have
locally, but behind the scenes,

00:30:22.356 --> 00:30:25.786 align:middle
it sets all the environment
variables needed for a PostgreSQL

00:30:25.786 --> 00:30:28.796 align:middle
to actually connect directly
to the symfony cloud database.

00:30:29.786 --> 00:30:32.376 align:middle
And that's, what I wanted.

00:30:32.506 --> 00:30:34.776 align:middle
I wanted something that is
fast, that is convenient.

00:30:34.776 --> 00:30:37.986 align:middle
So I have everything locally,
but the remote services.

00:30:38.326 --> 00:30:41.606 align:middle
It works on all the platforms,
including Windows.

00:30:42.176 --> 00:30:48.026 align:middle
I spent, I spent so much time on that.

00:30:49.936 --> 00:30:50.596 align:middle
You're welcome.

00:30:50.856 --> 00:30:53.606 align:middle
And you can test it today.

00:30:53.606 --> 00:30:57.386 align:middle
You can go to symfony.com/cloud/download.

00:30:57.846 --> 00:31:02.866 align:middle
So again, it's not just about Symfony Cloud,
we will probably change the URL at some point.

00:31:03.436 --> 00:31:07.876 align:middle
You can download it for all the
platforms and you can test the web server.

00:31:08.356 --> 00:31:14.046 align:middle
It's still an early version of that
so any feedback is very welcome.

00:31:14.756 --> 00:31:16.296 align:middle
And I think that's all for today.

00:31:16.566 --> 00:31:17.916 align:middle
Thank you for coming again.

00:31:18.096 --> 00:31:36.046 align:middle
Thank you for listening and
enjoy the conference.

