1
00:00:02,060 --> 00:00:05,440
Now what's so special about Laravel and PHP?

2
00:00:05,440 --> 00:00:08,140
Well, for one, this course is about Docker

3
00:00:08,140 --> 00:00:11,220
and all these examples thus far have mostly been

4
00:00:11,220 --> 00:00:14,290
about Node and MongoDB and React.

5
00:00:14,290 --> 00:00:16,500
I had some pipe examples

6
00:00:16,500 --> 00:00:19,350
but I really wanna emphasize that you can use Docker

7
00:00:19,350 --> 00:00:23,520
for anything, especially for any web technology.

8
00:00:23,520 --> 00:00:28,520
And Laravel is the most popular PHP Framework out there.

9
00:00:29,300 --> 00:00:32,430
It's really fun to work with it, I like it a lot,

10
00:00:32,430 --> 00:00:34,460
but setting up our local machine

11
00:00:34,460 --> 00:00:37,970
for Laravel development can be quite annoying.

12
00:00:37,970 --> 00:00:40,780
And that's not really a Laravel's fault,

13
00:00:40,780 --> 00:00:45,060
instead, having a PHP set up can be a bit annoying.

14
00:00:45,060 --> 00:00:47,900
Now, if we explore Laravel documentation

15
00:00:47,900 --> 00:00:51,740
we can learn about the server requirements we can learn

16
00:00:51,740 --> 00:00:54,450
about our system and what should be installed there.

17
00:00:54,450 --> 00:00:57,290
And we see there's quite a lot

18
00:00:57,290 --> 00:00:59,320
of stuff which should be installed.

19
00:00:59,320 --> 00:01:02,430
We need PHP installed most importantly

20
00:01:02,430 --> 00:01:04,739
and that's already a problem.

21
00:01:04,739 --> 00:01:09,620
Installing PHP just like that is something you can do

22
00:01:09,620 --> 00:01:14,620
but PHP, unlike NodeJS is not enough.

23
00:01:14,760 --> 00:01:18,430
The great thing about NodeJS is that

24
00:01:18,430 --> 00:01:21,180
it's not only the language in which

25
00:01:21,180 --> 00:01:22,950
we were going to write our code,

26
00:01:22,950 --> 00:01:24,930
I mean, the language is JavaScript

27
00:01:24,930 --> 00:01:27,290
but NodeJS is a JavaScript runtime.

28
00:01:27,290 --> 00:01:30,110
So we can write our application code with that.

29
00:01:30,110 --> 00:01:33,390
But with Node JS, we only to build the server

30
00:01:33,390 --> 00:01:35,630
which handles the incoming requests.

31
00:01:35,630 --> 00:01:39,400
So we have application code and server logic,

32
00:01:39,400 --> 00:01:43,730
all in one piece, all written with NodeJS.

33
00:01:43,730 --> 00:01:46,900
They [indistinct] NodeJS applications

34
00:01:46,900 --> 00:01:49,550
we really only need to install NodeJS

35
00:01:49,550 --> 00:01:52,793
and we can get started and that's super easy to do.

36
00:01:53,730 --> 00:01:57,650
Now with Laravel and PHP specifically it's different,

37
00:01:57,650 --> 00:02:00,710
just installing PHP is not enough because

38
00:02:00,710 --> 00:02:02,860
in addition to that we'll then need a server.

39
00:02:02,860 --> 00:02:06,210
We can't build the server itself with PHP.

40
00:02:06,210 --> 00:02:09,720
Instead, we need a server that handles incoming requests

41
00:02:09,720 --> 00:02:12,740
which then triggers the PHP interpreter

42
00:02:12,740 --> 00:02:17,010
to run our PHP code for these incoming requests.

43
00:02:17,010 --> 00:02:20,000
And setting all of that up on your local machine

44
00:02:20,000 --> 00:02:22,590
possibly combined with MySQL or

45
00:02:22,590 --> 00:02:26,630
MongoDB databases, that can be quite annoying.

46
00:02:26,630 --> 00:02:28,780
And that's why this is a great example

47
00:02:28,780 --> 00:02:32,320
for using Docker for this more complex setup

48
00:02:32,320 --> 00:02:34,810
because you will see how easy it is in the end

49
00:02:34,810 --> 00:02:38,590
to use Docker for that and without installing anything

50
00:02:38,590 --> 00:02:41,180
on our local machine except for Docker,

51
00:02:41,180 --> 00:02:44,490
which we already have installed I guess, we'll then be able

52
00:02:44,490 --> 00:02:49,000
to write Laravel PHP code and build such applications.

53
00:02:49,000 --> 00:02:51,360
Now here's our target setup, which

54
00:02:51,360 --> 00:02:53,490
we wanna achieve in this module therefore.

55
00:02:53,490 --> 00:02:56,380
And this will be a setup which allows us to build

56
00:02:56,380 --> 00:03:00,020
Laravel applications without installing anything

57
00:03:00,020 --> 00:03:03,070
on our host machine, except for Docker.

58
00:03:03,070 --> 00:03:06,110
Now, the idea is that we have some folder

59
00:03:06,110 --> 00:03:09,366
on our host machine that contains the source code

60
00:03:09,366 --> 00:03:12,200
of this Laravel PHP application.

61
00:03:12,200 --> 00:03:14,650
So that will be the folder which we can open

62
00:03:14,650 --> 00:03:16,750
on our local machine with an editor

63
00:03:16,750 --> 00:03:20,790
of our choice in which we can write Laravel code.

64
00:03:20,790 --> 00:03:24,530
Now this source code folder will then be exposed

65
00:03:24,530 --> 00:03:29,200
to one container, the PHP Interpreter container.

66
00:03:29,200 --> 00:03:32,720
That is a container which has PHP installed inside of it.

