I´m using Laravel 8 with Google App Engine Standard (GAE) and Google Cloud SQL. The connection between App Engine and Cloud SQL works (tried it with a simple DB::query in a controller), so everything seems to be set up correctly.
BUT: I want to run "php artisan migrate" after I´ve deployed the Laravel App to GAE. So I tried to add the following to my composer.json:
"post-install-cmd": [
"@php artisan migrate --no-interaction --force",
"@php artisan cache:clear"
]
However, when I deploy the app the following exception is thrown when the migrate command runs:
In Connection.php line 678:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_s
chema.tables where table_schema = forge and table_name = migrations and tab
le_type = 'BASE TABLE')
As you can see it uses the db "forge" which is the default fallback value in Laravel for the environment variable "DB_DATABASE". So it looks like the env_variables set in app.yaml are not loaded when composer runs the post install method which also results in a missing database Host. So that´s the reason for the "connection refused" exception.
Do you have any idea how I can address that issue so that the correct environment variables are loaded when composer runs the migrate command?