Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KarlHill69's avatar

Laravel Github CICD

Hello everyone.

I have laravel cicd for github action. But I want to use mysql for database and I want my cicd create the mysql database from the phpunit.xml file value. Can you adjust the script?

name: Laravel

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  laravel-tests:

    runs-on: ubuntu-latest

    steps:
    - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
      with:
        php-version: '8.2'
    - uses: actions/checkout@v3
    - name: Copy .env
      run: php -r "file_exists('.env') || copy('.env.example', '.env');"
    - name: Install Dependencies
      run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
    - name: Generate key
      run: php artisan key:generate
    - name: Install NPM
      run: npm install
    - name: Build NPM
      run: npm run build
    - name: Directory Permissions
      run: chmod -R 777 storage bootstrap/cache
    - name: Create Database
      run: |
        mkdir -p database
        touch database/database.sqlite
    - name: Execute tests (Unit and Feature tests) via PHPUnit
      env:
        DB_CONNECTION: sqlite
        DB_DATABASE: database/database.sqlite
      run: vendor/bin/phpunit
0 likes
6 replies
tisuchi's avatar

@karlhill69 I think you need to add a service for mysql in the docker. So that you can access it in the action. Have you tried this?

Just curiosity, is there any particular reason for using MySQL for testing instead of SQLite?

1 like
tisuchi's avatar

@KarlHill69 Can you try this?

name: Laravel

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  laravel-tests:
    runs-on: ubuntu-latest
    services:
      mysql:
        image: mysql:5.7
        env:
          MYSQL_ROOT_PASSWORD: password
          MYSQL_DATABASE: laravel
          MYSQL_USER: user
          MYSQL_PASSWORD: password
        ports:
          - 3306:3306
        options: >-
          --health-cmd="mysqladmin ping"
          --health-interval=10s
          --health-timeout=5s
          --health-retries=3

    steps:
    - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
      with:
        php-version: '8.2'
        extensions: mbstring, xml, ctype, iconv, mysql
    - uses: actions/checkout@v3
    - name: Copy .env
      run: php -r "file_exists('.env') || copy('.env.example', '.env');"
    - name: Install Dependencies
      run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
    - name: Generate key
      run: php artisan key:generate
    - name: Create Database
      run: |
        mysql -uroot -ppassword -h127.0.0.1 -e 'CREATE DATABASE IF NOT EXISTS laravel;'
    - name: Execute tests (Unit and Feature tests) via PHPUnit
      env:
        DB_CONNECTION: mysql
        DB_HOST: 127.0.0.1
        DB_PORT: 3306
        DB_DATABASE: laravel
        DB_USERNAME: user
        DB_PASSWORD: password
      run: vendor/bin/phpunit
1 like
KarlHill69's avatar

@tisuchi I am getting this error.

Illuminate\View\ViewException: Vite manifest not found at: /home/runner/work/laravel/laravel/public/build/manifest.json (View: /home/runner/work/laravel/laravel/resources/views/frontend/templates/master.blade.php)

1 like
tisuchi's avatar
tisuchi
Best Answer
Level 70

@KarlHill69 I see. You need to install NPM dependencies.

Can you try this:

steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
  with:
    php-version: '8.2'
    extensions: mbstring, xml, ctype, iconv, mysql
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
  with:
    node-version: '16'  # Specify your Node.js version if you want different
- name: Copy .env
  run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install PHP Dependencies
  run: composer install --prefer-dist --no-progress --no-scripts
- name: Install NPM Dependencies
  run: npm install
- name: Build Assets
  run: npm run build 
- name: Generate key
  run: php artisan key:generate
- name: Create Database
  run: |
    mysql -uroot -ppassword -h127.0.0.1 -e 'CREATE DATABASE IF NOT EXISTS laravel;'
- name: Execute tests (Unit and Feature tests) via PHPUnit
  env:
    DB_CONNECTION: mysql
    DB_HOST: 127.0.0.1
    DB_PORT: 3306
    DB_DATABASE: laravel
    DB_USERNAME: user
    DB_PASSWORD: password
  run: vendor/bin/phpunit
1 like

Please or to participate in this conversation.