Over 30% of all websites on the internet use WordPress as their content management system (CMS). It is most often used to run blogs, but it can also be used to run e-commerce sites, message boards, and many other popular things.
Why does WordPress need MySQL?
WordPress is a flexible content management system for building blogs, e-commerce sites, discussion boards, and more. For whatever kind of website you’re making, you will have content to store. In a blog, this will be your blog posts and comments. On an e-commerce site, it will be your products and user accounts.
This content needs to be permanently stored somewhere. WordPress uses MySQL to store this content. A lot of the data in a WordPress application is hierarchical, structured data. For example, your application may have blog posts that have user-submitted comments. A relational database is a good choice for storing hierarchical data like this. Further, MySQL is a popular open-source database and is a reliable, performant choice for this application.
Why use Amazon RDS for your WordPress database?
Many installation guides for WordPress use a MySQL database that is on the same server as the WordPress installation. While this may be sufficient to start, there are several reasons you may not want your MySQL database on the same server as your WordPress installation:
MySQL and WordPress will be competing for compute resources on the same server, potentially hurting your site’s performance.
You are unable to horizontally scale WordPress by adding additional WordPress servers as your site becomes more popular.
You are responsible for all database maintenance tasks, including database backups and security upgrades.
By using Amazon RDS for MySQL, these concerns go away. Your database will be on a separate instance than your WordPress installation, so they won’t be competing for resources. Further, you can create multiple WordPress installations that connect to a single MySQL instance on Amazon RDS, allowing you to scale your site horizontally. Finally, Amazon RDS for MySQL has automated backups and security patches to help you with your database administration.
Task
As WordPress requires a MySQL database to store its data, create an RDS.
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.
Set up the server and post your new WordPress app.
This task will show us how to set up a WordPress blog site.
Step 1: Creating a MySQL Database with Amazon RDS
Go to the 'Amazon RDS database' in the AWS management console to create a database.
Select engine type
'MySQL', database identifier
as 'wordpress', create a master username
& master password
and most important specify the initial database name
.
Here we got our 'wordpress' database created successfully.
Step 2: Creating an EC2 Instance
In this step, we launch an EC2 instance with 'ubuntu' ami, 't2.micro' instance type,
'SSH, HTTP, and HTTPS' are added to the inbound security group rule.
Step 3: Configure an Amazon RDS Database
Allow an EC2 instance to access the Amazon RDS database:
Select the 'wordpress' database in Amazon RDS databases & change the security group listed in VPC security groups as shown in the images.
SSH into an EC2 instance and create a database user:
Install mysql-client in the instance terminal to interact with the database.
Then we create a database user for the WordPress application and give the user permission to access the 'wordpress' database.
Run the following commands in the terminal:
mysql> CREATE USER 'wp_user' IDENTIFIED BY 'wordpass@123'; mysql> GRANT ALL PRIVILEGES ON wordpress.* TO wp_user; mysql> FLUSH PRIVILEGES; mysql> Exit
Step 4: Configuring WordPress on EC2
Install the Apache Web server by using
sudo apt install apache2 -y
command.Download and configure WordPress:
Download & uncompress the WordPress Software by using
wget
andtar
command.Change the directory to the wordpress directory and create a copy of the default config file using the following shown commands.
Set up the configuration.
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', 'wordpress' ); /** MySQL database username */ define( 'DB_USER', 'wp_user' ); /** MySQL database password */ define( 'DB_PASSWORD', 'wordpass@123' ); /** MySQL hostname */ define( 'DB_HOST', '<database_enpoint>' );
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' );
Go to this link to generate values for this configuration section. You can replace the entire content in that section with the content from the link.
Deploying WordPress
As WordPress works on PHP, install PHP (an application dependency for WordPress) by using
sudo apt install php libapache2-mod-php php-mysql -y
command.Thus we get our WordPress welcome page finally!
In addition to this, if we customize the details in the 'welcome page', we can successfully WordPress installed this way
and we also can get our sample website.
That's all guys, our project of deploying WordPress with the Amazon RDS database is completed.
Reference
For detailed guidance on this project,
Read the article by AWS & watch the video.
Thanks for reading my article.
Happy learning.
Keep Hustling and upskilling for your dream.
Peace out!!