rocket launch

Deploying your application using Laravel Forge

Preface

Before I get into this, I’m going to assume a few things that you either have, or are able to get without any help from this article. I’ll be referencing some terminology and software(s), if you don’t know anything about them, please read up using the links provided;

  • You have a PHP application (that uses PHP 7.1 or higher)
  • Your application is under version control using one of the following;
    • BitBucket, GitHub, or GitLab (cloud based, not on premises / private!)
      • GitHub and BitBucket allow users to have unlimited private repositories, so there’s really no excuse not to use these tools nowadays
  • You know your way around SSH Keys for authenticating against a server

Let’s get into it!

Firstly, you’ll need an account with Laravel Forge. You can sign up, here.

Now, these are paid accounts (unless you’re joining a circle, which is a slightly different process), however there is a 5-day free trial for all accounts if you want to try it out.

Once you have an account, you’ll want to setup your Source Control integration, and Server Providers

Source Control Providers

For this example, I’ll be showing how you setup a GitHub integration, however the process stands true and the same for BitBucket, and GitLab as well. The buttons / menus might be slightly different, but you’ll still be able to do this using the same methods.

Connect to GitHub

Click the button, shown below

You’ll be greeted with a nice little login form,


Fill this out, and you’re basically done. In my case, I got this little message;

Server Providers

These are a little different to the Source Control Providers, in that there is no Login screen or process to follow. It happens entirely in the small form here;

Follow the directions shown in the info links for your given provider, and you’ll have everything setup in no time.

Once you’ve got this setup, you’re ready to deploy your application!

Note: This process only has to happen once. As soon as you’ve setup your providers, you can reuse them again and again in the future

Create & Build a Server

Go to, https://forge.laravel.com/servers and click on the provider you wish to use for your server. In the screenshot below, I chose Digital Ocean. Fill out the form provided with all the necessary details to ensure your server fits the specifications, location, and various software versions you require.

Hit “Create Server” and let Forge do the rest for you! You will get a prompt very quickly, stating your sudo, and database credentials. Store these somewhere safe – as they are only provided to you once.

Now you play the “waiting game”. Once your server is ready, you’ll receive an email confirming this.

Luckily, this is a blog article, so I can skip the waiting and just get on with it.

Getting your application on the Server

Your server has provisioned, and is ready for an application, and traffic!

You’ll find your server listed under the “Create Server” form, in “Active Servers”. If you don’t – give the page a refresh.

Once you’re in the Server, you’ll see a screen like this, I’ve hidden my IP, and a few domains for “reasons”.

From here, you can see I have 4 sites currently on my “personal-website” server. There are 3 sites from GitHub, and one on WordPress. Of the 4 sites, 2 have SSL. Forge has SSL built in for all sites, using LetsEncrypt. The other two use CloudFlare for SSL (as they are wildcard domains, I leave CF to handle the SSL there). If you’re still paying for SSL – stop. It’s free nowadays, and should never be paid for.

To add a new site, you simply fill in the form provided. So I did that, and I was presented with the following;

After about 30 seconds, the refresh icon stopped, and the site was ready to go! Clicking into the site, you are offered 2 options, WordPress, or Git Repository – we’ll select Git Repository.

And that’s it. Setting up the site is done. You click install, and “Let forge do the rest” after that.

Your server is now setup, and ready to accept traffic to that domain. Naturally, you will have to point your DNS setup to the server, you can find your server IP in the Servers list, or on each server page, in the top right. The public IP is the one without the brackets.

Accessing your Server

Let’s say you want to get onto your server for some reason. Gone are the days of storing usernames and passwords for servers, and having to maintain them. Forge actively disables password auth on the server, and only allows SSH.

To add an SSH Key to a server, open the server, and then go to the SSH Keys section (found in the left navigation)

From here, you can add your keys, which are automatically uploaded to your server. As you can see from the screenshot, I have one SSH Key, for my Razer Blade laptop (yes, I’m flexxing, deal with it)

Then once the SSH key is installed, you can run ssh forge@{your-server-ip} and you’re in 👍

I hope that this little guide will help you get up and running with Laravel Forge. If you have any questions, feel free to contact me on the links below in my author profile, or catch me on The PHP Community Slack!

Share this post

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email