As Elastic Beanstalk is a managed service, you don’t need to deal with launching and managing servers or any underlying infrastructure. As a developer, you can directly push your codes into Elastic Beanstalk.
In below steps, you will:
In order to prepare the source environment for Elastic Beanstalk migration, you will need to install some tools into your source machine. Please follow below steps.
sudo apt install zip
sudo apt install awscli
awscli is required to communicate with S3 and upload the source bundle.
As, you will need to make updates on your source code, it is a best practice to separate your development environment from your production. Thus, you will need to create a new dev environment in your source machine.
Create a new folder called myapp_beanstalk under /tmp and copy all your application data into that folder.
mkdir /tmp/myapp_beanstalk cp -r /var/www/html/* /tmp/myapp_beanstalk/
You may have separate systems for your dev/test/prod environments. In this workshop, you will simulate it by creating a separate folder in the same machine.
You will need to update application configuration with RDS DB details which you’ve created in the previous module, see Database migration for more details.
Go into the myapp_beanstalk application folder you’ve just created and open the wp-config.php file.
cd /tmp/myapp_beanstalk sudo vi wp-config.php
Once you open the the wp-config.php file, you will see below parameters already set-up for existing DB settings.
define( 'DB_NAME', 'wordpress-db' ); /** MySQL database username */ define( 'DB_USER', 'wordpress-user' ); /** MySQL database password */ define( 'DB_PASSWORD', 'AWSRocksSince2006' ); /** MySQL hostname */ define( 'DB_HOST', '10.0.0.68' );
Update the above lines in the the wp-config.php file as below. Notice that, there are no hard-coded details like db-username, password in your configuration file anymore. You will configure those parameters when creating the application on Elastic Beanstalk console later. Following this approach is a best practice and allows for application changes without modifying application source code.
define('DB_NAME', $_SERVER['RDS_DB_NAME']); define('DB_USER', $_SERVER['RDS_USERNAME']); define('DB_PASSWORD', $_SERVER['RDS_PASSWORD']); define('DB_HOST', $_SERVER['RDS_HOSTNAME'] . ':' . $_SERVER['RDS_PORT']);
Save and quit the wp-config.php with :wq
Create a source code bundle (wordpress-beanstalk.zip) with zip.
cd /tmp/myapp_beanstalk zip ../wordpress-beanstalk.zip -r * .[^.]*
Confirm your wordpress-beanstalk.zip file is created under tmp folder.
cd /tmp/ ls
You’ve prepared your source code bundle. In the next step, you will create a S3 bucket and upload the source code bundle into S3.