@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?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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
@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
Please or to participate in this conversation.