HTTP 500 error in a GitHub Actions pipeline of a Dockerized Laravel application

I’m starting to lose hope. I want to create a GitHub Actions pipeline to run my Laravel tests using ‘php artisan test’.

My project is Dockerized and allows local code modification.

Here’s my pipeline script:

`name: Laravel Run Tests

on:
push:
branches:
– main
pull_request:
types: [opened, reopened, synchronize]

jobs:
test:
runs-on: ubuntu-latest

steps:
  - name: Checkout repository
    uses: actions/checkout@v2

  - name: Set up PHP
    uses: shivammathur/setup-php@v2
    with:
      php-version: '8.3'

  - name: Install PHP dependencies
    run: |
      cp .env.example .env
      cp nginx/conf.d/laravel.conf.example nginx/conf.d/laravel.conf
      sudo chown -R www-data:www-data .
      sudo chmod -R 777 .
      pwd
      ls -l
      ls -a
      ls -a ./nginx/conf.d
      cat ./nginx/conf.d/laravel.conf
      composer install --no-ansi --no-interaction --no-progress --no-scripts --optimize-autoloader
      php artisan key:generate
      php artisan config:cache

  - name: Install npm dependencies
    run: |
      npm install

  - name: Install Docker Compose
    run: |
      sudo curl -L "https://github.com/docker/compose/releases/download/v2.27.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
      sudo chmod +x /usr/local/bin/docker-compose
      docker-compose --version

  - name: Set up Docker Compose
    run: |
      docker-compose up -d
      sleep 40
      docker-compose exec -T app php artisan migrate --force
      docker ps

  - name: Check file permissions
    run: docker-compose exec -T app ls -l /var/www

  - name: Check logs of app container
    run: docker logs laravel_app

  - name: Check logs of webserver container
    run: docker logs nginx

  - name: Run tests inside Docker container
    run: docker-compose exec -T app php artisan test

`

I also have the docker-compose.yml:

`services:
app:
build:
context: .
dockerfile: Dockerfile
container_name: laravel_app
working_dir: /var/www
volumes:
– ./:/var/www
networks:
– laravel
env_file:
– .env
depends_on:
– db
healthcheck:
test: [ “CMD-SHELL”, “curl -f http://localhost || exit 1” ]
interval: 30s
timeout: 10s
retries: 5
restart: unless-stopped

webserver:
    image: nginx:1.26.0-alpine
    container_name: nginx
    ports:
        - "8081:80"
    volumes:
        - ./:/var/www
        - ./nginx/conf.d:/etc/nginx/conf.d
    depends_on:
        - app
    networks:
        - laravel
    restart: unless-stopped

db:
    image: mariadb:latest
    container_name: mariadb
    environment:
        MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
        MYSQL_DATABASE: ${DB_DATABASE}
        MYSQL_USER: ${DB_USERNAME}
        MYSQL_PASSWORD: ${DB_PASSWORD}
    volumes:
        - dbdata:/var/lib/mysql
    ports:
        - "3307:3306"
    networks:
        - laravel
    healthcheck:
        test: [ "CMD-SHELL", "mysqladmin ping -h localhost -u ${DB_USERNAME} -p${DB_PASSWORD} || exit 1" ]
        interval: 30s
        timeout: 10s
        retries: 5
    restart: unless-stopped

phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin
    environment:
        PMA_HOST: db
        MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
    ports:
        -   "8082:80"
    depends_on:
        -   db
    networks:
        -   laravel
    restart: unless-stopped

networks:
laravel:

volumes:
dbdata:
`

The Dockerfile:

`FROM php:8.3.7-fpm

RUN apt-get update && apt-get install -y
git
unzip
zip
nodejs
netcat-openbsd

RUN docker-php-ext-install pdo_mysql
RUN curl -sS https://getcomposer.org/installer | php — –install-dir=/usr/local/bin –filename=composer
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash –
RUN apt-get install -y nodejs
RUN apt-get update && apt-get install -y netcat-openbsd

WORKDIR /var/www

COPY . /var/www

RUN composer install –no-interaction –no-plugins –no-scripts
RUN npm i

COPY init.sh /usr/local/bin/

RUN chmod +x /usr/local/bin/init.sh

CMD [“sh”, “/usr/local/bin/init.sh”]
`

And the init.sh file:

`#!/bin/sh

chown -R www-data:www-data /var/www

until nc -z -v -w30 db 3306; do
echo ‘Waiting for database connection…’
sleep 1
done

php artisan migrate

exec php-fpm`

Currently, my .env and laravel.conf files are exact copies of the example files.

On my local machine, I can run tests and pass them with the command:

docker-compose exec -T app php artisan test

But in my GitHub Action, I’m getting a 500 error on a test that expects only a 200 response.

I’ve made a lot of changes, consulting documentation and even using AI.
Many instructions in my pipeline script are part of my research efforts.

I’m a novice, so I’m probably missing something, but I’m out of ideas.

I’m new to this platform and I’m not sure if it’s appropriate to share the link to my repository, but here it is: https://github.com/Green-Blind/PhoenixPedia

I’ve tried several times to modify the script of my GitHub Actions pipeline.

Firstly, I tried using services instead of my docker-compose setup.
Then, I ensured that the .env.example and laravel.conf.example files were correctly copied to .env and laravel.conf.

I used ‘cat’ to verify the information that was present.

I modified the script to display container logs and also experimented with file read and write permissions.

I tried using the same version of docker-compose as on my computer.

I also attempted to force migration in case it hadn’t been applied properly.

I added various pauses to ensure that my init.sh file could finish.

I’m really stuck on this issue.

New contributor

user26055514 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật