How to migrate to Laravel Artisan on AWAS Elastic Beanstalk?

I have a Laravel installation and have three environments configured with their respective configuration directories:

  • local
  • staging
  • production

I am using php artisan migrate:make create_users_table etc. as described here to create the database migration.

In my local environment, I use Vagrant and simple setup of the MySQL server, and at the stage of installation and production I use AWS RDS.

To configure access to the database for the staging environment , I have the app/config/staging/database.php file with the following settings:

 ... "mysql" => array( "driver" => "mysql", "host" => $_SERVER["RDS_HOSTNAME"], "database" => $_SERVER["RDS_DB_NAME"], "username" => $_SERVER["RDS_USERNAME"], "password" => $_SERVER["RDS_PASSWORD"], "charset" => "utf8", "collaction" => "utf8_unicode_ci", "prefix" => "", ), ... 

I am using git to deploy the application with git aws.push , as described here .

The question is: how do I migrate to my EBS staging server during deployment?

+6
source share
1 answer

I solved this by creating a new directory in the root of my project called .ebextensions . In this directory, I created the script file my-scripts.config :

 .ebextensions/ my-scripts.config app/ artisan bootstrap ... 

The my-scripts.config runs when you deploy EBS, is a YAML file, and looks like this:

 container_commands: 01-migration: command: "php /var/app/ondeck/artisan --env=staging migrate" leader_only: true 

Add the directory and file to git, commit and run git aws.push and it will migrate.

An explanation of how the material works in .ebextensions can be found here .

The path /var/app/ondeck is where your application runs when the script starts, after which it will be copied to /var/app/current .

The artisan --env=staging option is useful for telling the artisan what environment he should work in so that he can find the correct database settings from app/config/staging/database.php

If you need a quick and dirty way to register the cause of the failure, you can try something like "php /var/app/ondeck/artisan --env=staging migrate > /tmp/artisan-migrate.log" so you can log in your ec2 instance and check the log.

+12
source

All Articles