Now what's so special about Laravel and PHP?
Well, for one, this course is about Docker
and all these examples thus far have mostly been
about Node and MongoDB and React.
I had some pipe examples
but I really wanna emphasize that you can use Docker
for anything, especially for any web technology.
And Laravel is the most popular PHP Framework out there.
It's really fun to work with it, I like it a lot,
but setting up our local machine
for Laravel development can be quite annoying.
And that's not really a Laravel's fault,
instead, having a PHP set up can be a bit annoying.
Now, if we explore Laravel documentation
we can learn about the server requirements we can learn
about our system and what should be installed there.
And we see there's quite a lot
of stuff which should be installed.
We need PHP installed most importantly
and that's already a problem.
Installing PHP just like that is something you can do
but PHP, unlike NodeJS is not enough.
The great thing about NodeJS is that
it's not only the language in which
we were going to write our code,
I mean, the language is JavaScript
but NodeJS is a JavaScript runtime.
So we can write our application code with that.
But with Node JS, we only to build the server
which handles the incoming requests.
So we have application code and server logic,
all in one piece, all written with NodeJS.
They [indistinct] NodeJS applications
we really only need to install NodeJS
and we can get started and that's super easy to do.
Now with Laravel and PHP specifically it's different,
just installing PHP is not enough because
in addition to that we'll then need a server.
We can't build the server itself with PHP.
Instead, we need a server that handles incoming requests
which then triggers the PHP interpreter
to run our PHP code for these incoming requests.
And setting all of that up on your local machine
possibly combined with MySQL or
MongoDB databases, that can be quite annoying.
And that's why this is a great example
for using Docker for this more complex setup
because you will see how easy it is in the end
to use Docker for that and without installing anything
on our local machine except for Docker,
which we already have installed I guess, we'll then be able
to write Laravel PHP code and build such applications.
Now here's our target setup, which
we wanna achieve in this module therefore.
And this will be a setup which allows us to build
Laravel applications without installing anything
on our host machine, except for Docker.
Now, the idea is that we have some folder
on our host machine that contains the source code
of this Laravel PHP application.
So that will be the folder which we can open
on our local machine with an editor
of our choice in which we can write Laravel code.
Now this source code folder will then be exposed
to one container, the PHP Interpreter container.
That is a container which has PHP installed inside of it.
And that's a container which will have access
to our source code so that it can interpret this source code
and generate a response for incoming requests.
And that's the next building block
besides this PHP Interpreter, which we need
to run our code we also need that extra server.
Because unlike with Node as I mentioned,
we don't build that server with PHP.
That's when we'll have a second container,
which has Nginx in it, which is a web server
and that container and this web server will basically
take incoming requests then go to the PHP Interpreter
and let that PHP Interpreter generate a response
and send that response back to
the clients who sent the request.
Now for storing data, we're going to add
a MySQL database and you could also use MongoDB databases
in Laravel apps, but most commonly you work
with SQL databases and therefore I'll show this setup.
And of course our PHP Interpreter in the end
needs to be able to communicate with MySQL database.
Our level framework, which is just a bunch of PHP code
in the end needs to be able to communicate here.
So that's a number of container we need.
Now these three containers, three individual
separated containers which still
will work together somehow are application containers.
We don't use them for utility functionality,
instead, these containers will stay up and running
as long as our application is up and running.
Because they are dealing with incoming requests
with handling these requests and generating
responses with help of PHP at Laravel
and they are dealing with data storage in the database.
But besides these three application containers
our setup also needs a couple of utility containers.
Because it turns out that in Laravel applications,
there are three kinds of tools, utilities, which we need.
For example, we need Composer.
Composer is basically to PHP what NPM is to Node.
It's a package manager which we can use
to install third party packages and
we will use Composer to create Laravel application
and also Laravel will use Composer
to install dependencies, which it needs.
In addition Laravel ships with its
own tool called Laravel Artisian.
Now this is a command which we for example use
to run migrations against our database
and write initial starting data to the database.
And we use it for a couple of other things as well.
If you don't know how to work with Laravel,
that's absolutely no problem, it's just about
the project set up here we won't write any real code here.
So that's another tool, which we need to expose though.
And last but not least, we will also use NPM here.
It's not that important but Laravel uses it
for some of its front end logic.
So if in your views, which are returned by Laravel
you need some Java script code, for example.
And since I wanna present a complete setup
which you could use for developing Laravel applications
we will also add that container.
So overall we'll have six containers
which are to some extent, working with our source code.
And this is the set up which we are now
going to build for all this module.