Deploy your Laravel app from scratch

Introduction and preparations

Episode 1
3 years ago
6 min read

I find coding using the Laravel framework such a delight. It provides this clean and homely environment you grow to love even more each day.

Until, one day, you decide it’s ready for you to deploy your Laravel application. You’re then forced to leave your cocoon and embark on a journey full of googling server stuff, DNS things, nginx configurations, apt-get this and apt-get that.

In this series, we’re going to deploy a Laravel application from A to Z together. We’ll set up a domain name, a server and use the Deployer library to deploy our application with no downtime. At the end of the series, we’ll also see how we can use paid products such as Laravel Forge and Ploi to hugely reduce the stress of maintaining our servers.

The big picture

Alright, before we dig in, let’s take a step back and examine what we’ll achieve by the end of the series. That way you can be sure this series is what you're looking for before committing to reading it.

First of all, I’ll assume you already have a Laravel application on a git repository that has been cloned to your local machine. This series is not about creating a Laravel application but about deploying an existing one and I think it’s fair to say that these requirements are fairly standard.

A diagram showing “Git repository” attached to “Local machine”.

By the end of this series, we will end up with the following structure.

A diagram that will be referred to as the “Big picture diagram” in the rest of the series. It shows “Domain name” attached to “DNS settings” attached to “Server” attached to “Server management”. “Git repository” and “Local machine” are both attached to “Server” and to each other. “Domain name” is on a cell containing the Hover logo. “DNS settings” and “Server” are on a cell containing the Digital Ocean logo. “Server management” is on a cell containing both the Forge logo and the Ploi logo. The “Git repository” is on a cell containing both the Laravel logo and the Deployer logo.

  1. First, we’ll purchase a domain name on Hover and make its nameservers point to Digital Ocean so we can manage our servers and our DNS settings in one place. We will do this in this article.
  2. Then, we’ll go ahead a create a server from scratch on Digital Ocean on the next episode. Feel free to skip that one if you’ve already got a server ready or if you’re using Forge or Ploi to create your servers.
  3. With a server ready to deploy to, we will install and configure the Deployer library within our Laravel application.
  4. We will then start the first deployment to our production server and set up its environment variables accordingly.
  5. Next, we’ll see how we can customise our deployment flow even further using custom tasks and recipes.
  6. Finally, we’ll see how to get started with server management applications such as Laravel Forge and Ploi but also how to get them working with the Deployer library.
  7. As a bonus for my wholesome sponsors, the very last article will act as an exhaustive checklist of the entire series that can you can refer back to when you’re getting your hands dirty.

The portals

When teaching a subject there is a tough balance to find between giving too much information or not enough based on the reader’s knowledge. Since this series is about “deploying from scratch” I will err on the “too much information” side of the balance so anyone without much infrastructure knowledge can follow along and share their awesome app to the world!

That means some of you are probably not going to be interested in the entire series. So here are a few pointers for different types of readers.

Note that even if you have a Laravel Forge or Ploi account or if you know how to spin up your own server, you might still learn a thing or two by reading the whole series. We’re going to set up a lot of things including Nginx, HTTPS certificates, MySQL, Upgrading PHP, prettifying our server shell, and so on.

Anyhoo, you’ve been warned. Let’s get started!

The SSH key

Our big picture diagram with “Git repository” and “Local machine” highlighted.

If you already have a git repository somewhere like on GitHub and you’re working on a local clone then you’ve likely already set up your SSH key and provided your public key to your git provider.

If that’s not your case, then we need to fix this now. Most of the connections you see on the “Big picture” diagram rely on secure SSH communication which means we’ve got to have an RSA key pair set up.

On most computers, you’d typically find your public and private keys under ~/.ssh/id_rsa.pub and ~/.ssh/id_rsa respectively. Make sure you never share the latter on any website, but you’ll need to provide the former to various places to prove you are who you say you are.

If you still don’t see a public or private key on your computer, you may follow this guide to create a pair.

