M8 - Assignment - Database 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Assignment - Module-8: Database

Hello students, welcome back. So we will continue our assignment as we complete


RDS service in this module. I believe you already selected the AWS region where
you want to deploy this solution and created an S3 bucket, IAM user, one public
subnet and a private subnet. In this assignment, we will launch MySQL database in
a private subnet.
- Visit RDS console, click Create Database
- For Engine options, select MySQL
- For Templates, select Free tier,
- In Settings section,
- For DB identifier, enter wordpress,
- For Credentials Settings, enter your Master username and Master password
(for example: #12345678aA)
- In Connectivity section,
- For Virtual private cloud (VPC), select Vpc, you created in last time
- Click Additional connectivity configuration to show more configuration
- For Public access, select No
- For VPC security group, select Create new and enter db-sg in New VPC
security group name
- Scroll down and click Additional configuration,
- For Initial database name, enter wordpress,
- Finally, click Create database

Modify security group of RDS and EC2 instance

Now, we will continue further and modify security group of RDS and EC2 instance.
So we need EC2 instance. So please go ahead and create EC2 instance and all
missing AWS resources which we created so far.
Visit EC2 dashboard, select public-instance-sg,

- Click Edit inbound rules button


- Click Add rule, For Type, select MYSQL/Aurora,
- For Source, select custom and find the db-sg , and click Save rules
- Click Add rule, For Type, select HTTP,
- For Source, select My IP , and click Save rules

Visit Security Groups page, select db-sg ,

- Click Edit inbound rules button


- Click Add rule, For Type, select MYSQL/Aurora,
- For Source, select custom and find the public-instance-sg , and click Save
rules
Set Up The Wordpess Environment

● Visit EC2 console,


● Click the Edit button under Name column, enter Public and click Save
● Select the Public instance and click Connect,
● In Connect to instance page, click SSH client on menu and you can find the
connection command in Example.

Windows User: follow the step in this deck to connect EC2 instance by Putty

MacOS User: open a terminal on your computer, navigate to the folder where your
.pem key file is stored, and paste the connection command.
● After connection successes, run the following command to install Apache and
MySQL on your instance
○ sudo yum install -y httpd
○ sudo yum install -y mysql
● Set the environment variable of MySQL in your computer, replace
<your-endpoint> to the endpoint which can be found in RDS console→ your
database
○ export MYSQL_HOST=<your-endpoint>
● Replace your own user name and Password and run the following command
to connect to wordpress database
○ mysql --user=<your-username> --password=<your-password>
wordpress
● Create a new DB for WordPress and grant the permission
○ CREATE USER 'wordpress' IDENTIFIED BY 'wordpress-pass';
○ GRANT ALL PRIVILEGES ON wordpress.* TO wordpress;
○ FLUSH PRIVILEGES;
○ Exit
● Then, download the WordPress module and unzip it
○ wget https://wordpress.org/latest.tar.gz
○ tar -xzf latest.tar.gz
● Move into WordPress folder and backup the default config file
○ cd wordpress
○ cp wp-config-sample.php wp-config.php
● After that use nano to edit the wp-config.php file
○ nano wp-config.php
● Modify the following script into the correct value:
● DB_NAME: 'wordpress' ● DB_USER: 'wordpress' ● DB_PASSWORD:
'wordpress-pass' ● DB_HOST: your RDS endpoint
○ // ** MySQL settings - You can get this info from your web host ** //
○ /** The name of the database for WordPress */
○ define( 'DB_NAME', 'database_name_here' );
○ /** MySQL database username */
○ define( 'DB_USER', 'username_here' );
○ /** MySQL database password */
○ define( 'DB_PASSWORD', 'password_here' );
○ /** MySQL hostname */
○ define( 'DB_HOST', 'localhost' );
● Visit this link copy the content in the page and replace the following script
into new value
○ /**#@+
○ * Authentication Unique Keys and Salts.
○ *
○ * Change these to different unique phrases!
○ * You can generate these using the {@link
https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org
secret-key service}
○ * You can change these at any point in time to invalidate all existing
cookies. This will force all users to have to log in again.
○ *
○ * @since 2.6.0
○ */
○ define( 'AUTH_KEY', 'put your unique phrase here' );
○ define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
○ define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
○ define( 'NONCE_KEY', 'put your unique phrase here' );
○ define( 'AUTH_SALT', 'put your unique phrase here' );
○ define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
○ define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
○ define( 'NONCE_SALT', 'put your unique phrase here' );
● Also, paste the script below. After modifying the right value in configuration
file, use CTRL + O to save file, CTRL + X to quit nano editor
○ /** to allow 'W3TC' plugin write the configuration data into DB */
○ define( 'W3TC_CONFIG_DATABASE', true );
○ /** to allow https in WordPress, will be used in lab 2/
○ $_SERVER['HTTPS'] = 'on';
● Run the following command to deploy WordPress on your computer:
○ sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2
○ sudo yum install php-xml
○ cd /home/ec2-user
○ sudo cp -r wordpress/* /var/www/html/
○ sudo chown -R apache:apache /var/www/html
● Finally, start hosting the Apache web server
○ sudo service httpd start
○ sudo systemctl restart php-fpm

Visit Your Website And Configure The Wordpress Setting

● Open another tab/window and visit EC2 console


● Select the EC2 instance, and find the Public IPv4 DNS in Details below and
paste it on your browser, then you will see the setup page of WordPress.

● In setup page, enter your own value in the Site Title, Username, Password
and Your Email, then click Install WordPress
● After few seconds, it will be redirected to Login page,
● Enter your username and password, and click Login button, you will see the
admin page,
● In admin page, click Plugins on the left menu,
● Click Add New, search w3 total cache and click Install Now → Activate,
● Click Performance/General setting on the left menu,
● In CDN section, for CDN type, select Origin Push:S3,
● For CDN, make sure it is Enable and Click Save all Settings
Then

● Click Performance/CDN on the left menu, scroll down to find Configuration:


Objects section
● Copy and paste the Access key ID and Secret key from IAM user creation
page
● For Bucket, enter wp-workshop-<custom name> and click Create as new
bucket
● Click Test S3 upload to ensure connection succeeded and click Save all
Settings
● Click the Page/All pages on the left menu, click Simple page to edit it click
“+” icon on the top left and insert a sample image, then click Update to
confirm the change. download sample image
● Click Performance/CDN the left menu and click export the media library,
wp-includes, theme files
● Click custom files → start button to export file from EC2 to S3 bucket
Then
● Now, you can view your sample page in <your ec2
domain>/index.php/sample-page/
Congratulations, you have successfully hosted a simple WordPress website on EC2
instance and configured all required AWS services.

In case you have any confusion, I recommend visiting the lab of all previous
module.

Please note - It’s a good practice to terminate all the resources that you created in
your AWS account

That’s all for this assignment. See you in the next module.

You might also like