Hello at all,
I’m deploying a Laravel application with DO Apps Platform. Deployment works but I have an issue with the App environment variables.
I did set in the DO Console
DB_HOST=${db-mysql-fra1.HOSTNAME}
DB_PORT=${db-mysql-fra1.PORT}
DB_DATABASE=${db-mysql-fra1.DATABASE}
DB_USERNAME=${db-mysql-fra1.USERNAME}
DB_PASSWORD=${db-mysql-fra1.PASSWORD}
In the build process, I added a php artisan migrate --force
but it fails with:
php_network_getaddresses: getaddrinfo for ${db-mysql-fra1.HOSTNAME} failed
. The envvar is not translated.
Once launched, I have the same issue with php-fpm. If I do:
$ php artisan tinker
> echo env('DB_HOST'); // db-mysql-fra1-user.b.db.ondigitalocean.com
> echo config('database.connections.mysql.host'); // ${db-mysql-fra1.HOSTNAME}
> exit
$ php artisan config:clear
$ php artisan tinker
> echo config('database.connections.mysql.host'); // db-mysql-fra1-user-0.b.db.ondigitalocean.com
So I must manually clear the config cache to make it work. Of course, I added the php artisan config:clear
in the build phase commands but same:
php artisan cache:clear
php artisan config:clear
php artisan migrate --force
npm run build
I must add that I previously set a php artisan optimize
in the build commands but I removed it as I thought this was the problem.
Thanks in advance,
Axel
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there Axel,
Happy to hear that you’ve managed to figure out most of the issues.
Regarding the database migrations error that you are getting, you need to move the migrations step out of the build stage to the run stage.
Here is an example of a Laravel app with the same setup where the migrations step is executed right before the run command itself:
https://github.com/thedevdojo/wave/blob/main/.do/deploy.template.yaml#L9
In general it is always a good practice to run your database migrations during the deploy stage rather than the build stage, as if you make some database schema changes that are not backwords compatible during the build stage, you might end up in a situation where your running app is still using the old code base but with the new database schema causing an outage.
Let me know how it goes!
Best,
Bobby
I’m starting to uncover the answer: I set
FILESYSTEM_DISK=s3
for testing and forgot to revert it. Rollbacking toFILESYSTEM_DISK=local
fixed the php-fpm environment. But not the build phase with php-cli.