#90DaysOfDevOps Challenge - Day 45 - Deploy WordPress website on AWS

Cloud Engineer and DevOps enthusiast, just talking about AWS, Docker, Linux, Kubernetes, Python, and automation.
Search for a command to run...

Cloud Engineer and DevOps enthusiast, just talking about AWS, Docker, Linux, Kubernetes, Python, and automation.
No comments yet. Be the first to comment.
The #90DaysOfDevOps Challenge is a dedicated initiative aimed at promoting continuous learning and skill development in the field of DevOps over a 90-day period.
Welcome to Day 44 of the #90DaysOfDevOps Challenge! Today, we will explore Amazon Relational Database Service (RDS), a managed database service provided by AWS. RDS makes it easy to set up, operate, and scale a relational database in the cloud. Amaz...
Running your own home lab used to mean expensive hardware, complex networking, and hours of manual configuration. This project changes that. With a single Raspberry Pi, Docker Compose, and a few hundr

Welcome to an advanced hybrid directory demo where we'll guide you through setting up a hybrid environment, connecting to simulated on-premises infrastructure, creating a managed Microsoft AD within AWS, establishing a two-way forest trust, and integ...

Hello DevOps Community! Today marks the completion of the #90DaysOfDevOps Challenge, and it's a moment to reflect on the journey we've undertaken together. Throughout this period, I've engaged with various technologies, refining my skills in the DevO...

In a modern cloud infrastructure setup, creating a robust and scalable 2-tier architecture is essential. Such an architecture helps meet the demands of your applications while ensuring repeatability, reliability, and security. In this article, we'll ...

Welcome to Part 4 of my series on building a comprehensive CI/CD pipeline in AWS. In this article, I will explore AWS CodePipeline, a powerful service for building and deploying applications in a continuous integration and continuous delivery (CI/CD)...

Welcome to Day 45 of the #90DaysOfDevOps Challenge. Today, we will focus on deploying a WordPress website on AWS. WordPress is a popular content management system (CMS) used by millions of websites worldwide. By leveraging AWS services like Amazon EC2 and Amazon RDS, we can set up a highly scalable and reliable WordPress environment.

WordPress is a highly popular content management system (CMS) that is used for over 30% of all sites on the internet. It is most commonly used for blogs, but can also be used for running e-commerce sites, message boards, and many other popular use cases. In this guide, you will learn how to set up a WordPress site to run a blog.
WordPress requires a MySQL database to store its data.
In the modules that follow, you will see how to configure a WordPress installation using Amazon RDS for MySQL. To configure this WordPress site, you will create the following resources in AWS:
An Amazon EC2 instance to install and host the WordPress application
An Amazon RDS for MySQL database to store your WordPress data
Database maintenance for your WordPress site is critical. Your database instance holds all of your important data for your WordPress site. If the database goes down, your website may go down with it, and you could even lose your data.
Database maintenance can also be difficult, and database administrators have years of specialized experience. When setting up a WordPress site, you want to stay focused on designing your page and generating your content, not worrying about database performance and backups.
Amazon RDS for MySQL helps with both of these problems. Amazon RDS for MySQL is a managed database offering from AWS. With Amazon RDS for MySQL, you get:
Automated backup and recovery so that you won’t lose data in the event of an accident
Regular updates and patches, keeping your database secure and performant
Easy installation with smart default parameters.
These features allow you to get a fast, reliable database without requiring specialized database knowledge. You can get on your way faster and start building your website.
Create an Amazon RDS for MySQL database by following the steps outlined in Day 44.

Launch an Amazon EC2 instance, selecting the appropriate instance type and configuration that meets the minimum system requirements for running WordPress.

Configure the security group for your EC2 instance, allowing incoming traffic on port 3306 for MySQL.

Connect to your EC2 instance using SSH or any preferred method of remote access.

Install a MySQL client to interact with the database.
sudo yum install -y mysql
Create a environment variables MYSQL_PASSWORD.
export MYSQL_PASSWORD=<your-password>
Next, run the following command in your terminal to connect to your MySQL database. Replace “<user>" with the master username you configure when creating your Amazon RDS database and “<password>” with the environment variable you create earlier.
mysql --user=<user> --password=<password> wordpress

Finally, create a database user for your WordPress application and give the user permission to access the wordpress database.
CREATE USER 'wordpress' IDENTIFIED BY 'wordpress-pass';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpress;
FLUSH PRIVILEGES;
Exit

Install Apache on your EC2 instance, by running the following command in your terminal:
sudo yum install -y httpd
To start the Apache web server, run the following command in your terminal:
sudo service httpd start

Go to the EC2 Instances page and find your instance. In the Description below, find the Public IPv4 DNS of your instance. Copy and paste it into the browser:


In this step, you will download the WordPress software and set up the configuration. First, download and uncompress the software by running the following commands in your terminal:
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz

If you run ls to view the contents of your directory, you will see a tar file and a directory called wordpress with uncompressed contents.

Change the directory to the wordpress directory and create a copy of the default config file using the following commands:
cd wordpress
cp wp-config-sample.php wp-config.php
Then, open the wp-config.php file using the nano editor by running the following command.
nano wp-config.php
You need to edit two areas of configuration. First, edit the database configuration by changing the following lines:
// ** 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' );
The values should be:
DB_NAME: “wordpress”
DB_USER: The name of the user you created in the database in the earlier step
DB_PASSWORD: The password for the user you created in the earlier step
DB_HOST: The hostname of the database that you found in the earlier step

The second configuration section you need to configure is the Authentication Unique Keys and Salts. It looks as follows in the configuration file:
/**#@+
* 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' );

In this step, you will make your Apache web server handle requests for WordPress. First, install the application dependencies you need for WordPress. In your terminal, run the following command:
sudo amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2
Second, change to the proper directory by running the following command:
cd /home/ec2-user
Then, copy your WordPress application files into the /var/www/html directory used by Apache.
sudo cp -r wordpress/* /var/www/html/
Finally, restart the Apache web server to pick up the changes.
sudo service httpd restart
You should see the WordPress welcome page and the five-minute installation process.

Now it’s time for the fun part—go play with your new site. Configure the design, add pages and posts, and start getting users to your site.

For a detailed explanation of the deployment process, you can refer to the following resource: Deploy WordPress with Amazon RDS.
Congratulations on completing Day 45 of the #90DaysOfDevOps Challenge. Today, we successfully deployed a WordPress website on AWS, leveraging services like Amazon EC2 and Amazon RDS. Tomorrow, we will continue our journey by diving into CloudWatch alarms and SNS topic setup in AWS. Stay tuned for Day 46!