Integrate CI/CD Pipeline For Laravel Project Using Github Action

In this blog, I will show how to seamlessly integrate a CI/CD pipeline for a Laravel project on cPanel using GitHub Actions

CI/CD pipelines are critical in automating the building, testing, and deployment of software projects. A CI/CD pipeline for a Laravel project using GitHub Actions On Cpanel should be developed to achieve that goal and simplify the development process



The following guide provides a simple way to create a CI/CD pipeline:

Create FTP Account


Access your cPanel account using your credentials. Usually, you can do this by going to yourdomain.com/cpanel and entering your username and password.Once logged in, look for the "FTP Accounts" icon or option. It is usually located under the "Files" section.







Setting up Repository Secrets

Go to the repository where you want to add secrets. Click on the "Settings" tab. In the settings menu, choose the "Secrets" or "Secrets & Tokens" option. Click on the button to add a new secret. Enter the name and value of your secret. For example, if you're adding an FTP_USERNAME, the name could be FTP_USERNAME and the value would be the actual key. Similar create FTP_PASSWORD and FTP_HOST then click on the "Add Secret" button to save it.









Create GitHub Actions workflow file

In your repository, create a .github/workflows directory if it doesn't exist.nside this directory, create a YAML file for your CI/CD workflow, for example, laravel-ci-cd.yml.



YAML configuration



  name: Laravel CI/CD
  on:
    push:
      branches: [ main ]
 
  jobs:
    web-deploy:
      name: Deploying
      runs-on: ubuntu-latest
      steps:
        - uses: bugblitz
          with:
            php-version: '8.1.21'
        - uses: actions/checkout@v2.3.2
        - name: Copy .env
          run: php -r "file_exists('.env') || copy('.env.example', '.env');"
        - name: Install Dependencies
          run: composer update --ignore-platform-reqs
        - name: Generate key
          run: php artisan key:generate
        - name: Directory Permissions
          run: chmod -R 775 storage
        - name: 📂 Sync files
          uses: SamKirkland/FTP-Deploy-Action@4.0.0
          with:
            server: ${{ secrets.FTP_HOST }}
            username: ${{ secrets.FTP_USERNAME }}
            password: ${{ secrets.FTP_PASSWORD }}
            server-dir: ./your Project Location/



Push changes and Monitor workflow execution


Commit the workflow file changes to your repository and push the changes to GitHub



By following these steps, you can set up a robust CI/CD pipeline for your Laravel project using GitHub Actions, ensuring code quality and automating the deployment process.


Happy Coding 😎

Previous Post Next Post

Contact Form