Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrations and php-fpm crashes since Laravel 11 #51327

Closed
K2ouMais opened this issue May 7, 2024 · 3 comments
Closed

Migrations and php-fpm crashes since Laravel 11 #51327

K2ouMais opened this issue May 7, 2024 · 3 comments

Comments

@K2ouMais
Copy link

K2ouMais commented May 7, 2024

Laravel Version

11.7.0

PHP Version

8.3.6

Database Driver & Version

MySQL 8.3

Description

When installing a new laravel project with the installer (laravel new test), migrations are beeing run before I can choose my database of choice.

image

Even if I run laravel new test --database=mysql the database.sqlite file will always be created and the migrations still run on SQLite.

Because of this behaviour it has been really problematic to run Laravel on my own multipurpose Docker Base Images, because php-fpm will crash if the migrations havent been run before.

Before Laravel 11 every project would run on my images and even updated projects from Laravel 10 to Laravel 11 dont make any problems, but native Laravel 11 projects will crash php-fpm.

Steps To Reproduce

The issue

1. Install a new Laravel 11 project
laravel new docker-fpm-test --database=mysql

2. Change the following in the .env file

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=docker_fpm_test_db
DB_USERNAME=docker_fpm_test_user
DB_PASSWORD=docker_fpm_test_password

3. Create a docker-compose.yml file in the root folder of the newly created application

services:
    nginx:
        image: nginxinc/nginx-unprivileged:alpine-slim
        restart: unless-stopped
        environment:
            TZ: Europe/Berlin
            NGINX_ENTRYPOINT_QUIET_LOGS: true
        ports:
            - '${APP_PORT:-80}:8080'
        volumes:
            - ./docker/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf
            - .:/var/www/html
        networks:
            - test-test-network
        depends_on:
            mysql:
                condition: service_healthy
            app:
                condition: service_started

    app:
        image: johnnybigodes/images:php83
        restart: unless-stopped
        env_file:
            - .env
        environment:
            CONTAINER_ROLE: app
        volumes:
            - .:/var/www/html
        networks:
            - test-test-network
        depends_on:
            mysql:
                condition: service_healthy

    mysql:
        image: mysql:8.3
        command: --local-infile=ON --innodb_file_per_table=ON
        restart: unless-stopped
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'
        environment:
            TZ: Europe/Berlin
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ROOT_HOST: "%"
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 1
        volumes:
            - 'test-test-mysql:/var/lib/mysql'
        networks:
            - test-test-network
        healthcheck:
            test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
            interval: 5s
            timeout: 5s
            retries: 20
            start_period: 20s

networks:
    test-test-network:
        driver: bridge

volumes:
    test-test-mysql:
        driver: local

4. Now start all the containers with the following command
docker compose up -d

You will now notice that the app container wont start and it will try to restart again and again.

No docker error is beeing thrown, but you can see Exceptions in the laravel.log file, because of missing database tables.

This wasnt an issue on past Laravel versions and only startet happening since Laravel 11 and the change to SQLite.

Even upgraded Laravel 10 to Laravel 11 applications arent a problem and would work without a problem on this setup.

Because the container wont start properly, I have to run the migrations.

How to fix this issue?

1. Stop all containers
docker compose down

2. Change the purpose of the app container/service to default in the docker-compose.yml so, that php-fpm wont start

CONTAINER_ROLE: default

3. Start all containers again
docker compose up -d

4. Now without php-fpm running you can run the migrations
docker compose exec -it app php artisan migrate

5. Stop all containers the last time
docker compose down

6. Change again the purpose of the app container/service to app in the docker-compose.yml so, that php-fpm can start

CONTAINER_ROLE: app

Thats it... Now you have a running application and the app container with php-fpm wont crash again.

The problem with this is, that you can never delete the test-test-mysql docker volume or you will have to start from the beginning again while developing locally.

With other words... You cant clean your unused volumes, when working on other projects or you will have a bad time coming to this project again.

This was never a problem before Laravel 11 and it was a much better user experience, because not having run the migrations wouldnt crash the whole php-fpm.

@driesvints
Copy link
Member

Hey @K2ouMais. We're actually already fixing that in laravel/installer#337. Should go out in the release tomorrow. Thanks!

@K2ouMais
Copy link
Author

Hello @driesvints,

thank you for the response. Is this also related to a new app crashing php-fpm, because it cant run without any migrations?

@driesvints
Copy link
Member

yeah should be a general fix regardless of that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants