What to expect in the next generation of Laravel Forge. Read the blog post
Rewatch this lesson

Next video in… 10

What is MVC?

Deploying your app

Getting Started with Laravel

Deploying your app
Deploy your Laravel application to the internet with Laravel Cloud. Learn Git basics and get your app live with automatic deployments.

Alright, congratulations! You have your first Laravel application running locally. We used composer run dev to set up our local development server, and we used layouts to compose what the start of our application looks like. We haven't really touched the full power of Laravel just yet, but don't worry—we'll get there.

But here's the thing: Laravel is about the whole package of an application from start to finish. And what good is an application if only you can see it in your browser on your machine? Let's get this Chirper application live on the internet with Laravel Cloud! It's the easiest way to deploy a Laravel application, and it's made by Laravel itself.

Prerequisites

Before we deploy, there's a few things you'll need (or at least knowledge of things you'll need):

  • A GitHub account—you can create that free at github.com

  • Some basic Git knowledge—but don't worry, we'll walk through those commands together

  • Your Laravel application from the previous lessons—you should have that ready to go

Now, it's possible your machine doesn't have Git installed. If that's the case, git-scm.com is probably the best resource to get it installed.

Step 1: Initialize Git and Push to GitHub

Alright, let's get your code into a Git repository. In your terminal, in the directory of your Laravel Chirper application, we're going to initialize a new Git repository:

1git init

That way we have a repository ready for us to push to GitHub. Now let's add all of our files:

1git add .

This adds everything to that Git commit. And now let's commit:

1git commit -m "Our first Laravel app"

And because Laravel has .gitignore set up for us out of the box, we don't have to worry about pushing something that shouldn't be pushed to GitHub.

Now on GitHub.com, we're going to create a new repository:

  1. Go to github.com/new

  2. Select yourself as the owner

  3. Name it "chirper" (or whatever you like)

  4. You don't have to put a description if you don't want

  5. Keep it public or private—your choice (I'm going to make mine private for now)

  6. Don't initialize with any files—we already have our code

  7. Click "Create repository"

All the other default settings should be fine.

GitHub gives us some commands that we can use—and this is exactly what we want. Copy these commands and paste them in your terminal:

1git remote add origin <https://github.com/YOUR_USERNAME/chirper.git>
2git branch -M main
3git push -u origin main

If you refresh that GitHub repository page, you should see—yes!—there's all of our code, ready to be deployed on Laravel Cloud.

Step 2: Sign Up for Laravel Cloud

So I'm going to head to cloud.laravel.com. If you don't have a Laravel Cloud account already, you can sign up for one for free. It is free to get started—you do have to enter a credit card, which just means it's pay-as-you-go. So the amount of usage that your application uses, that's what you're going to be paying for.

Now, we're going to make this as cheap as possible for you when you push this application, but this is just to show you how easy it is to get this up and running. And it's great to see your application live out in the wild!

Once you're signed in, you'll see the Laravel Cloud dashboard. Time to deploy!

Step 3: Create Your First Application

I'm going to click "New Application" and then you'll see any repositories that have been recently pushed to your GitHub account. And there it is—Chirper! I'm going to select that and create the application.

While there shouldn't be too much that you have to change here, let me explain a few things:

Hibernation Settings: If you're on the Growth plan (the paid plan) of Laravel Cloud, then your app cluster isn't going to be hibernated by default. You can see that would be $5 per month in compute for these particular settings. Now, if you're on the Starter plan (the pay-as-you-go plan that you sign up with), you'll have hibernation enabled by default. I'm going to turn that on and set it to 5 minutes. What that does is say "Hey, this could cost up to $5 a month if it doesn't hibernate throughout the month." Feel free to change that "hibernate after" number to as low as you'd like. That startup time is probably going to be around 30 seconds if no one has actually hit your application after it's been hibernating.

Database Setup: Now the only thing we have to do is add a resource. While we haven't used our database in our local environment yet, we're going to get a database up and running so it's ready for us when we do push these changes into production.

Click "Create and connect a database" → "Create new database cluster"

I'm going to use Laravel Serverless Postgres just so we can hibernate this database—because we're not going to be using it much, and it's just a fun application. That way it costs less for us. You can select a specific region (I'm just going to select US East), and then we have "Dev" which will hibernate after 300 seconds. This database cluster will cost between $0 and $25.55 per month. And since this is just a fun application, you probably won't even get close to that upper number.

If you did want to select the Laravel MySQL database, that's a flat fee—so the dev would be a flat fee of $6 per month. But again, just to get started, we're going to use the Serverless Postgres.

Step 4: Deploy Your App

Now I'm going to click "Save and Deploy". So now that we have a database configured, Laravel Cloud is going to deploy our application—the code that we pushed to that GitHub repository. It's going to:

  1. Configure everything

  2. Install the dependencies

  3. Set up that database and connect to it so we're ready to go

  4. Configure our web server so this application is publicly accessible

  5. Give us a domain—a URL that we can actually change if we want

While Laravel Cloud deploys this fairly quickly, you can also watch the progress in real-time. It's oddly satisfying!

And just like that—in about 39 seconds in my case—we have our application deployed!

Step 5: Visit Your Live App

If I go to our environment, we'll see that Chirper URL that's automatically generated for us. Clicking on that brings us to our application.

And there we go! This is our application deployed to the cloud, and it looks identical to our development server. Boom! Your Laravel app is live on the internet. Share it with friends, family, or that neighbor who never believed you could build a web app.

Auto-Deploy Magic

The neat part is Laravel Cloud has already set up this magic for us. So anytime we make any change and push it to GitHub, Laravel Cloud will grab those changes and make them available for us in our public version.

So why don't we do that right now? In your code, let's add another line. Make a small change to your home.blade.php file:

1<p>This is your brand new Laravel app. Time to make it sing (or chirp)!</p>
2<p class="mt-2 text-sm text-gray-600">Now this is live on the internet! 🎉</p>

If we look at our local version, yes, we see this is available. But let's push it live! In your terminal:

1git status # Just to see that there's something that needs to be pushed
2git add .
3git commit -m "Our first Cloud auto deployment"
4git push

What Laravel Cloud is doing now is taking that change and adding it to a new Laravel Cloud deployment. You can see that happen live at cloud.laravel.com. You can see your latest deployment getting ready to be pushed up.

And then once this has completed—again in just under a minute—we should be able to refresh our live page and see that change. It's as simple as that!

What Just Happened?

So we've taken our code and put it onto GitHub using Git version control. It's there ready for deployment, as well as safekeeping and collaboration. And then we pushed this code through that GitHub repository to Laravel Cloud. It's a live application that now exists on the internet for your friends, family, and loved ones to see!

You've just:

  • Put your code under version control with Git

  • Pushed it to GitHub for safekeeping and collaboration

  • Deployed a real Laravel app to the internet

  • Set up automatic deployments for future changes

And the great thing is, because of those automatic deployments, anytime you push new changes to your GitHub repository—more features that we add throughout this bootcamp—those changes will automatically be updated live on your site. No FTP, no manual server management, no headaches.

Next up: Let's look at how Laravel organizes code with what's known as the MVC pattern. It's time to level up from "it works" to "it works beautifully."

00:00
All right.
00:00
Congratulations.
00:01
You have your first Laravel application running locally.
00:04
We used Composer, run Dev to set up our local development server, and then we
00:09
used layouts to compose what the start of our application should look like.
00:14
We haven't really touched Laravel just yet, but don't worry we'll get there.
00:18
Laravel is about the whole package of an application from start to finish,
00:22
but what good is an application if you.
00:24
Only can see it in your browser on your machine.
00:28
Why don't we get this CHI application live on the internet with Laravel Cloud?
00:33
It's the easiest way to deploy a Laravel application, and
00:36
it's made by Laravel itself.
00:38
There's a few things that you'll need, or at least knowledge of things that you'll
00:41
need before we deploy a GitHub account.
00:44
You can create that [email protected].
00:47
Um, some basic GI knowledge.
00:49
We'll walk through those commands together, and then your layer of
00:52
application from previous lessons.
00:54
So you should have that ready to go now it's possible your machine
00:59
does not have GI installed.
01:01
If that's the case, uh, gi s scm.com is probably the best,
01:06
resource in order to install Git.
01:09
Alright.
01:09
In our terminal, in the directory of our Laravel Chi application, we're going to
01:14
initialize a new Git repository that's done with the Git and knit command.
01:19
That way.
01:20
We have a repository ready for us to push to GitHub.
01:24
What I'm going to do is add all of our files.
01:26
We can do that by GI ADD, and then a period.
01:29
And this adds everything to that GI commit.
01:33
And we're just going to do that GI commit and we're gonna have a message
01:36
of, uh, our first Laravel app.
01:40
And because we have gi ignore set up for us outta the box within Laravel, we don't
01:43
have to worry about pushing something that shouldn't be pushed to github.com.
01:48
Now on github.com we're going to create a new GIT repository, new repository.
01:55
I'm going to create myself as the owner, and we're going to call this trooper.
02:00
You don't have to put a description if you don't want, and I'm going
02:02
to make this private for now.
02:05
Great repository.
02:06
All the other default settings should be fine and GitHub gives
02:10
us some commands that we are able to use and this is what we want.
02:15
So we're going to copy this and in our terminal paste that in.
02:19
If we refresh that GitHub repository, we should see yes, there is all of our
02:24
code ready to be deployed on Ville Cloud.
02:28
So I'm going to head to cloud.laravel.com if you don't have a Larva Cloud account
02:33
already, you can sign up for one for free.
02:36
It is free to get started.
02:37
You do have to enter a credit card, which just means it is pay as you go, so as
02:43
much usage that your application uses, that's what you're going to be paying for.
02:49
Now we're gonna make this as cheap as possible for you when you push this
02:53
application, but this is just to show you how easy it is to get this up and
02:57
running, and it's great to see your application live out in the wild.
03:01
I'm going to click new application and then you'll see any
03:04
repositories that have been recently pushed to your GitHub account.
03:08
And so that's what we want sharper.
03:10
I'm going to select that and create the application.
03:13
While there shouldn't be too much that you have to change here.
03:15
If you are on the growth plan, the paid plan of Laravel Cloud,
03:20
then your app cluster is not going to be hibernated by default.
03:25
You can see here that this is $5 per month in compute for these particular settings.
03:31
Now, if you are on the starter plan, the pay as you go, plan to sign up, then you
03:36
will have hibernation enabled by default.
03:39
I'm gonna turn that on for this as well as turning it to five minutes, and what that
03:45
will do is saying, Hey, this could cost up to $5 a month if it doesn't hibernate.
03:51
Throughout the month,
03:52
feel free to change that hibernate after number to as low as you would like.
03:57
That startup time is probably going to be around 30 seconds if no one
04:01
has actually hit your application after it's been hibernating.
04:05
Now the only thing that we have to do is add a resource, and while
04:07
we haven't used our database in our local environment, we're going to
04:11
get a database up and running so that it's ready for us when we do push
04:15
these changes into production, right?
04:16
Create and connect a database.
04:18
We can click Create new database cluster.
04:21
I am going to use Laravel Serverless Postgres just so we can hibernate this
04:25
database because we're not gonna be using it much, and it's just a fun application.
04:29
And then that way it costs less for us, the user.
04:32
We can select a specific region.
04:34
I'm just going to select US east, and then we have Dev.
04:38
It's gonna hibernate after 300 seconds.
04:41
This database cluster will cost between $0 and $25 and 55 cents per month.
04:46
And since this is just a fun application, you probably won't
04:50
even get close to this number.
04:52
If you did wanna select the layer of MySQL database, that is a flat fee.
04:56
So the dev would be a flat fee of $6 per month.
05:00
But again, just to get started, we're gonna use these serverless Postgres.
05:04
Now I'm gonna click save and deploy.
05:06
So now that we have a database configured, Laravel Cloud is going to deploy our
05:11
application, the code that we have pushed, so that GitHub repository, it's going
05:15
to configure everything, install the dependencies, set up that database and
05:20
connect to it so that we're ready to go.
05:22
Anytime we push any new changes to our GitHub repository, it's
05:26
gonna configure our web server so that this application is.
05:29
Publicly accessible, and it's going to give us a domain, a URL that
05:34
we can actually change as well.
05:36
While Abell Cloud deploys this fairly quickly, you can also
05:39
see the progress in real time.
05:42
And just like that.
05:43
In 39 seconds we have our application deployed.
05:46
If I was to go to our environment, we would see that chirp, URL, that's
05:50
automatically generated for us.
05:51
Clicking on that brings us to our application.
05:55
And there we go.
05:56
And this is our application deployed to the cloud, and it looks
06:00
identical to our development server.
06:03
The neat part is Larva Cloud has already set up this magic for us.
06:07
So anytime we make any change and deploy it or push it to GitHub, larva Cloud
06:12
will grab those changes and make that available for us in our public version.
06:18
So why don't we do that right now?
06:20
In our code.
06:20
I'm just gonna add another line of code right here.
06:23
This says, now this is live on the internet.
06:26
And if we were to take a look at our local version, yes, we see this is available,
06:31
but what we're going to do in our terminal, we're going to say get status.
06:35
Just so that we know, hey, there is something that needs
06:38
to be pushed and changed.
06:39
I'm going to add this new change and then commit it to say, uh,
06:43
our first cloud auto deployment.
06:47
And we're going to push this change.
06:50
So what Laravel Cloud is doing now is it's taking that change and then adding
06:54
this to the new Laravel Cloud deployment.
06:56
We can see that happen.
07:01
You can see here our latest deployment is getting ready to be pushed up.
07:05
I can go into CHIRP and see that happening in real time as well.
07:10
And then once this has completed again in just under a minute, we should be able to
07:15
refresh our live page and see that change.
07:20
It's as simple as that.
07:21
So we've taken our code and put it onto GitHub using the GI version control.
07:26
It's there, ready for deployment, as well as safekeeping and collaboration.
07:31
And then we push this.
07:32
Code through that GitHub repository to Laravel Cloud.
07:35
It's a live application that now exists on the internet for your friends,
07:39
family, and loved ones to seize.
07:41
And the great thing is because of those automatic deployments, anytime you push
07:45
new changes to your GitHub repository, more features that we add throughout this
07:50
bootcamp, those changes will automatically be updated live on your site.
07:55
Next.
07:55
Let's look how larva organizes code with what's known as the MVC pattern.