In the past years, I deployed a couple of Laravel apps to production using AWS and Github, and from time to time I find myself looking into other projects to remember which steps I took to set up the server, GitHub, the database, etc. Well, it can be a very repetitive task so I decided to document the steps in this post and share the world.
Depending on the size and requirements of the application, you have several options to deploy a Laravel application to a production environment; you may choose AWS Elastic Beanstalk (ELB), Amazon Elastic Kubernetes Service (EKS), Amazon EC2, AWS Lightsail, etc… The list of options can be very extensive. This tutorial is focused on deploying a small app to a single EC2 instance that bundles all the necessary pieces to run a Laravel application such as a web server and database which in this case will be Nginx and Postgres respectively.
Even though I used AWS as a cloud provider, these steps can be easily reproduced on any other provider like DigitalOcean, GCP, Azure, or Linode.
Prerequisites
Before diving into the deployment, ensure you have the following:
- GitHub Repository: Your Laravel application hosted on GitHub.
- AWS Account: Your account with permission to manage EC2.
Create the EC2 Instance
The first thing we need to do is to log in into the AWS console and navigate to the EC2 dashboard
Now, click on the launch instance button:
Define the name of your instance and choose an operational system. In this tutorial, we are going to use Ubuntu 22.04 LTS.
Create a new key pair to the instance that will be used later on to connect to the instance:
It’s very important to save this file in a secure place. If you lose it, you are not going to be able to download it again.
Now, let’s define the network settings. We are to create a new security group that will allow traffic for SSH, HTTP, and HTTPS from anywhere.
Click on the launch button. You should see a success message and will be able to connect to the instance
Now, connect to the server and update the system dependencies by running the following command:
bash
sudo apt update
sudo apt upgrade
Top comments (0)