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.
Overview
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.
What You Will Accomplish
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
Why This Matters
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.
Task 1 - Creating an EC2 Instance and RDS Database
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 calledwordpress
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 thenano
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!