Reputation: 577
I have a Laravel application that is connected to a RDS db, in localhost it works perfectly but when I deploy the application into Elastic Beanstalk it stops working.
The connection to mysql:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => 'dbpassword',
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
DB_CONNECTION=mysql
DB_HOST=dbname.ctwrtyncfghj.us-east-1.rds.amazonaws.com
DB_PORT=3306
DB_DATABASE=dbname
DB_USERNAME=dbUser
To deploy I compress all the files except for vendor/.
Upvotes: 3
Views: 1504
Reputation: 577
I resolve this problem so I'm going to write the solution that takes 2 steps:
a. Add define statements in config/database.php:
define('RDS_HOSTNAME', $_SERVER['RDS_HOSTNAME']);
define('RDS_USERNAME', $_SERVER['RDS_USERNAME']);
define('RDS_PASSWORD', $_SERVER['RDS_PASSWORD']);
define('RDS_DB_NAME', $_SERVER['RDS_DB_NAME']);
define('RDS_PORT', $_SERVER['RDS_PORT']);
b. and change mysql config:
'mysql' => [
'driver' => 'mysql',
'host' => RDS_HOSTNAME,
'port' => RDS_PORT,
'database' => RDS_DB_NAME,
'username' => RDS_USERNAME,
'password' => RDS_PASSWORD,
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
]
a. This is a video that shows exactly how to configure your VPC and Subnets exactly to use EB
https://www.youtube.com/watch?v=udY8x_g0dTk&frags=pl%2Cwn
b. After creating your VPC and Subnets you need to create a BRAND NEW EB environment and connected to your VPC and Subnets
https://www.youtube.com/watch?v=CB6YzVBxiL4&frags=pl%2Cwn
Upvotes: 3