# How can I automate running laravel database migrations?

**URL:** <https://community.fly.io/t/how-can-i-automate-running-laravel-database-migrations/13823>\
**Category:** Questions / Help\
**Tags:** login-only\
**Created:** [June 27, 2023, 8:41pm UTC](https://community.fly.io/t/how-can-i-automate-running-laravel-database-migrations/13823 "2023-06-27T20:41:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakeshead](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jakeshead/32/12109_2.png) [@jakeshead](https://community.fly.io/u/jakeshead)\
**Post date:** [June 27, 2023, 8:41pm UTC](https://community.fly.io/t/how-can-i-automate-running-laravel-database-migrations/13823/1 "2023-06-27T20:41:19Z")

</div>

I am moving one of my clients from using php forge + a colo server to github actions + fly.

I have set up a github workflow to do deploys on PR merges, per the docs. It works fine. What I can’t figure out how to do (which forge does) is run db migrations on deploy.

I was hoping I could add to the Dockerfile that fly creates for laravel:

```auto
RUN composer install --optimize-autoloader --no-dev \
    && mkdir -p storage/logs \
    && php artisan optimize:clear \
    && php artisan migrate --force \ # <-- this

```

…however, it appears that the environment hasn’t been injected which this runs, so it’s not actually able to access the db cluster.

Is there a better pattern for this?

---

<div class="post-metadata">

**Author:** ![greg](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/greg/32/2119_2.png) [@greg](https://community.fly.io/u/greg)\
**Post date:** [June 27, 2023, 8:49pm UTC](https://community.fly.io/t/how-can-i-automate-running-laravel-database-migrations/13823/2 "2023-06-27T20:49:35Z")

</div>

Hi,

Handily there is indeed 🙂

Fly have thought of that. Check out this linked part of the docs (Migrate on Deploy) for how:

> **[Full Stack Laravel](https://fly.io/laravel-bytes/full-stack-laravel/#migrate-on-deploy)**
>
> Running a complete Laravel application on Fly.

---

<div class="post-metadata">

**Author:** ![jakeshead](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/jakeshead/32/12109_2.png) [@jakeshead](https://community.fly.io/u/jakeshead)\
**Post date:** [June 27, 2023, 8:59pm UTC](https://community.fly.io/t/how-can-i-automate-running-laravel-database-migrations/13823/3 "2023-06-27T20:59:49Z")

</div>

Great, that works (or at least takes me to the next problem). Thanks!

(Talk about buried docs though ☹ )

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/fly1/original/3X/6/e/6e8955d00cb218e186ebbe3a6ab06fefdce15290.svg) [@system](https://community.fly.io/u/system)\
**Post date:** [July 4, 2023, 9:00pm UTC](https://community.fly.io/t/how-can-i-automate-running-laravel-database-migrations/13823/4 "2023-07-04T21:00:01Z")

</div>

Closed on July 4, 2023, 9:00pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
