Laravel Github Actions

Published on by

Laravel Github Actions image

This tutorial will show you how to configure Github actions to run your phpunit tests, how to deploy after your tests pass and a few other things. We'll also show you how to connect to a database (MySQL, Postgres or SQLite) to run your test suite.

The first thing we'll need is a docker container with PHP installed that is able to run our Laravel test suite. We, at KDG, put together a docker container specifically for this purpose. The docker container can be found at:

  • PHP 7.4: kirschbaumdevelopment/laravel-test-runner:7.4
  • PHP 7.3: kirschbaumdevelopment/laravel-test-runner:7.3
  • PHP 7.2: kirschbaumdevelopment/laravel-test-runner:7.2

The Github repository can be found at Laravel Test Runner Container. Please open issues or send pull requests if you find any libraries missing for your needs.

We also created this example repository which is using the setup mentioned below to run the test suite.

Alright, let's get into it!

Setting up the Github Action

You may need to tweak a few things, but basically you should be able to just copy and paste the following configuration to your Github actions.


on: push
name: CI
runs-on: ubuntu-latest
image: kirschbaumdevelopment/laravel-test-runner:7.3
image: mysql:5.7
- 33306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
- uses: actions/checkout@v1
fetch-depth: 1
- name: Install composer dependencies
run: |
composer install --no-scripts
- name: Prepare Laravel Application
run: |
cp .env
php artisan key:generate
- name: Run Testsuite
run: vendor/bin/phpunit tests/

Don’t forget to configure your env!

On this example, I created a file with some of the configurations. Here is what is important for you to configure in this file:

# database

You may need a few tweaks for your own configuration but afterwards you should be able to see the build passing.

Using PostgreSQL or SQLite instead of MySQL

To use PostgreSQL instead of MySQL, you can easily change the services section in your CI config with the following:

image: postgres:10.8
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

And also change your DB configuration to:


And to use SQLite, you should be able to just remove the services section entirely, and change your environment configuration to:


Compiling assets is easy too

If you use the kirschbaumdevelopment/laravel-test-runner docker container to run your suite then it already has Node/NPM/Yarn installed. You can install dependencies/compile assets by simply adding a new step into your pipeline:

- name: Install front-end dependencies
run: |
npm install
npm run dev

And that should be enough!

Deploying your code after your test suite passes

You can easily automatically deploy your code ONLY if all of your tests are passing. I’m going to assume you already have an automated way to deploy your code here and will not go into how to do this or all the different options available.

Let’s say you want to deploy to Laravel Forge after your build passes.

- name: Deploy to Laravel Forge
run: curl ${{ secrets.FORGE_DEPLOYMENT_WEBHOOK }}

In this case, you need to register FORGE_DEPLOYMENT_WEBHOOK in the repository secrets.

Or, if you want to deploy to Vapor:

- name: Deploy to Laravel Forge
run: |
export VAPOR_API_TOKEN="${{ secrets.VAPOR_API_TOKEN }}"
vapor deploy staging

And of course, register VAPOR_API_TOKEN in your repository secrets.


Github recently implemented the ability to include badges with the last status of your actions. You probably saw some of these around open source projects in the past. If you want to include in your project, you can find the documentation here. But in short, the only thing you need is the following markdown:

[![Actions Status]({owner}/{repo}/workflows/{workflow_name}/badge.svg)]({owner}/{repo}/actions)

Owner is the owner of the repo, repo is obviously the repo name, and workflow_name is the name property in your workflow file (usually line 2).

Below you can see the rendered badge from the example repo I created:

The code for this badge looks like this:

[![Actions Status](](

Extra: Configuring Laravel Nova on your pipeline

If your Laravel project uses Laravel Nova, you will need to authenticate composer before installing dependencies. You can configure Nova authentication by adding the following step:

- name: Configure composer for Laravel Nova
composer config "" "${{ secrets.NOVA_USERNAME }}" "${{ secrets.NOVA_PASSWORD }}"

Also, don’t forget to add NOVA_USERNAME and NOVA_PASSWORD to your Github Actions secrets. This configuration can be found the repository settings > Actions.

Luis Dalmolin photo

Luis is a senior developer at Kirschbaum and has over 10 years of experience architecting complex applications and has been working with Laravel since the early days of Laravel 4.

In addition to PHP and Laravel, Luis specializes in VueJS/Javascript and everything DevOps related. He loves working with Open Source and has contributed several open-source projects to the community.

Luis taught an AngularJS course at University Feevale, where he also earned his degree in Internet Systems, and he translated the Laravel book "Code Bright" by Dayle Rees into Portuguese.


Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

No Compromises

Join the Mastering Laravel community to level up your skills and get trusted advice

Visit No Compromises
Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Tinkerwell logo


The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Kirschbaum logo


Providing innovation and stability to ensure your web application succeeds.

Shift logo


Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Bacancy logo


Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $2500/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Lucky Media logo

Lucky Media

Bespoke software solutions built for your business. We ♥ Laravel

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo


The official Laravel job board

Larafast: Laravel SaaS Starter Kit logo

Larafast: Laravel SaaS Starter Kit

Larafast is a Laravel SaaS Starter Kit with ready-to-go features for Payments, Auth, Admin, Blog, SEO, and beautiful themes. Available with Vue and Livewire stacks.

Larafast: Laravel SaaS Starter Kit
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Rector logo


Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies


The latest

View all →
SQLite Studio is a SQLite Database Explorer image

SQLite Studio is a SQLite Database Explorer

Read article
Running a Single Test, Skipping Tests, and Other Tips and Tricks image

Running a Single Test, Skipping Tests, and Other Tips and Tricks

Read article
View Third-party Relations in model:show - Now Available in Laravel 11.11 image

View Third-party Relations in model:show - Now Available in Laravel 11.11

Read article
Asserting a JSON Response Structure in Laravel image

Asserting a JSON Response Structure in Laravel

Read article
Backpack turns 8 years old, celebrates with 40% discount image

Backpack turns 8 years old, celebrates with 40% discount

Read article
Create a DateTime from a Timestamp With this New Method Coming to PHP 8.4 image

Create a DateTime from a Timestamp With this New Method Coming to PHP 8.4

Read article