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

ahmeda's avatar

Run migrations through .ebextensions file?

I have a file in .ebextensions folder 01_deploy.config :

option_settings:
  # Set here your php.ini `memory_limit` value.
  - namespace: aws:elasticbeanstalk:container:php:phpini
    option_name: memory_limit
    value: 256M

container_commands:
  01_install_composer_dependencies:
    command: "sudo php -d memory_limit=-1 /usr/bin/composer.phar install --no-dev --no-interaction --prefer-dist --optimize-autoloader"
    cwd: "/var/app/staging"

  02_install_node_dependencies:
    command: "sudo npm install"
    cwd: "/var/app/staging"

  03_build_node_assets:
    command: "sudo npm run prod"
    cwd: "/var/app/staging"

  04_link_storage_folder:
    command: "php artisan storage:link"
    cwd: "/var/app/staging"

  05_run_migrations:
    command: "php artisan migrate --force"
    cwd: "/var/app/staging"

When I deploy the project I got this error in /var/log/cfn-init.log

2020-10-18 11:47:40,777 [INFO] Command 04_link_storage_folder succeeded
2020-10-18 11:47:41,188 [ERROR] Command 05_run_migrations (php artisan migrate --force) failed
2020-10-18 11:47:41,189 [ERROR] Error encountered during build of postbuild_0_asu_n: Command 05_run_migrations fail$
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 542, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/construction.py", line 260, in build
    changes['commands'] = CommandTool().apply(self._config.commands)
  File "/usr/lib/python2.7/site-packages/cfnbootstrap/command_tool.py", line 117, in apply
    raise ToolError(u"Command %s failed" % name)
ToolError: Command 05_run_migrations failed
0 likes
1 reply
bobbybouwmann's avatar

Are you sure you have the .env set up correctly and there is an actual working database connection? It could be that php artisan migrate just fails because it can't connect to the database.

You should be able to see some logs in storage/logs/laravel.log.

Please or to participate in this conversation.