67
00:03:32,720 --> 00:03:35,350
And that's a container which will have access

68
00:03:35,350 --> 00:03:39,900
to our source code so that it can interpret this source code

69
00:03:39,900 --> 00:03:44,210
and generate a response for incoming requests.

70
00:03:44,210 --> 00:03:46,610
And that's the next building block

71
00:03:46,610 --> 00:03:49,680
besides this PHP Interpreter, which we need

72
00:03:49,680 --> 00:03:53,200
to run our code we also need that extra server.

73
00:03:53,200 --> 00:03:55,730
Because unlike with Node as I mentioned,

74
00:03:55,730 --> 00:03:58,127
we don't build that server with PHP.

75
00:03:59,170 --> 00:04:01,460
That's when we'll have a second container,

76
00:04:01,460 --> 00:04:04,620
which has Nginx in it, which is a web server

77
00:04:04,620 --> 00:04:08,670
and that container and this web server will basically

78
00:04:08,670 --> 00:04:13,010
take incoming requests then go to the PHP Interpreter

79
00:04:13,010 --> 00:04:16,660
and let that PHP Interpreter generate a response

80
00:04:16,660 --> 00:04:18,380
and send that response back to

81
00:04:18,380 --> 00:04:20,192
the clients who sent the request.

82
00:04:21,529 --> 00:04:24,250
Now for storing data, we're going to add

83
00:04:24,250 --> 00:04:28,910
a MySQL database and you could also use MongoDB databases

84
00:04:28,910 --> 00:04:31,850
in Laravel apps, but most commonly you work

85
00:04:31,850 --> 00:04:35,900
with SQL databases and therefore I'll show this setup.

86
00:04:35,900 --> 00:04:39,311
And of course our PHP Interpreter in the end

87
00:04:39,311 --> 00:04:43,960
needs to be able to communicate with MySQL database.

88
00:04:43,960 --> 00:04:47,890
Our level framework, which is just a bunch of PHP code

89
00:04:47,890 --> 00:04:50,630
in the end needs to be able to communicate here.

90
00:04:50,630 --> 00:04:53,140
So that's a number of container we need.

91
00:04:53,140 --> 00:04:56,570
Now these three containers, three individual

92
00:04:56,570 --> 00:04:58,870
separated containers which still

93
00:04:58,870 --> 00:05:03,090
will work together somehow are application containers.

94
00:05:03,090 --> 00:05:06,520
We don't use them for utility functionality,

95
00:05:06,520 --> 00:05:09,790
instead, these containers will stay up and running

96
00:05:09,790 --> 00:05:12,570
as long as our application is up and running.

97
00:05:12,570 --> 00:05:15,340
Because they are dealing with incoming requests

98
00:05:15,340 --> 00:05:18,320
with handling these requests and generating

99
00:05:18,320 --> 00:05:21,090
responses with help of PHP at Laravel

100
00:05:21,090 --> 00:05:24,233
and they are dealing with data storage in the database.

101
00:05:25,630 --> 00:05:29,090
But besides these three application containers

102
00:05:29,090 --> 00:05:33,950
our setup also needs a couple of utility containers.

103
00:05:33,950 --> 00:05:38,000
Because it turns out that in Laravel applications,

104
00:05:38,000 --> 00:05:43,000
there are three kinds of tools, utilities, which we need.

105
00:05:43,970 --> 00:05:46,620
For example, we need Composer.

106
00:05:46,620 --> 00:05:51,620
Composer is basically to PHP what NPM is to Node.

107
00:05:52,530 --> 00:05:54,850
It's a package manager which we can use

108
00:05:54,850 --> 00:05:57,400
to install third party packages and

109
00:05:57,400 --> 00:06:00,950
we will use Composer to create Laravel application

110
00:06:00,950 --> 00:06:03,960
and also Laravel will use Composer

111
00:06:03,960 --> 00:06:06,960
to install dependencies, which it needs.

112
00:06:06,960 --> 00:06:09,480
In addition Laravel ships with its

113
00:06:09,480 --> 00:06:12,660
own tool called Laravel Artisian.

114
00:06:12,660 --> 00:06:15,650
Now this is a command which we for example use

115
00:06:15,650 --> 00:06:18,720
to run migrations against our database

116
00:06:18,720 --> 00:06:21,740
and write initial starting data to the database.

117
00:06:21,740 --> 00:06:24,680
And we use it for a couple of other things as well.

118
00:06:24,680 --> 00:06:26,790
If you don't know how to work with Laravel,

119
00:06:26,790 --> 00:06:29,310
that's absolutely no problem, it's just about

120
00:06:29,310 --> 00:06:33,810
the project set up here we won't write any real code here.

121
00:06:33,810 --> 00:06:37,010
So that's another tool, which we need to expose though.

122
00:06:37,010 --> 00:06:40,710
And last but not least, we will also use NPM here.

123
00:06:40,710 --> 00:06:43,620
It's not that important but Laravel uses it

124
00:06:43,620 --> 00:06:45,740
for some of its front end logic.

125
00:06:45,740 --> 00:06:48,860
So if in your views, which are returned by Laravel

126
00:06:48,860 --> 00:06:51,550
you need some Java script code, for example.

127
00:06:51,550 --> 00:06:54,180
And since I wanna present a complete setup

128
00:06:54,180 --> 00:06:57,430
which you could use for developing Laravel applications

129
00:06:57,430 --> 00:06:59,463
we will also add that container.

130
00:07:00,460 --> 00:07:03,500
So overall we'll have six containers

131
00:07:03,500 --> 00:07:06,900
which are to some extent, working with our source code.

132
00:07:06,900 --> 00:07:08,870
And this is the set up which we are now

133
00:07:08,870 --> 00:07:11,003
going to build for all this module.

