We are a dynamic team of full-stack developers, passionate about crafting innovative solutions and delivering seamless user experiences across the entire technology stack..

Get In Touch

A Comprehensive Guide to Automation with GitHub Actions

 

Automating Laravel Deployment with GitHub Actions: An Interactive Guide

πŸš€ Welcome to our guide on streamlining Laravel project deployment with the power of GitHub Actions!

Whether you’re a coding novice or a seasoned developer, get ready for an exciting journey! This step-by-step adventure will lead you from manual deployment routines to sleek, automated workflows. πŸ€–

We’ll kick things off by setting up a Laravel project manually, tackling tasks like configuring servers and establishing SSH connections. Then, it’s time for the grand entrance of GitHub Actions! πŸŽ‰ We’ll craft workflows, lock down secrets, and transform your deployment process into an efficient, time-saving marvel πŸ’―.

By the end of this adventure, you’ll have a deployment process so smooth it practically glides. Are you ready to dive into the world of automation? Let’s get this coding party started! 🎊

Step 1: Manual Deployment Basics

Now, let’s roll up our sleeves and start with the manual deployment of your Laravel project. πŸ› οΈ

1.1 Setting Up the Server

Task: Push your Laravel project to a private GitHub repository.

  1. πŸ—οΈ Create a shiny new private repository on GitHub.
  2. πŸš€ Launch your Laravel project into orbit by pushing it to this repository.

1.2 Clone this Private Repository On Server

Task: Bring your repository down to Earth by cloning it onto your server.

  1. πŸ“₯ Use the git clone command to fetch your private repository on the server.

1.3 Configuring Laravel Environment

Task: Set up your Laravel environment on the server.

  1. πŸ“‘ Duplicate the .env.example file to .env:
  2. cp .env.example .env.
  3. 🌐 Install dependencies and craft the database:
    composer install
    php artisan migrate
    php artisan key: generate

1.4 Final Touches and Deployment

Task: Ensure everything is set for liftoff.

  1. πŸš€ Copy an .htaccess file from another Laravel project.
  2. 🧹 Sweep away obstacles with additional commands:
    php artisan config: clear
    php artisan route: clear

Congratulations! You’ve successfully completed the manual deployment. Ready for the next thrilling step? Let’s dive into the world of automation with GitHub Actions! πŸŽ‰

Step 2: Embracing Automation with GitHub Actions

It’s time to take your deployment process to the next level by automating it with the magic of GitHub Actions! ✨

2.1 GitHub Actions YAML Configuration

Task: Set up the GitHub Actions workflow by creating a YAML file.

  1. 🌐 Create a file named .github/workflows/deploy.yml in your project.

πŸš€ Populate it with the following YAML configuration:

name: Auto-Deploy to Server

on:
  push:
    branches:
      — BRANCH

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      — name: Checkout code
        uses: actions/checkout@v4

      — name: Deploy to Server
        run: |
         sshpass -p 'DEPLOY_SSH_PASSWORD' ssh -o StrictHostKeyChecking=no -p DEPLOY_SSH_PORT 'DEPLOY_USER@DEPLOY_HOST' β‰ͺEOF
          cd 'DEPLOY_PATH'

          php artisan down

          git pull DEPLOY_GIT_URL 

          php artisan migrate
          php artisan config: clear
          php artisan route: clear
          php artisan view: clear
          php artisan cache: clear
          php artisan event: clear
          php artisan up

 

2.2 Putting it into Action

Tasks:

  1. Configure YAML File:

    • Open .github/workflows/deploy.yml.
    • Replace placeholder variables (e.g., DEPLOY_HOST) with your actual deployment details.
  2. Commit and Push Changes:

    • Execute git add. to stage changes.
    • Follow up with git commit -m “Configure GitHub Actions” to commit changes.
    • Finally, git push origin main to trigger GitHub Actions.
  3. Observe Workflow:

    • Head to your GitHub repository.
    • Navigate to the “Actions” tab to witness GitHub Actions automatically executing the deployment steps.

Congratulations! πŸŽ‰ You’ve just automated your Laravel deployment with GitHub Actions. The future of deployment is now at your fingertips! Ready for the final act? Let’s see live updates in action!

GitHub Actions will automatically trigger on each push to the main branch, ensuring your deployment process stays seamless and up-to-date. Let me know if you’re ready to dive into the final act or if there’s anything specific you’d like to explore!

Security Note: Be cautious with sensitive values. GitHub Actions secrets offer a secure method to handle confidential information. Never expose sensitive details directly in the YAML file to avoid potential security risks.

Finally, If you prefer a visual guide, we've got you covered! Check out the video version of this tutorial on our YouTube channel. Follow along with the video for a hands-on demonstration of automating Laravel deployment using GitHub Actions.

3 Comments

  • Justin Case

    Patient Comments are a collection of comments submitted by viewers in
    response to a question posed by a MedicineNet doctor.

  • Jemil Akthtan

    Include anecdotal examples of your experience, or things you took notice of that you feel others would find useful.

  • Justin Case

    Patient Comments are a collection of comments submitted by viewers in
    response to a question posed by a MedicineNet doctor.

Leave A Comment

Let’s Business Something Agency

There are many variations of passages of agency
Lorem Ipsum Fasts injecte.

WhatsApp