Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

smesj's avatar
Level 1

Laravel Vapor: mysql not found

Hey everyone,

I am working on setting up my existing Laravel 8 application on Vapor today and have run into an issue I can't seem to find anything about online.

I have installed the vapor-cli and vapor-core packages. Connected my AWS account, created a project and RDS database. Everything seems to be working up until the point I attempt to perform the initial migration of the database. It appears that the mysql command is not found?

Hook: migrate:fresh --seed
Dropped all tables successfully.
Migration table created successfully.
Loading stored database schema: /var/task/database/schema/mysql-schema.dump

   Symfony\Component\Process\Exception\ProcessFailedException 

  The command "mysql  --user="${:LARAVEL_LOAD_USER}" --password="${:LARAVEL_LOAD_PASSWORD}" --host="${:LARAVEL_LOAD_HOST}" --port="${:LARAVEL_LOAD_PORT}" --database="${:LARAVEL_LOAD_DATABASE}" < "${:LARAVEL_LOAD_PATH}"" failed.

Exit Code: 127(Command not found)

Working directory: /var/task

Output:
================


Error Output:
================
sh: mysql: command not found

  at vendor/symfony/process/Process.php:272
    268▕      */
    269▕     public function mustRun(callable $callback = null, array $env = []): self
    270▕     {
    271▕         if (0 !== $this->run($callback, $env)) {
  ➜ 272▕             throw new ProcessFailedException($this);
    273▕         }
    274▕ 
    275▕         return $this;
    276▕     }

      +30 vendor frames 
  31  artisan:43
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

I have tried running artisan migrate:fresh --seed from both the vapor CLI as well as the vapor UI both with the same result.

I have also provided the command as a deployment hook with the same effect.

id: 30012
name: my-app
environments:
    production:
        memory: 1024
        cli-memory: 512
        runtime: 'php-8.1:al2'
        build:
            - 'COMPOSER_MIRROR_PATH_REPOS=1 composer install --no-dev'
            - 'php artisan event:cache'
            - 'npm ci && npm run prod && rm -rf node_modules'
    staging:
        database: 'my-app-db'
        memory: 1024
        cli-memory: 512
        runtime: 'php-8.1:al2'
        deploy:
            - 'php artisan migrate:fresh --seed'
        build:
            - 'COMPOSER_MIRROR_PATH_REPOS=1 composer install'
            - 'php artisan event:cache'
            - 'npm ci && npm run dev && rm -rf node_modules'

(note i am only trying to deploy the staging environment php vendor/bin/vapor deploy staging) Otherwise everything else seems to be working fine. Has anyone else encountered this issue?

0 likes
3 replies
smesj's avatar
Level 1

Update: I suspected that my issue may have to do with the fact that I have previously "squashed" a load of old migration files into a single schema file. After deleting this file the migration kicks off successfully (though ultimately fails due to many tables missing). So as it appears, Vapor is unusable for anyone who has previously ran php artisan schema:dump --prune which is definitely a bummer...

smesj's avatar
smesj
OP
Best Answer
Level 1

Workaround:

If anyone else experiences this issue there is a way to work around the issue of the squashed Laravel migrations.

Assuming you are working locally, ensure your currently connected DB is in the exact state you would like.

Install this package https://github.com/kitloong/laravel-migrations-generator.

Delete all migration files as well as the schema dump file.

Clear your migrations table in the DB.

Run php artisan migrate:generate --squash to generate a proper Laravel migration file that reconstructs your entire CURRENT database schema.

Run vendor/bin/sail migrate:refresh (assuming you are using sail) to drop all tables and perform a fresh migration using the new migration file.

Once I did this i was able to run migrations for my Laravel Vapor enviroments.

Hope this helps somebody!

3 likes
rickschmidt's avatar

I recently faced the same issue with Laravel Vapor related to the MySQL client and squashed migrations. Sharing another solution that might help others in the same boat.

Laravel Vapor's native runtimes are super slim, meaning they don't include the MySQL client which causes this issue. This results in squashed migrations not being supported.

The alternative is to use Docker runtimes with Vapor. Before you jump into it, it's important to know that switching to Docker is a significant change and isn't reversible.

Pros of Using Docker Runtimes:

  1. Flexibility: You can include any dependencies you need, like the MySQL client.
  2. Customization: Tailor your environment to your specific needs.
  3. Consistency: Ensure your development and production environments are as similar as possible.

Cons of Using Docker Runtimes:

  1. Complexity: Docker is more complex to set up and manage compared to native runtimes.
  2. Heavier: Docker runtimes are generally more heavyweight, which might slightly impact performance and cost.
  3. Irreversible: Once you switch to Docker, you can't go back to native runtimes.

If you decide to go with Docker, here's a handy guide to get you started: Docker Runtimes in Vapor.

Carefully consider your project's needs before making the switch. If you are only doing this for a one time process, you may be better off reversing your squashed migrations with the OP's suggested package or this one.

Please or to participate in this conversation.