Day 45: Deploy Wordpress Website on AWS
Welcome to Day 45 of our comprehensive guide on mastering web development and cloud deployment. In this installment, we delve into the exciting realm of deploying a WordPress website on Amazon Web Services (AWS). 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.
What is WordPress?
WordPress is a popular and widely used open-source content management system (CMS) that allows individuals and businesses to create, manage, and publish websites and blogs without requiring extensive technical knowledge. It provides a user-friendly interface and a range of customizable themes, plugins, and tools, making it an accessible choice for both beginners and experienced web developers.
Features of WordPress
Here are some of the key features of WordPress
- User-Friendly Interface: WordPress provides an intuitive and user-friendly interface that makes it easy for beginners to create and manage website content without needing extensive technical knowledge.
- Themes and Customization: Users can choose from a vast library of free and premium themes to change the design and appearance of their websites. Customization options include color schemes, layout arrangements, and more.
- Plugins and Functionality: The WordPress Plugin Repository offers thousands of plugins that add various features and functionality to your website. These range from contact forms and social media integration to e-commerce solutions and search engine optimization tools.
- Content Creation and Management: WordPress makes it simple to create and manage various types of content, including blog posts, pages, images, videos, and other media. The built-in visual editor allows for easy content formatting and multimedia embedding.
- SEO Optimization: WordPress has built-in features and plugins that help optimize websites for search engines. Users can customize meta tags, optimize images, create SEO-friendly URLs, and more.
- Responsive Design: Many WordPress themes are designed to be responsive, ensuring that websites look and function well on different devices, from desktops to smartphones and tablets.
- Media Management: WordPress provides tools for uploading, organizing, and managing media files, such as images, videos, and audio clips. Users can easily insert media into their content using a user-friendly interface.
- User Roles and Permissions: WordPress allows you to define different user roles with varying levels of access and permissions. This is especially useful for collaborative websites or blogs with multiple authors.
Tasks
Task 1) As WordPress requires a MySQL database to store its data ,create an RDS as you did in Day 44. 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.
- Setup the server and post your new Wordpress app.
Step 1) Create RDS
Go to AWS Management Console > Search and Select RDS > Click on Create Database
Scroll down to Additional Configuration after the Monitoring section:
Initial Database name: wordpress-db
And retain the default settings.
Click on Create Database:
After few minutes, you can observe that the RDS is created.
Step 2) Create EC2 Instance
Now Create a EC2 Instance
Step 3) Configure the Amazon RDS Database
Services Used: Amazon RDS
Modify your Amazon RDS database to allow network access from your EC2 instance.
In the RDS Console > Select and open the Database you created.
Scroll to Connectivity and Security, and select the VPC Security Group
In the Security Groups > Go to Inbound Rules > Edit Inbound Rules.
For the existing rule > Change type to MySQL/Aurora > Remove the Security group configured earlier and select the Security group which you created earlier named wordpress-SG.
And click on Save Rules.
Now connect to your EC2 instance using SSH.
Let us create a Database user.
Install MySQL on your instance. Since in my OS, there are no default package repositories, let’s install the MySQL client by adding the MySQL Community Repository to your system and then installing the client from there:
sudo apt-get update
sudo apt-get install mysql-client -y
mysql --version
Here, We can see we’ve successfully installed mysql on our ec2 instance.
Run the following command in your terminal to connect to your MySQL database:
mysql --user=<user> --password=<password> wordpress
#mysql --user=admin --password=Radhey123 wordpress
Go to RDS Console > Open the Database you created > In the details of your Amazon RDS database, the hostname will be shown as the Endpoint in the Connectivity & Security section.
In the command line, use the following command:
export MYSQL_HOST=<your-endpoint>
#export MYSQL_HOST=wordpress-db.cztlyeyr1qzh.ap-south-1.rds.amazonaws.com
Run the following command in your terminal to connect to your MySQL database:
mysql --user=<user> --password=<password> wordpress
#mysql --user=admin --password=Radhey1234 wordpress
Run the following commands to create the user:
CREATE USER 'wordpress' IDENTIFIED BY 'wordpress-pass';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpress;
FLUSH PRIVILEGES;
Exit
Step 4 ) Configure WordPress on EC2
Services Used: EC2
Install the Apache Server:
sudo apt update
sudo apt install apache2
Go to your EC2 instance Page > Copy the Public DNS > Open this in the Browser:
Here our DNS is
ec2–65–0–133–32.ap-south-1.compute.amazonaws.com
So, Opening this in browser
Now let us Download and Configure WordPress.
To download and uncompress the software WordPress:
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
To change the directory to the WordPress directory and create a copy of the default config file
cd wordpress
cp wp-config-sample.php wp-config.php
Let us edit the wp-config.php using:
vim wp-config.php
The values that should be replaced are:
- DB_NAME: “wordpress”
- DB_USER: The name of the user you created in the database in the previous module
- DB_PASSWORD: The password for the user you created in the previous module
- DB_HOST: The hostname of the database that you found in the previous module
The changed lines would look like:
- Authentication Unique Keys and Salts:
You can generate the content of this section from this link: https://api.wordpress.org/secret-key/1.1/salt/.
Replace with the existing content.
Save and exit the file.
Let us deploy the WordPress now.
We need some dependencies for WordPress to function properly:
sudo apt install php libapache2-mod-php php-mysql -y
The above command will install PHP, the Apache module for PHP, and the PHP MySQL extension on your Ubuntu system.
Go to the proper directory and copy your WordPress application files into the /var/www/html directory used by Apache:
cd ..
sudo cp -r wordpress/* /var/www/html/
Let us restart our Apache server to incorporate the changes we made:
sudo systemctl restart apache2
Go to your Apache Web server and you should see the WordPress welcome page and the five-minute installation process.
In your Web Browser, give the address of your website in the following format to access the server:
http://Public_IPv4/wp-admin
Here our IPV4 is 65.0.133.32, So open this in browser
http://65.0.133.32/wp-admin
You should be able to see the following page:
Yay!! We’ve configured our wordpress page.