DEV Community

Cover image for Automatically Deploy Laravel Applications with Amezmo - Modern deployment Tool for PHP
Abednego Edet
Abednego Edet

Posted on

Automatically Deploy Laravel Applications with Amezmo - Modern deployment Tool for PHP

Introduction

What is Amezmo?

Amezmo is a managed Laravel hosting platform without the pain of managing a VPS, they provide automated deployments, automatic SSL, Remote MySQL, and so much more.
Using Amezmo you get the power of a VPS but without the complexity and time commitment required to maintain the server for hosting your PHP apps, helping you focus on what's important. For zero-downtime PHP deployments, You'll typically use a tool like Envoyer, but that requires using a VPS provider like Digital Ocean, or AWS. Hosting with Amezmo servers includes zero-downtime PHP deployment which is of course what we want.

Why use Amezmo?

Amez­mo dif­fers from oth­er offer­ings like Forge, in that it is backed by docker and has inte­grat­ed deploy­ments similar to Envoyer and also takes care of the VPS part of the equa­tion for you.
As an alternative to hosting Laravel on shared hosting, in this post, we’ll go over how to host a Laravel app on Amezmo. The end result is a complete Laravel application that’s production-ready, database-driven, and set up for automatic, zero-downtime deployments each time we push to our repository on GitHub and we’ll be taking advantage of all the features Laravel has to offer like Queues and scheduled tasks that aren't possible using shared hosting.
Hosting with Amezmo gives you:

  • Continuous delivery with automated deployments
  • Efficient queues powered by Redis
  • HTTPS domain with automated certificate renewals
  • Laravel task scheduler
  • Automated database backups and more.

Getting started

I assume you already know how to create a laravel project with composer locally and initialize a git repository, this guide aims at hosting your Laravel project using Amezmo for both staging and production (public access) environments.

If you’re used to hosting Laravel apps with shared hosting, or even a VPS, then we should highlight the difference between shared hosting and Laravel cloud hosting. The major disadvantage of shared hosting, especially for Laravel apps, is that we have less control over the actual server and ultimately, we lose the ability to use some of the advanced Laravel features like queues, and task scheduling.

Other issues with deploying laravel apps on shared hosting are that modern development doesn’t use FTP to upload code and many providers don’t offer automated deployments with Git. These days we use Git to deploy our Laravel apps, even if they are just simple apps.

With VPS hosting, you get all the power you need, but the tradeoff is the time it takes to configure the VPS for hosting Laravel apps.

If you haven’t signed up for Amezmo yet, you can do so here.

1 > Create a Linux container on Amezmo

Assuming your code is already hosted on Github
It is time to launch your Linux container instance to deploy your Laravel project on Amezmo. This instance will be where your Laravel project is both hosted on and deployed to. Login to your Amezmo account and launch a new application server from Instances > New

A screenshot of the Amezmo new application wizard step 1

From the new application form, use "your-laravel-app-name" for the Name, and use any fully qualified top-level domain that you'd like.
Eg. myappdomain.com
Amezmo will generate a private domain name for you by default when you create a new application.
You have an option to choose a server location for your region as well. After filling out the form, press Next.

A screenshot of the Amezmo new instance button

2 > Configure instance settings to suit your needs

If your app uses MySQL and Redis, do check or uncheck where applicable. You can be able to set PHP versions for specific applications, PHP 7.4 is selected by default. Click the blue Launch button to finish setting up your application server.

A screenshot of the Amezmo new application wizard step 2

3 > Git Wizard

After your instance launches, navigate to the Git tab and choose GitHub, where you have other options like GitLab and Bitbucket to choose from, but in this instance, we're using Github. From here you'll authorize Amezmo read-only access to your repository. Amezmo will create a unique deploy key and set up a webhook for automated deployments.

In the repository selection form, choose your repository, (your-laravel-app-name) from the Git repository dropdown. Type master for your Branch, and ensure you've chosen "Laravel" as the application type. Upon changing the application type, Amezmo will fill out the public document root field for you.

Leave "Automatically install Composer packages" checked, and click the Continue button. In the next step, you'll choose your domain name.

A screenshot of the Amezmo Git wizard repo selection step

4 > Add a custom domain

When you first launched your instance, you provided a custom fully qualified domain name to use for your app. In the Domain Name step of the wizard, you'll set this domain to map to your git repository. Choose your domain from the dropdown menu as seen in the screenshot below.

If you haven't validated your custom domain yet, you can always use the private domain provided by Amezmo, which is set up automatically.

A screenshot of the Amezmo Git wizard domain name selection step

5 > Automated deployments

As mentioned earlier, our development workflow is Git-first, meaning that we won't edit files directly on the server using Amezmo. All updates to your application will happen through Git. When you push your code to GitHub, Amezmo will automatically start a new zero-downtime deployment for you.

In the wizard, choose the first option, "Yes", and click the Finish button. After this step, you're done with the Git wizard, and next is to add a Cron job and a Worker process.

A screenshot of the Amezmo Add Worker form

6 > Setting up the Laravel task scheduler

Since the Laravel task scheduler is invoked by a Cron job, let's go the Crontab and add a new entry. Choose a name for the Cron entry.

By default, Amezmo will pre-fill the Command field since it knows that your app is a Laravel app. Choose @minutely for the schedule or any other as the case may be, and click the "Add Cron Entry" button.

A screenshot of the Amezmo Add Worker form

7 > Setup the Laravel Queue worker

Finally, add a new worker process that will run in the background on your server. The process will run the Redis-powered Laravel queue in the background.

Similar to the previous step, Amezmo will also pre-fill the Command field based on the fact that you imported a Laravel application. The full command, as can be seen in the screenshot below, is as follows:

php artisan queue:work --sleep=3 --tries=3 -vvv
Enter fullscreen mode Exit fullscreen mode

Based on the arguments in the above command, your queue will sleep for 3 seconds if there are no jobs to process, and will attempt to complete a job 3 times it is considered permanently failed. Bypassing the -vvv argument, you're telling Laravel to log/show extra information to standard output, so we know that our background queue worker is running.

A screenshot of the Amezmo Add Worker form

8 > What you've done so far

You're using Amezmo to host and deploy your Laravel application. You've imported a Laravel application to your Amezmo server instance, and you're all set up for automated, zero-downtime deployments. Each time you run git push on the command line, Amezmo will begin the deployment process.
Your app will be available live using your specified domain name or one generated by Amezmo.

As an advanced option, you can run scripts between each step of your deployment process and install NPM packages, and Composer packages instead of having Amezmo manage package installation. For example, of the available deployment hooks, see the .amezmo directory in the Amezmo Laravel Demo Application on GitHub.

So that's pretty much what you need to know to get started with using this amazing tool.
Don't forget to drop your comments if you need further assistance or clarity concerning this post or if you have just anything to say.

Happy coding guys! 🚀

Useful Links

Will be available to answer questions relating to Amezmo Generally

Top comments (0)