Coding

Laravel Homestead Tutorial – #3 Configuration

  • 00:00:01 welcome back so now that we have
  • 00:00:04 homestead set up it's time to learn how
  • 00:00:06 to work with it I'll start with the
  • 00:00:09 configuration file again so in this
  • 00:00:11 hidden homestead folder here I'll open
  • 00:00:16 up this Yama file and here while we
  • 00:00:21 already had a look at it in the last
  • 00:00:22 video most of this configuration is
  • 00:00:26 pretty straightforward we got our IP
  • 00:00:28 address at the top we can configure the
  • 00:00:31 resources this virtual machine should
  • 00:00:32 have the provider if you're using
  • 00:00:34 VirtualBox or VMware then while these
  • 00:00:38 keys and this authorization stuff should
  • 00:00:41 work this basically points towards your
  • 00:00:45 SSH keys folder this hidden folder and
  • 00:00:48 we'll make sure that you can easily
  • 00:00:51 connect to your virtual machine for SSH
  • 00:00:53 and if you should have problems there
  • 00:00:55 this might stem from multiple sources to
  • 00:00:59 be honest and bestest to Google for Lara
  • 00:01:02 homestead with your operating system and
  • 00:01:04 then as such a key problem or something
  • 00:01:07 like this and you will probably find a
  • 00:01:10 lot of solutions to possible problems
  • 00:01:13 here however this should not need any
  • 00:01:16 changes by default now the folders and
  • 00:01:19 sites keys I talked about them in the
  • 00:01:22 last video and this allows you to well
  • 00:01:25 map certain folders to be shared on your
  • 00:01:28 waiver oisin and here I follow the
  • 00:01:31 approach where I have my root folder
  • 00:01:33 mapped to a root folder on my machine
  • 00:01:36 now of course I could map multiple
  • 00:01:39 folders here and have each of my
  • 00:01:42 projects being mapped to a different
  • 00:01:45 let's say project folder on my way grant
  • 00:01:49 machine or on my VirtualBox but I don't
  • 00:01:52 like this I will like this root project
  • 00:01:54 set up but you may choose whichever Pro
  • 00:01:57 approach works for you now on sites we
  • 00:02:00 then make sure that we can access our
  • 00:02:02 projects from our local browser and we
  • 00:02:06 do this by mapping basically the URL
  • 00:02:10 here to to our
  • 00:02:13 path or public folder of the specific
  • 00:02:17 project we want to access through this
  • 00:02:19 URL so important this path here is to be
  • 00:02:23 seen on our virtual machine so not our
  • 00:02:25 path on our local machine but the path
  • 00:02:28 on the virtual machine and therefore
  • 00:02:30 this target here this – path always has
  • 00:02:35 to be included here of course since this
  • 00:02:37 is where we start on the virtual machine
  • 00:02:39 and then this path is derived from your
  • 00:02:43 local machine since they're local and
  • 00:02:46 virtual machine are equal since this is
  • 00:02:48 exactly what we same here the last
  • 00:02:53 configuration here allows us to define
  • 00:02:55 which databases we want vagrant to set
  • 00:02:59 up when starting this new box and by
  • 00:03:02 default the only have one homestead now
  • 00:03:05 we may add additional ones here but keep
  • 00:03:08 in mind those databases will be empty at
  • 00:03:10 the beginning but with full arable
  • 00:03:12 migrations you can of course quickly get
  • 00:03:14 them into the state where you want them
  • 00:03:16 to have and as I said this configuration
  • 00:03:18 here easily allows you to add either an
  • 00:03:21 error database if I could type like this
  • 00:03:29 now they commented out staff here
  • 00:03:33 doesn't need changes most of the time so
  • 00:03:36 I well we'll leave this out for now
  • 00:03:38 these are more advanced settings and I
  • 00:03:40 have never changed a bit before to be
  • 00:03:42 honest so save this closest file this is
  • 00:03:46 the configuration we have here I
  • 00:03:48 explained before that we have a
  • 00:03:50 possibility of shutting down our virtual
  • 00:03:52 machine and will waver and we can do
  • 00:03:55 this with two ways with vagrant destroy
  • 00:03:57 we will actually do what the name
  • 00:03:59 implies destroy the machine which means
  • 00:04:01 we can easily start up a new one but all
  • 00:04:04 the data on a machine for example in the
  • 00:04:06 database will be lost the new one though
  • 00:04:08 will ask the system main idea of vagrant
  • 00:04:11 have the exact same configuration as the
  • 00:04:14 old one the configuration of this
  • 00:04:17 homestead box and our config file if we
  • 00:04:21 want to keep the data around but still
  • 00:04:23 want to free up some resources for
  • 00:04:25 example we may use vagrant Hall
  • 00:04:27 to hold our machine this will not
  • 00:04:30 destroy it today they will persist but
  • 00:04:32 it is well shut down or paused we can in
  • 00:04:36 both cases
  • 00:04:37 bring up the well paused or a new
  • 00:04:40 machine with Waveland up and it will
  • 00:04:43 automatically decide what to do as it
  • 00:04:45 knows if I work but she must halted or
  • 00:04:47 destroyed just that you know how to
  • 00:04:50 manage your machines in my homestead
  • 00:04:56 folder where I ran Waveland up I can SSH
  • 00:05:00 into the virtual machine by running
  • 00:05:04 vagrant SSH and with assets a SS aging
  • 00:05:08 into it I mean that I'm now in my
  • 00:05:10 command line inside this virtual machine
  • 00:05:13 so all the commands I run here are not
  • 00:05:16 run on my local computer but inside a
  • 00:05:19 virtual machine West is important
  • 00:05:21 because for example it's very important
  • 00:05:24 when running our PHP artisan commands
  • 00:05:26 especially the database related ones
  • 00:05:29 since those commands need access to the
  • 00:05:31 database we have to run them on the
  • 00:05:34 virtual machine since there it's the
  • 00:05:36 place where our database lives it's not
  • 00:05:38 our local machine therefore for example
  • 00:05:41 PHP artisan migrate won't work on our
  • 00:05:44 local machine since it will try to
  • 00:05:46 migrate this file into our local my
  • 00:05:48 sequel database which we probably don't
  • 00:05:51 have or have not set up the way we need
  • 00:05:53 it
  • 00:05:53 therefore for this to work correctly we
  • 00:05:56 have to run such commands on the virtual
  • 00:05:59 machine now once I assets SS aged into
  • 00:06:02 this let's see where we are
  • 00:06:04 we're right at the root level where we
  • 00:06:06 have this code folder remember that's
  • 00:06:09 the folder where we mapped our local
  • 00:06:11 files to so let's have a look into this
  • 00:06:14 folder there you see exactly the same
  • 00:06:17 folder structure as I have here in this
  • 00:06:21 PHP folder
  • 00:06:22 I got projects tutorials homestead and
  • 00:06:24 these are the three folders and folders
  • 00:06:26 I have here if I go into tutorials and
  • 00:06:30 then YouTube you can see I have my
  • 00:06:32 lateral basics folder here and inside
  • 00:06:35 this level basics folder
  • 00:06:37 I could now run my PHP artisan commands
  • 00:06:41 like I would on my local machine if I
  • 00:06:44 were developing there of course you have
  • 00:06:46 to be in the project folder in the
  • 00:06:49 specific project but of course you also
  • 00:06:52 have to be on your local machine for
  • 00:06:54 this to work this is really important to
  • 00:06:56 keep in mind as you will get quite
  • 00:06:58 strange errors mostly saying that I
  • 00:07:02 can't connect database if you try to run
  • 00:07:05 database related commands on your local
  • 00:07:07 machine just stressing this because
  • 00:07:09 these are errors everyone will have
  • 00:07:12 experienced because you both did not
  • 00:07:14 think about it did not realize he's not
  • 00:07:16 in the local or an individual machine
  • 00:07:18 but on the local machine and therefore
  • 00:07:20 this is a key error source and I want to
  • 00:07:24 point this out now with this clear I
  • 00:07:28 will exit just about having exit so I'm
  • 00:07:31 back on my local machine Oh in the
  • 00:07:32 terminal and now I can run vagrant
  • 00:07:35 destroy but before I do this I want to
  • 00:07:38 show you how you can access your virtual
  • 00:07:41 machine database from your local machine
  • 00:07:44 now I I use sequel Pro for this but you
  • 00:07:48 may use whichever tool you want and well
  • 00:07:51 I already got it set up here but
  • 00:07:53 basically how you connect us you choose
  • 00:07:55 standard here not SSH standard because
  • 00:07:59 Larry will homestead will automatically
  • 00:08:01 forward some ports so that you can
  • 00:08:04 access them from your local machine
  • 00:08:06 easily one of these ports is this port
  • 00:08:10 30 30 3060 this is the database port and
  • 00:08:15 therefore on our local machine we may
  • 00:08:17 just access our well local host the
  • 00:08:22 homestead is host as a default user of
  • 00:08:25 database on your homestead machine your
  • 00:08:29 virtual machine and the password will be
  • 00:08:32 secret all lowercase now if we click
  • 00:08:35 connect you see we're right inside and
  • 00:08:39 here I see home state database that is
  • 00:08:41 automatically generated because it is
  • 00:08:43 set up this way
  • 00:08:45 the homestead EML file so this is how
  • 00:08:49 you can quickly connect to your database
  • 00:08:51 from your localhost
  • 00:08:53 just because level hosts that
  • 00:08:56 automatically forward some ports and
  • 00:08:59 this is really the key configuration or
  • 00:09:03 usage part I want to talk about I
  • 00:09:05 strongly recommend the official
  • 00:09:08 documentation here for more information
  • 00:09:10 about how to configure certain things
  • 00:09:13 and what the different configuration key
  • 00:09:16 is in the home study mo file mean but I
  • 00:09:19 think what this you should be good to go
  • 00:09:21 and you should be able to set us up and
  • 00:09:25 use it as your day-to-day development
  • 00:09:27 environment