For now, we just need to make sure our git provider — e.g. GitHub — knows our SSH public key. Otherwise, we won’t be able to clone and we won’t be able to deploy. Most git providers have a section on their settings where you can provide SSH keys. Here’s a guide for GitHub.

Okay, from now on, I’ll assume you have an SSH key available at ~/.ssh/id_rsa.pub. Keep that in mind as we’ll have to copy/paste it in more than one place.

The domain name

Our big picture diagram with “Domain name” highlighted

Next, let’s make sure we have a domain name ready for our app. Let’s give our application a jolly good name. We’ll call it jollygood.app! 🎩

To manage my domain names, I use Hover but feel free to use any of the millions of domain providers available out there.

If you do want to use Hover and don’t have an account yet, feel free to use my referral link here. It will give you a $2 discount on your first domain and it will give me a $2 credit on my account. Honestly, it’s such a pathetic referral system that I wouldn’t be offended if you decide not to use it out of protest. 😅

Okay, let’s type our domain name and purchase it.

Screenshot of the hover landing page with “jollygood” entered in their search bar.

Once purchased you should have access to its detail page where you can control its settings and DNS records.

Screenshot of the detail page of the “jollygood.app” domain.

However, since we’ll be using Digital Ocean to create our server — spoiler alert — I’d rather maintain my DNS settings directly on Digital Ocean so we’ve got everything in one place. Also, I much prefer the user interface of Digital Ocean for managing DNS records.

To achieve this we need to tell Hover: “Hey, if anyone asks about that domain, tell them Digital Ocean is handling it”. Concretely, we do that by replacing the domain’s nameservers.

On Hover, you can do that directly on the domain’s detail page.

We simply need to replace the two nameservers from Hover with the three following nameservers from Digital Ocean.

ns1.digitalocean.com
ns2.digitalocean.com
ns3.digitalocean.com

Screenshot of the modal editing nameservers on Hover.

Conclusion

Alrighty, that should do for our preparations.

Now that we’ve changed the nameservers to point to Digital Ocean, we can start configuring our DNS settings such that our purchased domain — jollygood.app — redirects to the IP address of our server.

However, at this point, we ain’t got no server. So let’s create one in the next episode!

Discussions

Author avatar
Yamen A. Abdulrahman
3 years ago

You're doing great job!

💖 1

Discussion

Introduction and preparations
Author avatar
Yamen A. Abdulrahman
3 years ago

You're doing great job!

💖 1
Author avatar
Loris Leiva
3 years ago

Thank you Yamen! 🥰

💖 0

Would you like to chime in?

You must be a member to add a reply to a discussion.

Fortunately, it only takes two click to become one. See you on the other side! 🌸

Become a Member
Author avatar
Siraj Kimuli
3 years ago

It's such a nice introduction

💖 2

Discussion

Introduction and preparations
Author avatar
Siraj Kimuli
3 years ago

It's such a nice introduction

💖 2
Author avatar
Loris Leiva
3 years ago

Thanks Siraj! 🙂

💖 0

Would you like to chime in?

You must be a member to add a reply to a discussion.

Fortunately, it only takes two click to become one. See you on the other side! 🌸

Become a Member
Author avatar
Syofyan Zuhad
3 years ago

I think it's better to show the 'next button' instead of just link text... ✌️ #justsuggestion

💖 1

Discussion

Introduction and preparations
Author avatar
Syofyan Zuhad
3 years ago

I think it's better to show the 'next button' instead of just link text... ✌️ #justsuggestion

💖 1
Author avatar
Loris Leiva
3 years ago

That's definitely in my To-Do list, I want to design nice previous/next buttons for series articles. I'm glad you agree too! 🥰

💖 0

Would you like to chime in?

You must be a member to add a reply to a discussion.

Fortunately, it only takes two click to become one. See you on the other side! 🌸

Become a Member

Would you like to chime in?

You must be a member to start a new discussion.

Fortunately, it only takes two click to become one. See you on the other side! 🌸

Become a Member